From ab28382d58aa4755366e317daaab5dddd58a52fc Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Fri, 24 Oct 2025 18:25:47 +0200 Subject: [PATCH] Replace service toggle with separate start/stop commands - Change Space key toggle to 's' for start and 'S' for stop - Remove problematic service status detection logic - Update statusbar shortcuts to show S/Shift+S instead of Space - Split UiCommand::ServiceStartStop into ServiceStart and ServiceStop - Simplify command handling with explicit actions This resolves the toggle bug where Space always sent start commands regardless of current service status. --- dashboard/src/app.rs | 28 ++++++++++++---------------- dashboard/src/ui/mod.rs | 22 ++++++++++++++++------ 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/dashboard/src/app.rs b/dashboard/src/app.rs index d062603..e4eccd4 100644 --- a/dashboard/src/app.rs +++ b/dashboard/src/app.rs @@ -279,23 +279,19 @@ impl Dashboard { }; self.zmq_command_sender.send_command(&hostname, agent_command).await?; } - UiCommand::ServiceStartStop { hostname, service_name } => { - // Check current service status and toggle appropriately - let current_status = self.get_service_status(&hostname, &service_name); - let action = match current_status { - Some(status) if status.contains("active") || status.contains("running") => { - info!("Sending stop command for active service {} on {}", service_name, hostname); - ServiceAction::Stop - } - _ => { - info!("Sending start command for inactive service {} on {}", service_name, hostname); - ServiceAction::Start - } - }; - + UiCommand::ServiceStart { hostname, service_name } => { + info!("Sending start command for service {} on {}", service_name, hostname); let agent_command = AgentCommand::ServiceControl { - service_name, - action, + service_name: service_name.clone(), + action: ServiceAction::Start, + }; + self.zmq_command_sender.send_command(&hostname, agent_command).await?; + } + UiCommand::ServiceStop { hostname, service_name } => { + info!("Sending stop command for service {} on {}", service_name, hostname); + let agent_command = AgentCommand::ServiceControl { + service_name: service_name.clone(), + action: ServiceAction::Stop, }; self.zmq_command_sender.send_command(&hostname, agent_command).await?; } diff --git a/dashboard/src/ui/mod.rs b/dashboard/src/ui/mod.rs index 4938b6d..20c86a1 100644 --- a/dashboard/src/ui/mod.rs +++ b/dashboard/src/ui/mod.rs @@ -22,7 +22,8 @@ use widgets::{BackupWidget, ServicesWidget, SystemWidget, Widget}; #[derive(Debug, Clone)] pub enum UiCommand { ServiceRestart { hostname: String, service_name: String }, - ServiceStartStop { hostname: String, service_name: String }, // Toggle between start/stop + ServiceStart { hostname: String, service_name: String }, + ServiceStop { hostname: String, service_name: String }, SystemRebuild { hostname: String }, TriggerBackup { hostname: String }, } @@ -288,13 +289,21 @@ impl TuiApp { } } } - KeyCode::Char(' ') => { + KeyCode::Char('s') => { if self.focused_panel == PanelType::Services { - // Service start/stop toggle + // Service start command if let (Some(service_name), Some(hostname)) = (self.get_selected_service(), self.current_host.clone()) { - // For now, assume it's a start command - could be enhanced to check current state self.start_command(&hostname, CommandType::ServiceStart, service_name.clone()); - return Ok(Some(UiCommand::ServiceStartStop { hostname, service_name })); + return Ok(Some(UiCommand::ServiceStart { hostname, service_name })); + } + } + } + KeyCode::Char('S') => { + if self.focused_panel == PanelType::Services { + // Service stop command + if let (Some(service_name), Some(hostname)) = (self.get_selected_service(), self.current_host.clone()) { + self.start_command(&hostname, CommandType::ServiceStop, service_name.clone()); + return Ok(Some(UiCommand::ServiceStop { hostname, service_name })); } } } @@ -755,7 +764,8 @@ impl TuiApp { shortcuts.push("R: Rebuild".to_string()); } PanelType::Services => { - shortcuts.push("Space: Start/Stop".to_string()); + shortcuts.push("S: Start".to_string()); + shortcuts.push("Shift+S: Stop".to_string()); shortcuts.push("R: Restart".to_string()); } PanelType::Backup => {