From dad73b1f0cfa9eac6703a98d055f6b999f4afaa2 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 5 Apr 2020 10:47:58 -0700 Subject: [PATCH] Fixed bug 5073 - SDL does not handle URL Schemes in MacOS Jason In iOS, URL Events trigger the DropFile event. I would also expect the same event to be fired on the macOS platform but this is not implemented at all in the AppDelegate. --- src/video/cocoa/SDL_cocoaevents.m | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/video/cocoa/SDL_cocoaevents.m b/src/video/cocoa/SDL_cocoaevents.m index 0de74df31..1cc24b480 100644 --- a/src/video/cocoa/SDL_cocoaevents.m +++ b/src/video/cocoa/SDL_cocoaevents.m @@ -248,10 +248,24 @@ static void Cocoa_DispatchEvent(NSEvent *theEvent) [NSApp activateIgnoringOtherApps:YES]; } + [[NSAppleEventManager sharedAppleEventManager] + setEventHandler:self + andSelector:@selector(handleURLEvent:withReplyEvent:) + forEventClass:kInternetEventClass + andEventID:kAEGetURL]; + /* If we call this before NSApp activation, macOS might print a complaint * about ApplePersistenceIgnoreState. */ [SDLApplication registerUserDefaults]; } + +- (void)handleURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent +{ + NSString* path = [[event paramDescriptorForKeyword:keyDirectObject] stringValue]; + SDL_SendDropFile(NULL, [path UTF8String]); + SDL_SendDropComplete(NULL); +} + @end static SDLAppDelegate *appDelegate = nil;