Commit e9981efb authored by Felix Paul Kühne's avatar Felix Paul Kühne

macosx: contacting an app using SBApplication can fail, be a bit more...

macosx: contacting an app using SBApplication can fail, be a bit more conservative to prevent runtime exceptions
parent 901d25ad
...@@ -1394,7 +1394,7 @@ static bool f_appExit = false; ...@@ -1394,7 +1394,7 @@ static bool f_appExit = false;
iTunesApplication *iTunesApp = (iTunesApplication *) [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"]; iTunesApplication *iTunesApp = (iTunesApplication *) [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
if (iTunesApp && [iTunesApp isRunning]) { if (iTunesApp && [iTunesApp isRunning]) {
if ([iTunesApp playerState] == iTunesEPlSPaused) { if ([iTunesApp playerState] == iTunesEPlSPaused) {
msg_Dbg(p_intf, "Unpause iTunes..."); msg_Dbg(p_intf, "unpausing iTunes");
[iTunesApp playpause]; [iTunesApp playpause];
} }
} }
...@@ -1402,12 +1402,16 @@ static bool f_appExit = false; ...@@ -1402,12 +1402,16 @@ static bool f_appExit = false;
if (b_has_spotify_paused) { if (b_has_spotify_paused) {
SpotifyApplication *spotifyApp = (SpotifyApplication *) [SBApplication applicationWithBundleIdentifier:@"com.spotify.client"]; SpotifyApplication *spotifyApp = (SpotifyApplication *) [SBApplication applicationWithBundleIdentifier:@"com.spotify.client"];
if (spotifyApp) {
if ([spotifyApp respondsToSelector:@selector(isRunning)] && [spotifyApp respondsToSelector:@selector(playerState)]) {
if ([spotifyApp isRunning] && [spotifyApp playerState] == kSpotifyPlayerStatePaused) { if ([spotifyApp isRunning] && [spotifyApp playerState] == kSpotifyPlayerStatePaused) {
msg_Dbg(p_intf, "Unpause Spotify..."); msg_Dbg(p_intf, "unpausing Spotify");
[spotifyApp play]; [spotifyApp play];
} }
} }
} }
}
}
b_has_itunes_paused = NO; b_has_itunes_paused = NO;
b_has_spotify_paused = NO; b_has_spotify_paused = NO;
...@@ -1437,7 +1441,7 @@ static bool f_appExit = false; ...@@ -1437,7 +1441,7 @@ static bool f_appExit = false;
iTunesApplication *iTunesApp = (iTunesApplication *) [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"]; iTunesApplication *iTunesApp = (iTunesApplication *) [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
if (iTunesApp && [iTunesApp isRunning]) { if (iTunesApp && [iTunesApp isRunning]) {
if ([iTunesApp playerState] == iTunesEPlSPlaying) { if ([iTunesApp playerState] == iTunesEPlSPlaying) {
msg_Dbg(p_intf, "Pause iTunes..."); msg_Dbg(p_intf, "pausing iTunes");
[iTunesApp pause]; [iTunesApp pause];
b_has_itunes_paused = YES; b_has_itunes_paused = YES;
} }
...@@ -1447,13 +1451,18 @@ static bool f_appExit = false; ...@@ -1447,13 +1451,18 @@ static bool f_appExit = false;
// pause Spotify // pause Spotify
if (!b_has_spotify_paused) { if (!b_has_spotify_paused) {
SpotifyApplication *spotifyApp = (SpotifyApplication *) [SBApplication applicationWithBundleIdentifier:@"com.spotify.client"]; SpotifyApplication *spotifyApp = (SpotifyApplication *) [SBApplication applicationWithBundleIdentifier:@"com.spotify.client"];
if (spotifyApp) {
if ([spotifyApp respondsToSelector:@selector(isRunning)] && [spotifyApp respondsToSelector:@selector(playerState)]) {
if ([spotifyApp isRunning] && [spotifyApp playerState] == kSpotifyPlayerStatePlaying) { if ([spotifyApp isRunning] && [spotifyApp playerState] == kSpotifyPlayerStatePlaying) {
msg_Dbg(p_intf, "Pause Spotify..."); msg_Dbg(p_intf, "pausing Spotify");
[spotifyApp pause]; [spotifyApp pause];
b_has_spotify_paused = YES; b_has_spotify_paused = YES;
} }
} }
} }
}
}
/* Declare user activity. /* Declare user activity.
This wakes the display if it is off, and postpones display sleep according to the users system preferences This wakes the display if it is off, and postpones display sleep according to the users system preferences
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment