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,19 +159,26 @@ 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();
self.current_host = Some(self.available_hosts[0].clone()); if !self.available_hosts.is_empty() {
self.host_index = 0; if self.available_hosts.contains(&localhost) {
} // Localhost is available - always switch to it
self.current_host = Some(localhost);
// If current host is not in the new list, reset to first available self.host_index = 0; // localhost is always first in sorted_hosts
if let Some(ref current) = self.current_host { } else if self.current_host.is_none() {
if !self.available_hosts.contains(current) && !self.available_hosts.is_empty() { // 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(index) = self.available_hosts.iter().position(|h| h == current) { } else if let Some(ref current) = self.current_host {
self.host_index = index; 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;
}
} }
} }
} }