diff --git a/termua/src/footbar/mod.rs b/termua/src/footbar/mod.rs index 0ea0c59..95b2054 100644 --- a/termua/src/footbar/mod.rs +++ b/termua/src/footbar/mod.rs @@ -16,6 +16,7 @@ use crate::{ globals::{ensure_ctx_global, ensure_ctx_global_with}, lock_screen, notification, right_sidebar::{RightSidebarState, RightSidebarTab}, + settings::AssistantSettings, }; mod transfers; @@ -93,6 +94,7 @@ impl FootbarView { lock_enabled: bool, lock_tooltip: SharedString, messages_selected: bool, + assistant_enabled: bool, assistant_selected: bool, ) -> gpui::AnyElement { h_flex() @@ -152,19 +154,24 @@ impl FootbarView { crate::menu::toggle_messages_sidebar(&crate::ToggleMessagesSidebar, cx) }), ) - .child( - Button::new("termua-footbar-assistant-button") - .xsmall() - .compact() - .ghost() - .icon(Icon::default().path(TermuaIcon::Bot)) - .tooltip(t!("Footbar.Tooltip.Assistant").to_string()) - .selected(assistant_selected) - .debug_selector(|| "termua-footbar-assistant".to_string()) - .on_click(|_, _, cx| { - crate::menu::toggle_assistant_sidebar(&crate::ToggleAssistantSidebar, cx) - }), - ) + .when(assistant_enabled, |this| { + this.child( + Button::new("termua-footbar-assistant-button") + .xsmall() + .compact() + .ghost() + .icon(Icon::default().path(TermuaIcon::Bot)) + .tooltip(t!("Footbar.Tooltip.Assistant").to_string()) + .selected(assistant_selected) + .debug_selector(|| "termua-footbar-assistant".to_string()) + .on_click(|_, _, cx| { + crate::menu::toggle_assistant_sidebar( + &crate::ToggleAssistantSidebar, + cx, + ) + }), + ) + }) .into_any_element() } } @@ -189,7 +196,19 @@ impl Render for FootbarView { let sessions_visible = cx.global::().sessions_sidebar_visible; let right = cx.global::(); let messages_selected = right.visible && right.active_tab == RightSidebarTab::Notifications; - let assistant_selected = right.visible && right.active_tab == RightSidebarTab::Assistant; + let assistant_enabled = cx + .try_global::() + .map(|s| s.enabled) + .unwrap_or(true); + let assistant_selected = + assistant_enabled && right.visible && right.active_tab == RightSidebarTab::Assistant; + + // When assistant is disabled while the AI panel is open, close the panel. + if !assistant_enabled && right.visible && right.active_tab == RightSidebarTab::Assistant { + cx.defer(|cx| { + crate::menu::toggle_assistant_sidebar(&crate::ToggleAssistantSidebar, cx); + }); + } let icon_path = Self::multi_exec_icon_path(enabled); let lock_state = cx.global::(); @@ -217,6 +236,7 @@ impl Render for FootbarView { lock_enabled, lock_tooltip, messages_selected, + assistant_enabled, assistant_selected, ); diff --git a/termua/src/menu.rs b/termua/src/menu.rs index 5ba35e9..5eda8c8 100644 --- a/termua/src/menu.rs +++ b/termua/src/menu.rs @@ -217,9 +217,22 @@ pub(crate) fn toggle_messages_sidebar(_: &ToggleMessagesSidebar, cx: &mut App) { } pub(crate) fn toggle_assistant_sidebar(_: &ToggleAssistantSidebar, cx: &mut App) { + let assistant_enabled = cx + .try_global::() + .map(|s| s.enabled) + .unwrap_or(true); + if cx.try_global::().is_none() { cx.set_global(RightSidebarState::default()); } + + // Block opening the assistant panel when the feature is disabled, + // but allow closing it if it was already open (e.g. after a settings change). + let state = cx.global::(); + if !assistant_enabled && !(state.visible && state.active_tab == RightSidebarTab::Assistant) { + return; + } + cx.global_mut::() .toggle_tab(RightSidebarTab::Assistant); cx.refresh_windows(); diff --git a/termua/src/window/settings/view.rs b/termua/src/window/settings/view.rs index 1244d9a..a1a7f15 100644 --- a/termua/src/window/settings/view.rs +++ b/termua/src/window/settings/view.rs @@ -1266,6 +1266,7 @@ impl SettingsWindow { this.settings.assistant.enabled = checked; this.settings.apply_assistant_settings(cx); this.save_only(window, cx); + cx.refresh_windows(); if checked { // If enabled and zeroclaw isn't running, pull it up.