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:
parent
07633e4e0e
commit
bf2f066029
@ -159,22 +159,29 @@ 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() {
|
||||
// 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;
|
||||
}
|
||||
|
||||
// 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() {
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Handle keyboard input
|
||||
pub fn handle_input(&mut self, event: Event) -> Result<()> {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user