diff --git a/crates/agent_ui/src/acp/thread_view.rs b/crates/agent_ui/src/acp/thread_view.rs index 13a454cdeaa5ccf0a99253ab896075ff0bce9007..e15ca9557346c43e8dd637006756d1939ec75631 100644 --- a/crates/agent_ui/src/acp/thread_view.rs +++ b/crates/agent_ui/src/acp/thread_view.rs @@ -2151,30 +2151,40 @@ impl AcpServerView { self.show_notification(caption, icon, window, cx); } - fn agent_is_visible(&self, window: &Window, cx: &App) -> bool { - if window.is_window_active() { - let workspace_is_foreground = window - .root::() - .flatten() - .and_then(|mw| { - let mw = mw.read(cx); - self.workspace.upgrade().map(|ws| mw.workspace() == &ws) - }) - .unwrap_or(true); + fn agent_panel_visible(&self, multi_workspace: &Entity, cx: &App) -> bool { + let Some(workspace) = self.workspace.upgrade() else { + return false; + }; - if workspace_is_foreground { - if let Some(workspace) = self.workspace.upgrade() { - return AgentPanel::is_visible(&workspace, cx); - } - } + multi_workspace.read(cx).workspace() == &workspace && AgentPanel::is_visible(&workspace, cx) + } + + fn agent_status_visible(&self, window: &Window, cx: &App) -> bool { + if !window.is_window_active() { + return false; } - false + if let Some(multi_workspace) = window.root::().flatten() { + multi_workspace.read(cx).is_sidebar_open() + || self.agent_panel_visible(&multi_workspace, cx) + } else { + self.workspace + .upgrade() + .is_some_and(|workspace| AgentPanel::is_visible(&workspace, cx)) + } } fn play_notification_sound(&self, window: &Window, cx: &mut App) { let settings = AgentSettings::get_global(cx); - if settings.play_sound_when_agent_done && !self.agent_is_visible(window, cx) { + let visible = window.is_window_active() + && if let Some(mw) = window.root::().flatten() { + self.agent_panel_visible(&mw, cx) + } else { + self.workspace + .upgrade() + .is_some_and(|workspace| AgentPanel::is_visible(&workspace, cx)) + }; + if settings.play_sound_when_agent_done && !visible { Audio::play_sound(Sound::AgentDone, cx); } } @@ -2192,7 +2202,7 @@ impl AcpServerView { let settings = AgentSettings::get_global(cx); - let should_notify = !self.agent_is_visible(window, cx); + let should_notify = !self.agent_status_visible(window, cx); if !should_notify { return; @@ -2296,7 +2306,7 @@ impl AcpServerView { let pop_up_weak = pop_up.downgrade(); cx.observe_window_activation(window, move |this, window, cx| { - if this.agent_is_visible(window, cx) + if this.agent_status_visible(window, cx) && let Some(pop_up) = pop_up_weak.upgrade() { pop_up.update(cx, |notification, cx| {