Skip to content

Commit

Permalink
Merge pull request #190 from GoXLR-on-Linux/macos-aggergate-disable
Browse files Browse the repository at this point in the history
Macos aggergate disable
  • Loading branch information
FrostyCoolSlug authored Sep 8, 2024
2 parents 3f718e9 + e6e9097 commit 01e8c10
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 0 deletions.
16 changes: 16 additions & 0 deletions daemon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ rather than through additional parameters. When that comes, this will be removed
static OVERRIDE_SAMPLER_INPUT: Mutex<Option<String>> = Mutex::new(None);
static OVERRIDE_SAMPLER_OUTPUT: Mutex<Option<String>> = Mutex::new(None);

/**
This is also ugly, but for now it's important to allow users to simply disable aggregate
management, and have the utility obey.
*/
pub static HANDLE_MACOS_AGGREGATES: Mutex<Option<bool>> = Mutex::new(Some(true));

lazy_static! {
/**
This is a fetcher of the system locale, used for language and translations of the UI.
Expand Down Expand Up @@ -109,6 +115,10 @@ async fn run_utility() -> Result<()> {
let args: Cli = Cli::parse();
let settings = SettingsHandle::load(args.config).await?;

// Set the MacOS Aggregate management..
let aggregates = settings.get_macos_handle_aggregates().await;
HANDLE_MACOS_AGGREGATES.lock().unwrap().replace(aggregates);

// Configure and / or create the log path, and file name.
let log_path = settings.get_log_directory().await;
if !log_path.clone().exists() {
Expand Down Expand Up @@ -187,6 +197,12 @@ async fn run_utility() -> Result<()> {
warn!("Unable to calculate timezone, using UTC for log timestamps");
}

if cfg!(target_os = "macos") {
debug!(
"Configure MacOS Aggregates: {:?}",
HANDLE_MACOS_AGGREGATES.lock().unwrap().unwrap()
);
}
if is_root() {
if args.force_root {
error!("GoXLR Utility running as root, this is generally considered bad.");
Expand Down
5 changes: 5 additions & 0 deletions daemon/src/platform/macos/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::platform::macos::core_audio::{
};
use crate::platform::macos::device::{Inputs, Outputs};
use crate::shutdown::Shutdown;
use crate::HANDLE_MACOS_AGGREGATES;
use tokio::signal::unix::{signal, SignalKind};
use tokio::sync::mpsc;
use tokio::time::sleep;
Expand All @@ -34,6 +35,10 @@ pub async fn run(tx: mpsc::Sender<EventTriggers>, mut stop: Shutdown) -> Result<
}
}

if !HANDLE_MACOS_AGGREGATES.lock().unwrap().unwrap() {
return Ok(());
}

// Ticker to monitor for device changes..
let mut ticker = time::interval(Duration::from_secs(2));

Expand Down
10 changes: 10 additions & 0 deletions daemon/src/primary_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use goxlr_usb::{PID_GOXLR_FULL, PID_GOXLR_MINI};
use json_patch::diff;
use log::{debug, error, info, warn};
use std::collections::{BTreeMap, HashMap};
use std::env;
use std::time::{Duration, Instant};
use tokio::sync::broadcast::Sender as BroadcastSender;
use tokio::sync::mpsc::{Receiver, Sender};
Expand Down Expand Up @@ -346,6 +347,13 @@ pub async fn spawn_usb_handler(
change_found = true;
let _ = sender.send(Ok(()));
}
DaemonCommand::HandleMacOSAggregates(value) => {
settings.set_macos_handle_aggregates(value).await;
settings.save().await;

change_found = true;
let _ = sender.send(Ok(()));
}
}
},

Expand Down Expand Up @@ -447,6 +455,8 @@ async fn get_daemon_status(
active_path: settings.get_activate().await,
app_path: app_check.clone(),
},
platform: env::consts::OS.to_string(),
handle_macos_aggregates: settings.get_macos_handle_aggregates().await,
},
paths: Paths {
profile_directory: settings.get_profile_directory().await,
Expand Down
16 changes: 16 additions & 0 deletions daemon/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ impl SettingsHandle {
selected_locale: None,
tts_enabled: Some(false),
allow_network_access: Some(false),
macos_handle_aggregates: None,
profile_directory: None,
mic_profile_directory: None,
samples_directory: None,
Expand Down Expand Up @@ -140,6 +141,10 @@ impl SettingsHandle {
settings.allow_network_access = Some(false);
}

if settings.macos_handle_aggregates.is_none() {
settings.macos_handle_aggregates = Some(true);
}

if settings.devices.is_none() {
settings.devices = Some(Default::default());
}
Expand Down Expand Up @@ -217,6 +222,16 @@ impl SettingsHandle {
settings.allow_network_access = Some(enabled);
}

pub async fn set_macos_handle_aggregates(&self, enabled: bool) {
let mut settings = self.settings.write().await;
settings.macos_handle_aggregates = Some(enabled);
}

pub async fn get_macos_handle_aggregates(&self) -> bool {
let settings = self.settings.read().await;
settings.macos_handle_aggregates.unwrap()
}

pub async fn get_profile_directory(&self) -> PathBuf {
let settings = self.settings.read().await;
if let Some(directory) = settings.profile_directory.clone() {
Expand Down Expand Up @@ -653,6 +668,7 @@ pub struct Settings {
selected_locale: Option<String>,
tts_enabled: Option<bool>,
allow_network_access: Option<bool>,
macos_handle_aggregates: Option<bool>,
profile_directory: Option<PathBuf>,
mic_profile_directory: Option<PathBuf>,
samples_directory: Option<PathBuf>,
Expand Down
2 changes: 2 additions & 0 deletions ipc/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ pub struct DaemonConfig {
pub allow_network_access: bool,
pub log_level: LogLevel,
pub open_ui_on_launch: bool,
pub platform: String,
pub handle_macos_aggregates: bool,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
Expand Down
2 changes: 2 additions & 0 deletions ipc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ pub enum DaemonCommand {

SetSampleGainPct(String, u8),
ApplySampleChange,

HandleMacOSAggregates(bool),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down

0 comments on commit 01e8c10

Please sign in to comment.