From 1d24fcb2d0c842c125c0bae50bdf7bf3221c301f Mon Sep 17 00:00:00 2001 From: GlassOnTin Date: Thu, 29 May 2025 15:04:15 +0100 Subject: [PATCH] Fix GUI closing immediately when enabling service - Add retry logic with up to 10 attempts for IPC connection - Detect service installation/startup state to prevent premature closure - Implement exponential backoff for connection retries - Check installing_service() flag for accurate service state detection This fixes the issue where the GUI would close within ~500ms when enabling the service due to 'Access is denied' IPC errors. Fixes #7010 --- src/ui_interface.rs | 65 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 3 deletions(-) diff --git a/src/ui_interface.rs b/src/ui_interface.rs index b1ce62643..1ff1df293 100644 --- a/src/ui_interface.rs +++ b/src/ui_interface.rs @@ -1157,9 +1157,14 @@ async fn check_connect_status_(reconnect: bool, rx: mpsc::UnboundedReceiver { log::error!("ipc connection closed: {}", err); + // Don't quit immediately if we're starting the service + // Give the service time to start and allow retries if is_cm { - crate::ui_cm_interface::quit_cm(); + // Check if service is starting up + let mut service_starting = false; + + #[cfg(windows)] + { + // On Windows, check if we're in elevated mode or if service is being installed + let is_elevated = crate::platform::is_elevated(None).unwrap_or(false); + service_starting = !is_elevated && (crate::platform::installing_service() || + (crate::platform::is_installed() && !crate::platform::is_root())); + } + + #[cfg(not(windows))] + { + // On other platforms, check if service is installed but not running as root + service_starting = crate::platform::is_installed() && + !crate::platform::is_root(); + } + + if !service_starting { + crate::ui_cm_interface::quit_cm(); + } } break; } @@ -1247,6 +1274,36 @@ async fn check_connect_status_(reconnect: bool, rx: mpsc::UnboundedReceiver= max_attempts { + let mut service_starting = false; + + #[cfg(windows)] + { + // On Windows, check if service is being installed/started + let is_elevated = crate::platform::is_elevated(None).unwrap_or(false); + service_starting = !is_elevated && (crate::platform::installing_service() || + (crate::platform::is_installed() && !crate::platform::is_root())); + } + + #[cfg(not(windows))] + { + // On other platforms + service_starting = crate::platform::is_installed() && + !crate::platform::is_root(); + } + + if !service_starting { + log::error!("Failed to connect after {} attempts, quitting", max_attempts); + crate::ui_cm_interface::quit_cm(); + break; + } + } } *UI_STATUS.lock().unwrap() = UiStatus { status_num: -1, @@ -1259,7 +1316,9 @@ async fn check_connect_status_(reconnect: bool, rx: mpsc::UnboundedReceiver