From b0797e8fe99bf5eb0b399ad2a57b62e8f0c71fed Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 7 Sep 2013 11:49:04 +0200 Subject: macosx_application: handle URL events as fileopen events This allows to open URLs directly with mpv. This is useful for streaming and libquvi supported sites. --- osdep/macosx_application.m | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'osdep/macosx_application.m') diff --git a/osdep/macosx_application.m b/osdep/macosx_application.m index fb20fbf2cc..7c5990d912 100644 --- a/osdep/macosx_application.m +++ b/osdep/macosx_application.m @@ -97,11 +97,25 @@ static NSString *escape_loadfile_name(NSString *input) handler:^(NSEvent *event) { return [self.eventsResponder handleKey:event]; }]; + + NSAppleEventManager *em = [NSAppleEventManager sharedAppleEventManager]; + [em setEventHandler:self + andSelector:@selector(getUrl:withReplyEvent:) + forEventClass:kInternetEventClass + andEventID:kAEGetURL]; } return self; } +- (void)dealloc +{ + NSAppleEventManager *em = [NSAppleEventManager sharedAppleEventManager]; + [em removeEventHandlerForEventClass:kInternetEventClass + andEventID:kAEGetURL]; + [super dealloc]; +} + #define _R(P, T, E, K) \ { \ NSMenuItem *tmp = [self menuItemWithParent:(P) title:(T) \ @@ -221,6 +235,22 @@ static NSString *escape_loadfile_name(NSString *input) [self stopPlayback]; } +- (void)getUrl:(NSAppleEventDescriptor *)event + withReplyEvent:(NSAppleEventDescriptor *)replyEvent +{ + NSString *url = + [[event paramDescriptorForKeyword:keyDirectObject] stringValue]; + + self.files = @[url]; + + if (self.willStopOnOpenEvent) { + self.willStopOnOpenEvent = NO; + cocoa_stop_runloop(); + } else { + [self handleFiles]; + } +} + - (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames { Application *app = mpv_shared_app(); -- cgit v1.2.3