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.
This commit is contained in:
parent
9df6106bf5
commit
ab28382d58
@ -279,23 +279,19 @@ impl Dashboard {
|
|||||||
};
|
};
|
||||||
self.zmq_command_sender.send_command(&hostname, agent_command).await?;
|
self.zmq_command_sender.send_command(&hostname, agent_command).await?;
|
||||||
}
|
}
|
||||||
UiCommand::ServiceStartStop { hostname, service_name } => {
|
UiCommand::ServiceStart { hostname, service_name } => {
|
||||||
// Check current service status and toggle appropriately
|
info!("Sending start command for service {} on {}", service_name, hostname);
|
||||||
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
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let agent_command = AgentCommand::ServiceControl {
|
let agent_command = AgentCommand::ServiceControl {
|
||||||
service_name,
|
service_name: service_name.clone(),
|
||||||
action,
|
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?;
|
self.zmq_command_sender.send_command(&hostname, agent_command).await?;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,7 +22,8 @@ use widgets::{BackupWidget, ServicesWidget, SystemWidget, Widget};
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum UiCommand {
|
pub enum UiCommand {
|
||||||
ServiceRestart { hostname: String, service_name: String },
|
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 },
|
SystemRebuild { hostname: String },
|
||||||
TriggerBackup { hostname: String },
|
TriggerBackup { hostname: String },
|
||||||
}
|
}
|
||||||
@ -288,13 +289,21 @@ impl TuiApp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
KeyCode::Char(' ') => {
|
KeyCode::Char('s') => {
|
||||||
if self.focused_panel == PanelType::Services {
|
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()) {
|
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());
|
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());
|
shortcuts.push("R: Rebuild".to_string());
|
||||||
}
|
}
|
||||||
PanelType::Services => {
|
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());
|
shortcuts.push("R: Restart".to_string());
|
||||||
}
|
}
|
||||||
PanelType::Backup => {
|
PanelType::Backup => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user