Hopefully implemented a proper workaround for new Mojave permissions required for the Media Key event hook. We shouldn't crash any more.
This commit is contained in:
parent
a7eee36cde
commit
6e6648624d
3 changed files with 29 additions and 10 deletions
|
@ -32,8 +32,18 @@
|
||||||
context:nil];
|
context:nil];
|
||||||
|
|
||||||
keyTap = [[SPMediaKeyTap alloc] initWithDelegate:self];
|
keyTap = [[SPMediaKeyTap alloc] initWithDelegate:self];
|
||||||
if([SPMediaKeyTap usesGlobalMediaKeyTap])
|
if([SPMediaKeyTap usesGlobalMediaKeyTap]) {
|
||||||
[keyTap startWatchingMediaKeys];
|
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
|
else
|
||||||
ALog(@"Media key monitoring disabled");
|
ALog(@"Media key monitoring disabled");
|
||||||
}
|
}
|
||||||
|
|
2
ThirdParty/SPMediaKeyTap/SPMediaKeyTap.h
vendored
2
ThirdParty/SPMediaKeyTap/SPMediaKeyTap.h
vendored
|
@ -23,7 +23,7 @@
|
||||||
-(id)initWithDelegate:(id)delegate;
|
-(id)initWithDelegate:(id)delegate;
|
||||||
|
|
||||||
+(BOOL)usesGlobalMediaKeyTap;
|
+(BOOL)usesGlobalMediaKeyTap;
|
||||||
-(void)startWatchingMediaKeys;
|
-(BOOL)startWatchingMediaKeys;
|
||||||
-(void)stopWatchingMediaKeys;
|
-(void)stopWatchingMediaKeys;
|
||||||
-(void)handleAndReleaseMediaKeyEvent:(NSEvent *)event;
|
-(void)handleAndReleaseMediaKeyEvent:(NSEvent *)event;
|
||||||
|
|
||||||
|
|
15
ThirdParty/SPMediaKeyTap/SPMediaKeyTap.m
vendored
15
ThirdParty/SPMediaKeyTap/SPMediaKeyTap.m
vendored
|
@ -60,7 +60,7 @@ static CGEventRef tapEventCallback(CGEventTapProxy proxy, CGEventType type, CGEv
|
||||||
_app_switching_ref = NULL;
|
_app_switching_ref = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)startWatchingMediaKeys;{
|
-(BOOL)startWatchingMediaKeys;{
|
||||||
// Prevent having multiple mediaKeys threads
|
// Prevent having multiple mediaKeys threads
|
||||||
[self stopWatchingMediaKeys];
|
[self stopWatchingMediaKeys];
|
||||||
|
|
||||||
|
@ -74,13 +74,22 @@ static CGEventRef tapEventCallback(CGEventTapProxy proxy, CGEventType type, CGEv
|
||||||
CGEventMaskBit(NX_SYSDEFINED),
|
CGEventMaskBit(NX_SYSDEFINED),
|
||||||
tapEventCallback,
|
tapEventCallback,
|
||||||
(__bridge void*)self);
|
(__bridge void*)self);
|
||||||
assert(_eventPort != NULL);
|
|
||||||
|
|
||||||
|
if (_eventPort != NULL){
|
||||||
_eventPortSource = CFMachPortCreateRunLoopSource(kCFAllocatorSystemDefault, _eventPort, 0);
|
_eventPortSource = CFMachPortCreateRunLoopSource(kCFAllocatorSystemDefault, _eventPort, 0);
|
||||||
assert(_eventPortSource != NULL);
|
|
||||||
|
if (_eventPortSource != NULL){
|
||||||
|
|
||||||
// Let's do this in a separate thread so that a slow app doesn't lag the event tap
|
// 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];
|
[NSThread detachNewThreadSelector:@selector(eventTapThread) toTarget:self withObject:nil];
|
||||||
|
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[self setShouldInterceptMediaKeyEvents:NO];
|
||||||
|
|
||||||
|
return NO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
-(void)stopWatchingMediaKeys;
|
-(void)stopWatchingMediaKeys;
|
||||||
|
|
Loading…
Reference in a new issue