From d83afe2f847b33141dfdfdc372df6be42807a2f6 Mon Sep 17 00:00:00 2001 From: Reactor Scram Date: Tue, 16 Jan 2024 16:14:03 -0600 Subject: [PATCH] fix(windows): when the token expires, change the GUI to signed-out state (#3142) Fixes #3128 Will mark ready for review in an hour or two when it replicates on my dev laptop --- .../src-tauri/src/client/gui.rs | 40 ++++++++++++------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/rust/windows-client/src-tauri/src/client/gui.rs b/rust/windows-client/src-tauri/src/client/gui.rs index fbefb3f19..176a03382 100644 --- a/rust/windows-client/src-tauri/src/client/gui.rs +++ b/rust/windows-client/src-tauri/src/client/gui.rs @@ -227,6 +227,7 @@ fn handle_system_tray_event(app: &tauri::AppHandle, event: TrayMenuEvent) -> Res pub(crate) enum ControllerRequest { CopyResource(String), Disconnected, + DisconnectedTokenExpired, ExportLogs { path: PathBuf, stem: PathBuf }, GetAdvancedSettings(oneshot::Sender), SchemeRequest(url::Url), @@ -261,7 +262,12 @@ impl connlib_client_shared::Callbacks for CallbackHandler { error: Option<&connlib_client_shared::Error>, ) -> Result<(), Self::Error> { tracing::debug!("on_disconnect {error:?}"); - self.ctlr_tx.try_send(ControllerRequest::Disconnected)?; + self.ctlr_tx.try_send(match error { + Some(connlib_client_shared::Error::TokenExpired) => { + ControllerRequest::DisconnectedTokenExpired + } + _ => ControllerRequest::Disconnected, + })?; Ok(()) } @@ -485,9 +491,26 @@ async fn run_controller( controller.tunnel_ready = false; if let Some(mut session) = controller.session.take() { tracing::debug!("disconnecting connlib"); + // This is probably redundant since connlib shuts itself down if it's disconnected. session.connlib.disconnect(None); } - }, + controller.refresh_system_tray_menu()?; + } + Req::DisconnectedTokenExpired | Req::SignOut => { + tracing::debug!("Token expired or user signed out"); + controller.auth.sign_out()?; + controller.tunnel_ready = false; + if let Some(mut session) = controller.session.take() { + tracing::debug!("disconnecting connlib"); + // This is redundant if the token is expired, in that case + // connlib already disconnected itself. + session.connlib.disconnect(None); + } + else { + tracing::error!("tried to sign out but there's no session"); + } + controller.refresh_system_tray_menu()?; + } Req::ExportLogs{path, stem} => logging::export_logs_to(path, stem).await?, Req::GetAdvancedSettings(tx) => { tx.send(controller.advanced_settings.clone()).ok(); @@ -506,18 +529,6 @@ async fn run_controller( )?; } } - Req::SignOut => { - controller.auth.sign_out()?; - controller.tunnel_ready = false; - if let Some(mut session) = controller.session.take() { - tracing::debug!("disconnecting connlib"); - session.connlib.disconnect(None); - } - else { - tracing::error!("tried to sign out but there's no session"); - } - controller.refresh_system_tray_menu()?; - } Req::StartStopLogCounting(enable) => { if enable { if controller.log_counting_task.is_none() { @@ -533,6 +544,7 @@ async fn run_controller( } Req::TunnelReady => { controller.tunnel_ready = true; + controller.refresh_system_tray_menu()?; // May say "Windows Powershell" in dev mode // See https://github.com/tauri-apps/tauri/issues/3700