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,25 +37,38 @@
options:NSKeyValueObservingOptionNew options:NSKeyValueObservingOptionNew
context:nil]; context:nil];
if (NSClassFromString(@"MPRemoteCommandCenter")) { NSProcessInfo *processInfo = [NSProcessInfo processInfo];
MPRemoteCommandCenter *remoteCommandCenter = [MPRemoteCommandCenter sharedCommandCenter];
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
[remoteCommandCenter.playCommand setEnabled:YES]; NSOperatingSystemVersion version = {10,14};
[remoteCommandCenter.pauseCommand setEnabled:YES]; if ([processInfo isOperatingSystemAtLeastVersion:version] && NSClassFromString(@"MPRemoteCommandCenter")) {
[remoteCommandCenter.togglePlayPauseCommand setEnabled:YES]; MPRemoteCommandCenter *remoteCommandCenter = [MPRemoteCommandCenter sharedCommandCenter];
[remoteCommandCenter.stopCommand setEnabled:YES];
[remoteCommandCenter.changePlaybackPositionCommand setEnabled:YES]; [remoteCommandCenter.playCommand setEnabled:YES];
[remoteCommandCenter.nextTrackCommand setEnabled:YES]; [remoteCommandCenter.pauseCommand setEnabled:YES];
[remoteCommandCenter.previousTrackCommand setEnabled:YES]; [remoteCommandCenter.togglePlayPauseCommand setEnabled:YES];
[remoteCommandCenter.stopCommand setEnabled:YES];
[[remoteCommandCenter playCommand] addTarget:self action:@selector(clickPlay)]; [remoteCommandCenter.changePlaybackPositionCommand setEnabled:YES];
[[remoteCommandCenter pauseCommand] addTarget:self action:@selector(clickPause)]; [remoteCommandCenter.nextTrackCommand setEnabled:YES];
[[remoteCommandCenter togglePlayPauseCommand] addTarget:self action:@selector(clickPlay)]; [remoteCommandCenter.previousTrackCommand setEnabled:YES];
[[remoteCommandCenter stopCommand] addTarget:self action:@selector(clickStop)];
[[remoteCommandCenter changePlaybackPositionCommand] addTarget:self action:@selector(clickSeek:)]; [[remoteCommandCenter playCommand] addTarget:self action:@selector(clickPlay)];
[[remoteCommandCenter nextTrackCommand] addTarget:self action:@selector(clickNext)]; [[remoteCommandCenter pauseCommand] addTarget:self action:@selector(clickPause)];
[[remoteCommandCenter previousTrackCommand] addTarget:self action:@selector(clickPrev)]; [[remoteCommandCenter togglePlayPauseCommand] addTarget:self action:@selector(clickPlay)];
} else { [[remoteCommandCenter stopCommand] addTarget:self action:@selector(clickStop)];
[[remoteCommandCenter changePlaybackPositionCommand] addTarget:self action:@selector(clickSeek:)];
[[remoteCommandCenter nextTrackCommand] addTarget:self action:@selector(clickNext)];
[[remoteCommandCenter previousTrackCommand] addTarget:self action:@selector(clickPrev)];
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;
} }
} }