test: disable real sound playback during checks
This commit is contained in:
parent
55cdf2e8f8
commit
9663028a82
10
src/sound.rs
10
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(()),
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue