From 3f4f8ba7c1fae349f97621f1f623ef47e4da3e25 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Wed, 10 Sep 2025 23:03:57 +0200 Subject: [PATCH] app: [macOS] make the app delegate optional Inspired by the discussion at golang.org/issue/70089, this change makes our particular NSApplicationDelegate implementation optional. Signed-off-by: Elias Naur --- app/os_macos.go | 3 +++ app/os_macos.m | 23 ++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) 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]; + } +}