Disable MPRemoteCommandCenter unless on Mojave or newer

CQTexperiment
Christopher Snowhill 2020-02-28 00:40:29 -08:00
parent 004c53962a
commit d05ada5d0a
1 changed files with 34 additions and 21 deletions

View File

@ -37,7 +37,15 @@
options:NSKeyValueObservingOptionNew options:NSKeyValueObservingOptionNew
context:nil]; context:nil];
if (NSClassFromString(@"MPRemoteCommandCenter")) { NSProcessInfo *processInfo = [NSProcessInfo processInfo];
if ([processInfo respondsToSelector:@selector(isOperatingSystemAtLeastVersion:)]) {
// For some STUPID reason, this interface only really works properly
// on Mojave or newer. On the other hand, the fallback interface
// only stopped working on Catalina
NSOperatingSystemVersion version = {10,14};
if ([processInfo isOperatingSystemAtLeastVersion:version] && NSClassFromString(@"MPRemoteCommandCenter")) {
MPRemoteCommandCenter *remoteCommandCenter = [MPRemoteCommandCenter sharedCommandCenter]; MPRemoteCommandCenter *remoteCommandCenter = [MPRemoteCommandCenter sharedCommandCenter];
[remoteCommandCenter.playCommand setEnabled:YES]; [remoteCommandCenter.playCommand setEnabled:YES];
@ -55,7 +63,12 @@
[[remoteCommandCenter changePlaybackPositionCommand] addTarget:self action:@selector(clickSeek:)]; [[remoteCommandCenter changePlaybackPositionCommand] addTarget:self action:@selector(clickSeek:)];
[[remoteCommandCenter nextTrackCommand] addTarget:self action:@selector(clickNext)]; [[remoteCommandCenter nextTrackCommand] addTarget:self action:@selector(clickNext)];
[[remoteCommandCenter previousTrackCommand] addTarget:self action:@selector(clickPrev)]; [[remoteCommandCenter previousTrackCommand] addTarget:self action:@selector(clickPrev)];
} else {
return;
}
}
{
keyTap = [[SPMediaKeyTap alloc] initWithDelegate:self]; keyTap = [[SPMediaKeyTap alloc] initWithDelegate:self];
if([SPMediaKeyTap usesGlobalMediaKeyTap]) { if([SPMediaKeyTap usesGlobalMediaKeyTap]) {
[keyTap startWatchingMediaKeys]; [keyTap startWatchingMediaKeys];
@ -120,17 +133,17 @@
switch( keyCode ) switch( keyCode )
{ {
case NX_KEYTYPE_PLAY: case NX_KEYTYPE_PLAY:
[(AppController *)[self delegate] clickPlay]; [self clickPlay];
break; break;
case NX_KEYTYPE_NEXT: case NX_KEYTYPE_NEXT:
case NX_KEYTYPE_FAST: case NX_KEYTYPE_FAST:
[(AppController *)[self delegate] clickNext]; [self clickNext];
break; break;
case NX_KEYTYPE_PREVIOUS: case NX_KEYTYPE_PREVIOUS:
case NX_KEYTYPE_REWIND: case NX_KEYTYPE_REWIND:
[(AppController *)[self delegate] clickPrev]; [self clickPrev];
break; break;
} }
} }