have a workaround to avoid crash on old macOS versions

This commit is contained in:
Joesis
2020-06-10 01:33:34 -07:00
parent 4a576eb251
commit 1d2efbb70d
3 changed files with 12 additions and 2 deletions
+1 -1
View File
@@ -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
+2
View File
@@ -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
View File
@@ -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;
}