diff --git a/Cargo.lock b/Cargo.lock index fa20603..7f935ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -270,7 +270,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" [[package]] name = "cm-dashboard" -version = "0.1.58" +version = "0.1.59" dependencies = [ "anyhow", "chrono", @@ -292,7 +292,7 @@ dependencies = [ [[package]] name = "cm-dashboard-agent" -version = "0.1.58" +version = "0.1.59" dependencies = [ "anyhow", "async-trait", @@ -315,7 +315,7 @@ dependencies = [ [[package]] name = "cm-dashboard-shared" -version = "0.1.58" +version = "0.1.59" dependencies = [ "chrono", "serde", diff --git a/agent/Cargo.toml b/agent/Cargo.toml index 936376d..36ac9e4 100644 --- a/agent/Cargo.toml +++ b/agent/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard-agent" -version = "0.1.59" +version = "0.1.60" edition = "2021" [dependencies] diff --git a/dashboard/Cargo.toml b/dashboard/Cargo.toml index 48daf2a..a6392d0 100644 --- a/dashboard/Cargo.toml +++ b/dashboard/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard" -version = "0.1.59" +version = "0.1.60" edition = "2021" [dependencies] diff --git a/dashboard/src/ui/mod.rs b/dashboard/src/ui/mod.rs index bd9b068..91f809f 100644 --- a/dashboard/src/ui/mod.rs +++ b/dashboard/src/ui/mod.rs @@ -90,10 +90,13 @@ pub struct TuiApp { user_navigated_away: bool, /// Dashboard configuration config: DashboardConfig, + /// Cached localhost hostname to avoid repeated system calls + localhost: String, } impl TuiApp { pub fn new(config: DashboardConfig) -> Self { + let localhost = gethostname::gethostname().to_string_lossy().to_string(); let mut app = Self { host_widgets: HashMap::new(), current_host: None, @@ -102,6 +105,7 @@ impl TuiApp { should_quit: false, user_navigated_away: false, config, + localhost, }; // Sort predefined hosts @@ -207,13 +211,12 @@ impl TuiApp { self.available_hosts = all_hosts; // Get the current hostname (localhost) for auto-selection - let localhost = gethostname::gethostname().to_string_lossy().to_string(); if !self.available_hosts.is_empty() { - if self.available_hosts.contains(&localhost) && !self.user_navigated_away { + if self.available_hosts.contains(&self.localhost) && !self.user_navigated_away { // Localhost is available and user hasn't navigated away - switch to it - self.current_host = Some(localhost.clone()); + self.current_host = Some(self.localhost.clone()); // Find the actual index of localhost in the sorted list - self.host_index = self.available_hosts.iter().position(|h| h == &localhost).unwrap_or(0); + self.host_index = self.available_hosts.iter().position(|h| h == &self.localhost).unwrap_or(0); } else if self.current_host.is_none() { // No current host - select first available (which is localhost if available) self.current_host = Some(self.available_hosts[0].clone()); @@ -410,9 +413,8 @@ impl TuiApp { self.current_host = Some(self.available_hosts[self.host_index].clone()); // Check if user navigated away from localhost - let localhost = gethostname::gethostname().to_string_lossy().to_string(); if let Some(ref current) = self.current_host { - if current != &localhost { + if current != &self.localhost { self.user_navigated_away = true; } else { self.user_navigated_away = false; // User navigated back to localhost diff --git a/shared/Cargo.toml b/shared/Cargo.toml index b73d657..cb95214 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard-shared" -version = "0.1.59" +version = "0.1.60" edition = "2021" [dependencies]