diff --git a/src/sound.rs b/src/sound.rs index a156349b..12b127bb 100644 --- a/src/sound.rs +++ b/src/sound.rs @@ -9,6 +9,8 @@ use std::process::{Command, Output}; use tracing::warn; +const DISABLE_SOUND_ENV: &str = "HERDR_DISABLE_SOUND"; + static SOUND_DONE: &[u8] = include_bytes!("../assets/sounds/done.mp3"); static SOUND_REQUEST: &[u8] = include_bytes!("../assets/sounds/request.mp3"); @@ -24,6 +26,10 @@ pub enum Sound { /// Play a notification sound in a background thread. /// Silently does nothing if no audio player is available. pub fn play(sound: Sound, config: &crate::config::SoundConfig) { + if sound_playback_disabled_by_env() { + return; + } + let custom_path = config.path_for(sound); std::thread::spawn(move || { if let Some(path) = custom_path { @@ -46,6 +52,10 @@ pub fn play(sound: Sound, config: &crate::config::SoundConfig) { }); } +fn sound_playback_disabled_by_env() -> bool { + std::env::var_os(DISABLE_SOUND_ENV).is_some() || std::env::var_os("NEXTEST").is_some() +} + fn play_file(path: &Path) -> Result<(), String> { match run_player(path) { Ok(output) if output.status.success() => Ok(()), diff --git a/tests/client_mode.rs b/tests/client_mode.rs index d5a798ec..8aea0dda 100644 --- a/tests/client_mode.rs +++ b/tests/client_mode.rs @@ -86,6 +86,7 @@ fn spawn_client_process( let mut cmd = CommandBuilder::new(env!("CARGO_BIN_EXE_herdr")); cmd.arg("client"); + cmd.env("HERDR_DISABLE_SOUND", "1"); cmd.env("XDG_CONFIG_HOME", config_home); cmd.env("XDG_RUNTIME_DIR", runtime_dir); cmd.env("HERDR_SOCKET_PATH", api_socket_path); @@ -556,6 +557,7 @@ fn server_unreachable_shows_clear_error() { let output = std::process::Command::new(env!("CARGO_BIN_EXE_herdr")) .arg("client") + .env("HERDR_DISABLE_SOUND", "1") .env("XDG_CONFIG_HOME", &config_home) .env("XDG_RUNTIME_DIR", &runtime_dir) .env("HERDR_SOCKET_PATH", &api_socket) diff --git a/tests/cross_area.rs b/tests/cross_area.rs index 494b694b..3975d402 100644 --- a/tests/cross_area.rs +++ b/tests/cross_area.rs @@ -146,6 +146,7 @@ fn spawn_client_process( let mut cmd = CommandBuilder::new(env!("CARGO_BIN_EXE_herdr")); cmd.arg("client"); + cmd.env("HERDR_DISABLE_SOUND", "1"); cmd.env("XDG_CONFIG_HOME", config_home); cmd.env("XDG_RUNTIME_DIR", runtime_dir); cmd.env("HERDR_SOCKET_PATH", api_socket_path); diff --git a/tests/multi_client.rs b/tests/multi_client.rs index 582fecf7..b74e527c 100644 --- a/tests/multi_client.rs +++ b/tests/multi_client.rs @@ -156,6 +156,7 @@ fn spawn_client_process( let mut cmd = CommandBuilder::new(env!("CARGO_BIN_EXE_herdr")); cmd.arg("client"); + cmd.env("HERDR_DISABLE_SOUND", "1"); cmd.env("XDG_CONFIG_HOME", config_home); cmd.env("XDG_RUNTIME_DIR", runtime_dir); cmd.env("HERDR_SOCKET_PATH", api_socket_path);