diff --git a/app/os_macos.go b/app/os_macos.go index 10734e8f..c4ea3114 100644 --- a/app/os_macos.go +++ b/app/os_macos.go @@ -40,6 +40,7 @@ import ( #define MOUSE_SCROLL 4 __attribute__ ((visibility ("hidden"))) void gio_main(void); +__attribute__ ((visibility ("hidden"))) void gio_init(void); __attribute__ ((visibility ("hidden"))) CFTypeRef gio_createView(int presentWithTrans); __attribute__ ((visibility ("hidden"))) CFTypeRef gio_createWindow(CFTypeRef viewRef, CGFloat width, CGFloat height); __attribute__ ((visibility ("hidden"))) void gio_viewSetHandle(CFTypeRef viewRef, uintptr_t handle); @@ -334,6 +335,8 @@ import "C" func init() { // Darwin requires that UI operations happen on the main thread only. runtime.LockOSThread() + // Register launch finished listener. + C.gio_init() } // AppKitViewEvent notifies the client of changes to the window AppKit handles. diff --git a/app/os_macos.m b/app/os_macos.m index 2357adea..1b94b8f9 100644 --- a/app/os_macos.m +++ b/app/os_macos.m @@ -420,7 +420,6 @@ void gio_viewSetHandle(CFTypeRef viewRef, uintptr_t handle) { - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; [NSApp activateIgnoringOtherApps:YES]; - gio_onFinishLaunching(); } @end @@ -451,3 +450,25 @@ void gio_main() { [NSApp run]; } } + +@interface AppListener : NSObject +@end + +static AppListener *appListener; + +@implementation AppListener +- (void)launchFinished:(NSNotification *)notification { + appListener = nil; + gio_onFinishLaunching(); +} +@end + +void gio_init() { + @autoreleasepool { + appListener = [[AppListener alloc] init]; + [[NSNotificationCenter defaultCenter] addObserver:appListener + selector:@selector(launchFinished:) + name:NSApplicationDidFinishLaunchingNotification + object:nil]; + } +}