Skip to content

Commit

Permalink
Partial fix for apps' bundle IDs not matching their HAL clients.
Browse files Browse the repository at this point in the history
Some apps have different bundle IDs to their CoreAudio clients, so
the bundle ID BGMApp sends with the app's volume doesn't match any
client in BGMDriver.

This change hardcodes the bundle IDs used by some popular apps and the
bundle IDs their clients use. We should be able to fix this for all
(almost all?) apps at some point.
  • Loading branch information
kyleneideck committed Jun 22, 2017
1 parent 5a657a0 commit c907f13
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
8 changes: 6 additions & 2 deletions BGMApp/BGMApp/BGMAppVolumes.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,19 @@

@interface BGMAppVolumes : NSObject

- (id) initWithMenu:(NSMenu*)menu appVolumeView:(NSView*)view audioDevices:(BGMAudioDeviceManager*)audioDevices;
- (id) initWithMenu:(NSMenu*)menu
appVolumeView:(NSView*)view
audioDevices:(BGMAudioDeviceManager*)audioDevices;

@end

// Protocol for the UI custom classes

@protocol BGMAppVolumeMenuItemSubview <NSObject>

- (void) setUpWithApp:(NSRunningApplication*)app context:(BGMAppVolumes*)ctx menuItem:(NSMenuItem*)item;
- (void) setUpWithApp:(NSRunningApplication*)app
context:(BGMAppVolumes*)ctx
menuItem:(NSMenuItem*)item;

@end

Expand Down
39 changes: 37 additions & 2 deletions BGMApp/BGMApp/BGMAppVolumes.mm
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,33 @@ - (void) sendPanPositionChangeToBGMDevice:(SInt32)newPanPosition appProcessID:(p
[audioDevices bgmDevice].SetPropertyData_CFType(kBGMAppVolumesAddress, appVolumeChanges.AsPropertyList());
}

// This is a temporary solution that lets us control the volumes of some multiprocess apps, i.e.
// apps that play their audio from a process with a different bundle ID.
//
// We can't just check the child processes of the apps' main processes because they're usually
// created with launchd rather than being actual child processes. There's a private API to get the
// processes that an app is "responsible for", so we'll try to use it in the proper fix and only use
// this list if the API doesn't work.
//
// TODO: Consider moving the logic to a new class when we fix this issue properly so this class is
// only responsible for UI.
+ (NSArray<NSString*>*) responsibleBundleIDsOf:(NSString*)parentBundleID {
NSDictionary<NSString*, NSArray<NSString*>*>* bundleIDMap = @{
// Safari
@"com.apple.Safari": @[@"com.apple.WebKit.WebContent"],
// Firefox
@"org.mozilla.firefox": @[@"org.mozilla.plugincontainer"],
// Firefox Nightly
@"org.mozilla.nightly": @[@"org.mozilla.plugincontainer"],
// VMWare Fusion
@"com.vmware.fusion": @[@"com.vmware.vmware-vmx"],
// MPlayer OSX Extended
@"hu.mplayerhq.mplayerosx.extended": @[@"ch.sttz.mplayerosx.extended.binaries.officialsvn"]
};

return bundleIDMap[parentBundleID];
}

@end

#pragma mark Custom Classes (IB)
Expand Down Expand Up @@ -428,8 +455,12 @@ - (void) appVolumeChanged {
DebugMsg("BGMAppVolumes::appVolumeChanged: App volume for %s changed to %d", appBundleID.UTF8String, self.intValue);

[self snap];

[context sendVolumeChangeToBGMDevice:self.intValue appProcessID:appProcessID appBundleID:appBundleID];

for (NSString* bundleID : [BGMAppVolumes responsibleBundleIDsOf:appBundleID]) {
[context sendVolumeChangeToBGMDevice:self.intValue appProcessID:-1 appBundleID:bundleID];
}
}

@end
Expand Down Expand Up @@ -471,8 +502,12 @@ - (void) appPanPositionChanged {
// TODO: This (sending updates to the driver) should probably be rate-limited. It uses a fair bit of CPU for me.

DebugMsg("BGMAppVolumes::appPanPositionChanged: App pan position for %s changed to %d", appBundleID.UTF8String, self.intValue);

[context sendPanPositionChangeToBGMDevice:self.intValue appProcessID:appProcessID appBundleID:appBundleID];

for (NSString* bundleID : [BGMAppVolumes responsibleBundleIDsOf:appBundleID]) {
[context sendPanPositionChangeToBGMDevice:self.intValue appProcessID:-1 appBundleID:bundleID];
}
}

@end
Expand Down

0 comments on commit c907f13

Please sign in to comment.