handle click dock icon to reopen app for Mac

This commit is contained in:
Drew Weymouth
2026-03-14 19:38:41 -07:00
parent e23dfb8554
commit 9a30559343
4 changed files with 78 additions and 1 deletions
+41
View File
@@ -0,0 +1,41 @@
//go:build darwin
#import <AppKit/AppKit.h>
extern void appReopened(void);
@interface ReopenDelegate : NSObject<NSApplicationDelegate>
@property (nonatomic, strong) id<NSApplicationDelegate> wrapped;
@end
@implementation ReopenDelegate
- (BOOL)applicationShouldHandleReopen:(NSApplication *)app
hasVisibleWindows:(BOOL)hasVisible {
if (!hasVisible) {
appReopened();
}
if ([self.wrapped respondsToSelector:_cmd]) {
return [self.wrapped applicationShouldHandleReopen:app
hasVisibleWindows:hasVisible];
}
return YES;
}
- (BOOL)respondsToSelector:(SEL)sel {
return [super respondsToSelector:sel] ||
[self.wrapped respondsToSelector:sel];
}
- (id)forwardingTargetForSelector:(SEL)sel {
return [self.wrapped respondsToSelector:sel] ? self.wrapped : nil;
}
@end
void installReopenDelegate(void) {
ReopenDelegate *d = [ReopenDelegate new];
d.wrapped = [NSApp delegate];
[NSApp setDelegate:d];
}