@@ -2,6 +2,8 @@
22#import <Cocoa/Cocoa.h>
33#import <WebKit/WebKit.h>
44
5+extern void callIO(HsStablePtr);
6+extern void callWithCString(const char * _Nonnull, HsStablePtr);
57extern void callWithWebView(WKWebView *, HsStablePtr);
68
79@interface AppDelegate : NSObject <NSApplicationDelegate>
@@ -11,6 +13,10 @@ extern void callWithWebView(WKWebView *, HsStablePtr);
1113- (instancetype)initApp:(HsStablePtr)handler progName:(NSString *)progName;
1214@end
1315
16+HsStablePtr global_willFinishLaunchingWithOptions = 0;
17+HsStablePtr global_didFinishLaunchingWithOptions = 0;
18+HsStablePtr global_applicationUniversalLink = 0;
19+
1420@implementation AppDelegate
1521
1622- (void)applicationWillTerminate:(NSNotification *)aNotification {
@@ -37,12 +43,26 @@ extern void callWithWebView(WKWebView *, HsStablePtr);
3743 WKWebView *webView = [[WKWebView alloc] initWithFrame: [_window.contentView frame] configuration:theConfiguration];
3844 [_window setContentView:webView];
3945 callWithWebView(webView, _handler);
46+ callIO(global_willFinishLaunchingWithOptions);
47+ // Listen to URL events
48+ NSAppleEventManager *manager = [NSAppleEventManager sharedAppleEventManager];
49+ [manager
50+ setEventHandler:self
51+ andSelector:@selector(applicationUniversalLink:)
52+ forEventClass:kInternetEventClass
53+ andEventID:kAEGetURL];
54+}
55+
56+- (void)applicationUniversalLink:(NSAppleEventDescriptor *)event {
57+ NSString *url = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
58+ callWithCString([url UTF8String], global_applicationUniversalLink);
4059}
4160
4261-(void)applicationDidFinishLaunching:(NSNotification *)notification {
4362 [_window orderFrontRegardless];
4463 [_window center];
4564 [NSApp activateIgnoringOtherApps:YES];
65+ callIO(global_didFinishLaunchingWithOptions);
4666}
4767
4868-(BOOL) applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)app {
@@ -51,8 +71,29 @@ extern void callWithWebView(WKWebView *, HsStablePtr);
5171
5272@end
5373
54−void runInWKWebView(HsStablePtr handler, const char * _Nonnull progName) {
74+void runInWKWebView(HsStablePtr handler,
75+ const char * _Nonnull progName,
76+ HsStablePtr hs_willFinishLaunchingWithOptions,
77+ HsStablePtr hs_didFinishLaunchingWithOptions,
78+ HsStablePtr hs_applicationDidBecomeActive,
79+ HsStablePtr hs_applicationWillResignActive,
80+ HsStablePtr hs_applicationDidEnterBackground,
81+ HsStablePtr hs_applicationWillEnterForeground,
82+ HsStablePtr hs_applicationWillTerminate,
83+ HsStablePtr hs_applicationSignificantTimeChange,
84+ HsStablePtr hs_applicationUniversalLink,
85+ const uint64_t hs_requestAuthorizationWithOptions,
86+ const uint64_t hs_requestAuthorizationOptionBadge,
87+ const uint64_t hs_requestAuthorizationOptionSound,
88+ const uint64_t hs_requestAuthorizationOptionAlert,
89+ const uint64_t hs_requestAuthorizationOptionCarPlay,
90+ const uint64_t hs_registerForRemoteNotifications,
91+ HsStablePtr hs_didRegisterForRemoteNotificationsWithDeviceToken,
92+ HsStablePtr hs_didFailToRegisterForRemoteNotificationsWithError) {
5593 @autoreleasepool {
94+ global_willFinishLaunchingWithOptions = hs_willFinishLaunchingWithOptions;
95+ global_didFinishLaunchingWithOptions = hs_didFinishLaunchingWithOptions;
96+ global_applicationUniversalLink = hs_applicationUniversalLink;
5697 NSApplication *application = [NSApplication sharedApplication];
5798 AppDelegate *appDelegate = [[AppDelegate alloc] initApp:handler progName:[NSString stringWithCString:progName encoding:NSUTF8StringEncoding]];
5899 [application setDelegate:appDelegate];