diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/app/actions.rs | 54 | ||||
| -rw-r--r-- | src/sound.rs | 1 |
2 files changed, 45 insertions, 10 deletions
diff --git a/src/app/actions.rs b/src/app/actions.rs index 98159fcc..787f6869 100644 --- a/src/app/actions.rs +++ b/src/app/actions.rs @@ -9,6 +9,24 @@ use crate::layout::{find_in_direction, NavDirection, PaneId}; use super::state::{AppState, Mode}; +fn notification_sound_for_state_change( + is_active_ws: bool, + prev_state: AgentState, + new_state: AgentState, +) -> Option<crate::sound::Sound> { + if new_state == prev_state { + return None; + } + + match new_state { + AgentState::Waiting => Some(crate::sound::Sound::Request), + AgentState::Idle if prev_state != AgentState::Idle && !is_active_ws => { + Some(crate::sound::Sound::Done) + } + _ => None, + } +} + // --------------------------------------------------------------------------- // Workspace operations // --------------------------------------------------------------------------- @@ -168,16 +186,12 @@ impl AppState { pane.seen = false; } - // Sound notifications for background state changes - if self.sound.allows(agent) && !is_active_ws && state != prev_state { - match state { - AgentState::Idle if prev_state != AgentState::Idle => { - crate::sound::play(crate::sound::Sound::Done); - } - AgentState::Waiting => { - crate::sound::play(crate::sound::Sound::Request); - } - _ => {} + // Waiting prompts should always make noise; done sounds stay background-only. + if self.sound.allows(agent) { + if let Some(sound) = + notification_sound_for_state_change(is_active_ws, prev_state, state) + { + crate::sound::play(sound); } } @@ -409,6 +423,26 @@ mod tests { } #[test] + fn waiting_sound_plays_even_in_active_workspace() { + assert_eq!( + notification_sound_for_state_change(true, AgentState::Busy, AgentState::Waiting), + Some(crate::sound::Sound::Request) + ); + } + + #[test] + fn done_sound_only_plays_in_background() { + assert_eq!( + notification_sound_for_state_change(false, AgentState::Busy, AgentState::Idle), + Some(crate::sound::Sound::Done) + ); + assert_eq!( + notification_sound_for_state_change(true, AgentState::Busy, AgentState::Idle), + None + ); + } + + #[test] fn toggle_fullscreen_works() { let mut state = app_with_workspaces(&["test"]); state.workspaces[0].test_split(Direction::Horizontal); diff --git a/src/sound.rs b/src/sound.rs index e184d02c..8f769701 100644 --- a/src/sound.rs +++ b/src/sound.rs @@ -10,6 +10,7 @@ static SOUND_DONE: &[u8] = include_bytes!("../assets/sounds/done.mp3"); static SOUND_REQUEST: &[u8] = include_bytes!("../assets/sounds/request.mp3"); /// Which notification sound to play. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Sound { /// Agent finished work (transitioned to Idle). Done, |
