diff --git a/README.md b/README.md index 45cfa6a..e0ed70d 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ Now look for *Awesome App* in your menu bar! ## The Webview example -The code under `webview_example` is to demostrate how it can co-exist with other UI elements. +The code under `webview_example` is to demostrate how it can co-exist with other UI elements. Note that the example doesn't work on macOS versions older than 10.15 Catalina. ## Platform notes diff --git a/systray.go b/systray.go index 82158ed..729b521 100644 --- a/systray.go +++ b/systray.go @@ -78,6 +78,8 @@ func Run(onReady func(), onExit func()) { // Register initializes GUI and registers the callbacks but relies on the // caller to run the event loop somewhere else. It's useful if the program // needs to show other UI elements, for example, webview. +// To overcome some OS weirdness, On macOS versions before Catalina, calling +// this does exactly the same as Run(). func Register(onReady func(), onExit func()) { if onReady == nil { systrayReady = func() {} diff --git a/systray_darwin.m b/systray_darwin.m index b4f38bc..8336c1f 100644 --- a/systray_darwin.m +++ b/systray_darwin.m @@ -212,10 +212,18 @@ NSMenuItem *find_menu_item(NSMenu *ourMenu, NSNumber *menuId) { void registerSystray(void) { AppDelegate *delegate = [[AppDelegate alloc] init]; [[NSApplication sharedApplication] setDelegate:delegate]; + // A workaround to avoid crashing on macOS versions before Catalina. Somehow + // SIGSEGV would happen inside AppKit if [NSApp run] is called from a + // different function, even if that function is called right after this. + if (floor(NSAppKitVersionNumber) <= /*NSAppKitVersionNumber10_14*/ 1671){ + [NSApp run]; + } } int nativeLoop(void) { - [NSApp run]; + if (floor(NSAppKitVersionNumber) > /*NSAppKitVersionNumber10_14*/ 1671){ + [NSApp run]; + } return EXIT_SUCCESS; }