Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions BGMApp/BGMApp/BGMAppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

static NSString* const kOptNoPersistentData = @"--no-persistent-data";
static NSString* const kOptShowDockIcon = @"--show-dock-icon";
static NSString* const kOptSafeAudioMode = @"--safe-audio-mode";

@implementation BGMAppDelegate {
// The button in the system status bar that shows the main menu.
Expand Down Expand Up @@ -121,8 +122,13 @@ - (void) applicationDidFinishLaunching:(NSNotification*)aNotification {

// Skip this if we're compiling on a version of macOS before 10.14 as won't compile and it
// isn't needed.
if ([NSProcessInfo.processInfo.arguments indexOfObject:kOptSafeAudioMode] != NSNotFound) {
DebugMsg("BGMAppDelegate::applicationDidFinishLaunching: Safe audio mode enabled "
"from launch argument %s", kOptSafeAudioMode.UTF8String);
[self continueLaunchAfterInputDevicePermissionGranted];
}
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400 // MAC_OS_X_VERSION_10_14
if (@available(macOS 10.14, *)) {
else if (@available(macOS 10.14, *)) {
// On macOS 10.14+ we need to get the user's permission to use input devices before we can
// use BGMDevice for playthrough (see BGMPlayThrough), so we wait until they've given it
// before making BGMDevice the default device. This way, if the user is playing audio when
Expand All @@ -146,7 +152,7 @@ - (void) applicationDidFinishLaunching:(NSNotification*)aNotification {
"audio.\n\nYou can grant the permission by going to "
"System Preferences > Security and Privacy > "
"Microphone and checking the box for Background Music."
exitAfterMessageDismissed:YES];
exitAfterMessageDismissed:YES];
}
});
}];
Expand All @@ -161,11 +167,19 @@ - (void) applicationDidFinishLaunching:(NSNotification*)aNotification {
}

- (void) continueLaunchAfterInputDevicePermissionGranted {
BOOL safeAudioModeEnabled = [NSProcessInfo.processInfo.arguments
indexOfObject:kOptSafeAudioMode] != NSNotFound;

// Choose an output device for BGMApp to use to play audio.
if (![self setInitialOutputDevice]) {
return;
}

if (safeAudioModeEnabled) {
DebugMsg("BGMAppDelegate::continueLaunchAfterInputDevicePermissionGranted: "
"Safe audio mode enabled; using normal default-output routing.");
}

// Make BGMDevice the default device.
[self setBGMDeviceAsDefault];

Expand Down Expand Up @@ -541,4 +555,3 @@ - (void) menu:(NSMenu*)menu willHighlightItem:(NSMenuItem* __nullable)item {
@end

#pragma clang assume_nonnull end

Loading