aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOgulcan Celik <ogulcancelik@gmail.com>2026-03-28 01:02:10 +0300
committerOgulcan Celik <ogulcancelik@gmail.com>2026-03-28 01:02:10 +0300
commite719c6517d6cc2ef2b51a056725d2558c5fb94fa (patch)
tree4a485f244ddd0af7dcbc5d1ab3dec1652bf7057b
parent380778a9286a941d14c7af166de14836ec4c2d0f (diff)
fix sound request alerts in active workspace
-rw-r--r--src/app/actions.rs54
-rw-r--r--src/sound.rs1
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,