Skip to content

Commit

Permalink
Fix a couple of bugs in iTunes plugin:
Browse files Browse the repository at this point in the history
Sending event just after launch failed because the process cannot be resolved. Use the pid to target it directly.

Some action where using the wrong bundle id to find iTunes.
  • Loading branch information
Jean-Daniel committed Jul 3, 2015
1 parent 13e1d73 commit 7c583d4
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 17 deletions.
2 changes: 1 addition & 1 deletion SparkKit/SparkKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
1BC6A8EC17061FE700E7EA12 /* WBImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BE316D80D3815C9005C3FB2 /* WBImageView.m */; };
1BC6A8ED17061FF300E7EA12 /* WBBezelItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BB983690D381ECC0074D18E /* WBBezelItem.h */; settings = {ATTRIBUTES = (Public, ); }; };
1BC6A8EE17061FF300E7EA12 /* WBBezelItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BB9836A0D381ECC0074D18E /* WBBezelItem.m */; };
1BC6A8EF17061FF300E7EA12 /* WBBezelItemContent.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BB9836B0D381ECC0074D18E /* WBBezelItemContent.h */; settings = {ATTRIBUTES = (Public, ); }; };
1BC6A8EF17061FF300E7EA12 /* WBBezelItemContent.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BB9836B0D381ECC0074D18E /* WBBezelItemContent.h */; };
1BC6A8F017061FF300E7EA12 /* WBBezelItemContent.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BB9836C0D381ECC0074D18E /* WBBezelItemContent.m */; };
1BC6A8F117061FF300E7EA12 /* WBNotificationWindow.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BB9836D0D381ECC0074D18E /* WBNotificationWindow.h */; settings = {ATTRIBUTES = (Public, ); }; };
1BC6A8F217061FF300E7EA12 /* WBNotificationWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BB9836E0D381ECC0074D18E /* WBNotificationWindow.m */; };
Expand Down
7 changes: 5 additions & 2 deletions SparkPlugins/iTunes/Headers/ITunesAESuite.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,11 @@ typedef enum {
} ITunesTrackProperty;

