diff --git a/rust/gui-client/src-tauri/src/client.rs b/rust/gui-client/src-tauri/src/client.rs index 76fd1aa18..ac1dac2d0 100644 --- a/rust/gui-client/src-tauri/src/client.rs +++ b/rust/gui-client/src-tauri/src/client.rs @@ -16,6 +16,7 @@ mod network_changes; mod resolvers; mod settings; mod updates; +mod uptime; #[cfg(target_os = "windows")] mod wintun_install; diff --git a/rust/gui-client/src-tauri/src/client/gui.rs b/rust/gui-client/src-tauri/src/client/gui.rs index d2759198a..2c7cc7702 100644 --- a/rust/gui-client/src-tauri/src/client/gui.rs +++ b/rust/gui-client/src-tauri/src/client/gui.rs @@ -503,6 +503,7 @@ struct Controller { /// Tells us when to wake up and look for a new resource list. Tokio docs say that memory reads and writes are synchronized when notifying, so we don't need an extra mutex on the resources. notify_controller: Arc, tunnel_ready: bool, + uptime: client::uptime::Tracker, } /// Everything related to a signed-in user session @@ -634,7 +635,18 @@ impl Controller { self.sign_out()?; } } - Req::SystemTrayMenu(TrayMenuEvent::ShowWindow(window)) => self.show_window(window)?, + Req::SystemTrayMenu(TrayMenuEvent::ShowWindow(window)) => { + self.show_window(window)?; + // When the About or Settings windows are hidden / shown, log the + // run ID and uptime. This makes it easy to check client stability on + // dev or test systems without parsing the whole log file. + let uptime_info = self.uptime.info(); + tracing::debug!( + uptime_s = uptime_info.uptime.as_secs(), + run_id = uptime_info.run_id.to_string(), + "Uptime info" + ); + } Req::SystemTrayMenu(TrayMenuEvent::Resource { id }) => self .copy_resource(&id) .context("Couldn't copy resource to clipboard")?, @@ -784,6 +796,7 @@ async fn run_controller( logging_handles, notify_controller, tunnel_ready: false, + uptime: Default::default(), }; if let Some(token) = controller diff --git a/rust/gui-client/src-tauri/src/client/uptime.rs b/rust/gui-client/src-tauri/src/client/uptime.rs new file mode 100644 index 000000000..088de8bf9 --- /dev/null +++ b/rust/gui-client/src-tauri/src/client/uptime.rs @@ -0,0 +1,31 @@ +use std::time::Duration; +use tokio::time::Instant; +use uuid::Uuid; + +pub struct Tracker { + run_id: Uuid, + start_time: Instant, +} + +pub struct Info { + pub run_id: Uuid, + pub uptime: Duration, +} + +impl Default for Tracker { + fn default() -> Self { + Self { + start_time: Instant::now(), + run_id: Uuid::new_v4(), + } + } +} + +impl Tracker { + pub fn info(&self) -> Info { + Info { + run_id: self.run_id, + uptime: Instant::now() - self.start_time, + } + } +}