Fix localhost prioritization to always switch when localhost connects

- Dashboard now switches to localhost even if another host is already selected
- Ensures localhost is always preferred regardless of connection order
- Resolves issue where srv01 connecting first would prevent localhost selection
This commit is contained in:
Christoffer Martinsson 2025-10-19 11:12:05 +02:00
parent 07633e4e0e
commit bf2f066029

View File

@ -159,22 +159,29 @@ impl TuiApp {
self.available_hosts = sorted_hosts; self.available_hosts = sorted_hosts;
// Always select localhost first if available, otherwise use first available host // Always prioritize localhost if it becomes available, even if another host is selected
if self.current_host.is_none() && !self.available_hosts.is_empty() { let localhost = gethostname::gethostname().to_string_lossy().to_string();
if !self.available_hosts.is_empty() {
if self.available_hosts.contains(&localhost) {
// Localhost is available - always switch to it
self.current_host = Some(localhost);
self.host_index = 0; // localhost is always first in sorted_hosts
} else if self.current_host.is_none() {
// No localhost, no current host - select first available
self.current_host = Some(self.available_hosts[0].clone()); self.current_host = Some(self.available_hosts[0].clone());
self.host_index = 0; self.host_index = 0;
} } else if let Some(ref current) = self.current_host {
if !self.available_hosts.contains(current) {
// If current host is not in the new list, reset to first available // Current host disconnected - select first available
if let Some(ref current) = self.current_host {
if !self.available_hosts.contains(current) && !self.available_hosts.is_empty() {
self.current_host = Some(self.available_hosts[0].clone()); self.current_host = Some(self.available_hosts[0].clone());
self.host_index = 0; self.host_index = 0;
} else if let Some(index) = self.available_hosts.iter().position(|h| h == current) { } else if let Some(index) = self.available_hosts.iter().position(|h| h == current) {
// Update index for current host
self.host_index = index; self.host_index = index;
} }
} }
} }
}
/// Handle keyboard input /// Handle keyboard input
pub fn handle_input(&mut self, event: Event) -> Result<()> { pub fn handle_input(&mut self, event: Event) -> Result<()> {