WB_INLINE
OSStatus iTunesSendCommand(ITunesCommand command) {
return WBAESendSimpleEventToBundle(kiTunesBundleIdentifier, kiTunesSuite, command);
OSStatus iTunesSendCommand(ITunesCommand command, pid_t pid) {
if (pid)
return WBAESendSimpleEventTo(pid, kiTunesSuite, command);
else
return WBAESendSimpleEventToBundle(kiTunesBundleIdentifier, kiTunesSuite, command);
}

WB_INLINE
Expand Down
26 changes: 15 additions & 11 deletions SparkPlugins/iTunes/ITunesAction.m
Original file line number Diff line number Diff line change
Expand Up @@ -408,15 +408,15 @@ - (void)notifyLaunch {

static
NSRunningApplication *iTunesLaunch(NSWorkspaceLaunchOptions flags) {
NSURL *url = [[NSWorkspace sharedWorkspace] URLForApplicationWithBundleIdentifier:kiTunesActionBundleIdentifier];
NSURL *url = [[NSWorkspace sharedWorkspace] URLForApplicationWithBundleIdentifier:SPXCFToNSString(kiTunesBundleIdentifier)];
return [[NSWorkspace sharedWorkspace] launchApplicationAtURL:url options:flags configuration:nil error:NULL];
}

- (SparkAlert *)performAction {
SparkAlert *alert = nil;
switch ([self iTunesAction]) {
case kiTunesLaunch: {
NSRunningApplication *iTunes = [NSRunningApplication runningApplicationsWithBundleIdentifier:kiTunesActionBundleIdentifier].firstObject;
NSRunningApplication *iTunes = [NSRunningApplication runningApplicationsWithBundleIdentifier:SPXCFToNSString(kiTunesBundleIdentifier)].firstObject;
if (!iTunes) {
NSWorkspaceLaunchOptions flags = NSWorkspaceLaunchDefault;
if (ia_iaFlags.hide)
Expand All @@ -427,8 +427,12 @@ - (SparkAlert *)performAction {
if (ia_iaFlags.notify) {
[self notifyLaunch];
}
if (ia_iaFlags.autoplay)
iTunesSendCommand(kiTunesCommandPlay);
if (ia_iaFlags.autoplay) {
pid_t pid = iTunes.processIdentifier;
OSStatus err = iTunesSendCommand(kiTunesCommandPlay, pid);
if (noErr != err)
SPXLogError(@"play event failed: %d", err);
}
} else if (!ia_iaFlags.background) {
/* if not launch in background, bring to front */
[iTunes activateWithOptions:NSApplicationActivateIgnoringOtherApps];
Expand All @@ -439,18 +443,18 @@ - (SparkAlert *)performAction {
iTunesQuit();
break;
case kiTunesPlayPause: {
NSRunningApplication *iTunes = [NSRunningApplication runningApplicationsWithBundleIdentifier:kiTunesActionBundleIdentifier].firstObject;
NSRunningApplication *iTunes = [NSRunningApplication runningApplicationsWithBundleIdentifier:SPXCFToNSString(kiTunesBundleIdentifier)].firstObject;
if (!iTunes) {
if (ia_iaFlags.autorun) {
/* Launch iTunes */
iTunesLaunch(NSWorkspaceLaunchDefault | NSWorkspaceLaunchWithoutActivation);
iTunes = iTunesLaunch(NSWorkspaceLaunchDefault | NSWorkspaceLaunchWithoutActivation);
/* Display iTunes Icon */
[self notifyLaunch];
/* Send Play event*/
iTunesSendCommand(kiTunesCommandPlay);
iTunesSendCommand(kiTunesCommandPlay, iTunes.processIdentifier);
}
} else {
iTunesSendCommand(kiTunesCommandPlayPause);
iTunesSendCommand(kiTunesCommandPlayPause, iTunes.processIdentifier);
[self displayInfoIfRunning];
}
}
Expand All @@ -459,15 +463,15 @@ - (SparkAlert *)performAction {
alert = [self playPlaylist];
break;
case kiTunesNextTrack:
iTunesSendCommand(kiTunesCommandNextTrack);
iTunesSendCommand(kiTunesCommandNextTrack, 0);
[self displayInfoIfNeeded];
break;
case kiTunesBackTrack:
iTunesSendCommand(kiTunesCommandPreviousTrack);
iTunesSendCommand(kiTunesCommandPreviousTrack, 0);
[self displayInfoIfNeeded];
break;
case kiTunesStop:
iTunesSendCommand(kiTunesCommandStopPlaying);
iTunesSendCommand(kiTunesCommandStopPlaying, 0);
break;
case kiTunesShowTrackInfo:
[self displayTrackNotification];
Expand Down
2 changes: 1 addition & 1 deletion SparkPlugins/iTunes/ITunesActionPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ - (NSArray *)playlists {
NSURL *_iTunesGetLibraryPathFromPreferences(Boolean compat) {
NSURL *path = nil;
CFDataRef data = CFPreferencesCopyValue(CFSTR("alis:1:iTunes Library Location"),
CFSTR("com.apple.iTunes"),
kiTunesBundleIdentifier,
kCFPreferencesCurrentUser,
kCFPreferencesAnyHost);
if (data) {
Expand Down
6 changes: 5 additions & 1 deletion SparkPlugins/iTunes/ITunesVisualSetting.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ - (id)init {
return self;
}

- (void)dealloc {
[ia_info close];
}

- (IBAction)hide:(id)sender {
[[ia_info window] close];
[[ia_info window] setIgnoresMouseEvents:YES];
Expand All @@ -48,7 +52,7 @@ - (IBAction)hide:(id)sender {

- (IBAction)show:(id)sender {
[[ia_info window] setIgnoresMouseEvents:NO];
[ia_info showWindow:sender];
[ia_info.window orderFront:sender];

[ibShow setTitle:NSLocalizedStringFromTableInBundle(@"Hide", nil, kiTunesActionBundle,
@"Hide/Show button * Visual settings *")];
Expand Down

0 comments on commit 7c583d4

Please sign in to comment.