From 8097df99301a63267ea57ba52f866a71602e622d Mon Sep 17 00:00:00 2001 From: Siva Date: Mon, 20 Nov 2023 13:07:47 -0800 Subject: [PATCH] app: [macOS] activate app on ActionRaise if necessary Calling window.Perform(system.ActionRaise) does not show the window on the top if the app is currently not active. This can happen for example if the app integrated with systray (https://pkg.go.dev/fyne.io/systray) where the menu item launches a window, the window is not showing at the top. It is fixed by activating the current app if necessary. Signed-off-by: Siva Dirisala --- app/os_macos.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/os_macos.go b/app/os_macos.go index 2513eaf3..d02c7cb9 100644 --- a/app/os_macos.go +++ b/app/os_macos.go @@ -192,6 +192,10 @@ static CFTypeRef windowForView(CFTypeRef viewRef) { } static void raiseWindow(CFTypeRef windowRef) { + NSRunningApplication *currentApp = [NSRunningApplication currentApplication]; + if (![currentApp isActive]) { + [currentApp activateWithOptions:(NSApplicationActivateAllWindows | NSApplicationActivateIgnoringOtherApps)]; + } NSWindow* window = (__bridge NSWindow *)windowRef; [window makeKeyAndOrderFront:nil]; }