mirror of
https://github.com/netbirdio/systray.git
synced 2026-05-22 17:08:41 -07:00
have a workaround to avoid crash on old macOS versions
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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() {}
|
||||
|
||||
+9
-1
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user