diff --git a/Application/MediaKeysApplication.m b/Application/MediaKeysApplication.m index 2fba4ced0..e99fd994e 100644 --- a/Application/MediaKeysApplication.m +++ b/Application/MediaKeysApplication.m @@ -32,8 +32,18 @@ context:nil]; keyTap = [[SPMediaKeyTap alloc] initWithDelegate:self]; - if([SPMediaKeyTap usesGlobalMediaKeyTap]) - [keyTap startWatchingMediaKeys]; + if([SPMediaKeyTap usesGlobalMediaKeyTap]) { + NSAlert *alert = [[NSAlert alloc] init]; + [alert addButtonWithTitle:@"Retry"]; + [alert addButtonWithTitle:@"Cancel"]; + [alert setMessageText:@"Enable Media Key access?"]; + [alert setInformativeText:@"Media Key support requires the \"Accessibility\" permission."]; + [alert setAlertStyle:NSInformationalAlertStyle]; + while (![keyTap startWatchingMediaKeys]) { + if ([alert runModal] == NSAlertFirstButtonReturn) continue; + else break; + } + } else ALog(@"Media key monitoring disabled"); } diff --git a/ThirdParty/SPMediaKeyTap/SPMediaKeyTap.h b/ThirdParty/SPMediaKeyTap/SPMediaKeyTap.h index d2ed793b8..f3c864fdc 100644 --- a/ThirdParty/SPMediaKeyTap/SPMediaKeyTap.h +++ b/ThirdParty/SPMediaKeyTap/SPMediaKeyTap.h @@ -23,7 +23,7 @@ -(id)initWithDelegate:(id)delegate; +(BOOL)usesGlobalMediaKeyTap; --(void)startWatchingMediaKeys; +-(BOOL)startWatchingMediaKeys; -(void)stopWatchingMediaKeys; -(void)handleAndReleaseMediaKeyEvent:(NSEvent *)event; diff --git a/ThirdParty/SPMediaKeyTap/SPMediaKeyTap.m b/ThirdParty/SPMediaKeyTap/SPMediaKeyTap.m index 04271f3e0..502857de4 100644 --- a/ThirdParty/SPMediaKeyTap/SPMediaKeyTap.m +++ b/ThirdParty/SPMediaKeyTap/SPMediaKeyTap.m @@ -60,7 +60,7 @@ static CGEventRef tapEventCallback(CGEventTapProxy proxy, CGEventType type, CGEv _app_switching_ref = NULL; } --(void)startWatchingMediaKeys;{ +-(BOOL)startWatchingMediaKeys;{ // Prevent having multiple mediaKeys threads [self stopWatchingMediaKeys]; @@ -74,13 +74,22 @@ static CGEventRef tapEventCallback(CGEventTapProxy proxy, CGEventType type, CGEv CGEventMaskBit(NX_SYSDEFINED), tapEventCallback, (__bridge void*)self); - assert(_eventPort != NULL); + + if (_eventPort != NULL){ + _eventPortSource = CFMachPortCreateRunLoopSource(kCFAllocatorSystemDefault, _eventPort, 0); + + if (_eventPortSource != NULL){ - _eventPortSource = CFMachPortCreateRunLoopSource(kCFAllocatorSystemDefault, _eventPort, 0); - assert(_eventPortSource != NULL); - - // Let's do this in a separate thread so that a slow app doesn't lag the event tap - [NSThread detachNewThreadSelector:@selector(eventTapThread) toTarget:self withObject:nil]; + // Let's do this in a separate thread so that a slow app doesn't lag the event tap + [NSThread detachNewThreadSelector:@selector(eventTapThread) toTarget:self withObject:nil]; + + return YES; + } + } + + [self setShouldInterceptMediaKeyEvents:NO]; + + return NO; } } -(void)stopWatchingMediaKeys;