From bf2f066029969eca45a00ab827f8d46bbaed7e92 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Sun, 19 Oct 2025 11:12:05 +0200 Subject: [PATCH] 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 --- dashboard/src/ui/mod.rs | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/dashboard/src/ui/mod.rs b/dashboard/src/ui/mod.rs index 308107f..880bc8c 100644 --- a/dashboard/src/ui/mod.rs +++ b/dashboard/src/ui/mod.rs @@ -159,19 +159,26 @@ impl TuiApp { self.available_hosts = sorted_hosts; - // Always select localhost first if available, otherwise use first available host - if self.current_host.is_none() && !self.available_hosts.is_empty() { - self.current_host = Some(self.available_hosts[0].clone()); - self.host_index = 0; - } - - // If current host is not in the new list, reset to first available - if let Some(ref current) = self.current_host { - if !self.available_hosts.contains(current) && !self.available_hosts.is_empty() { + // Always prioritize localhost if it becomes available, even if another host is selected + 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.host_index = 0; - } else if let Some(index) = self.available_hosts.iter().position(|h| h == current) { - self.host_index = index; + } else if let Some(ref current) = self.current_host { + if !self.available_hosts.contains(current) { + // Current host disconnected - select first available + self.current_host = Some(self.available_hosts[0].clone()); + self.host_index = 0; + } else if let Some(index) = self.available_hosts.iter().position(|h| h == current) { + // Update index for current host + self.host_index = index; + } } } }