From ba18bddaa2d3b1d8b7e28ff3ba3328fe7677bd0a Mon Sep 17 00:00:00 2001 From: Brian Pearce Date: Wed, 18 Dec 2024 14:09:22 +0100 Subject: [PATCH] fix: retry window fetching (#1291) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Description --- Seeing errors in Sentry where the main window can't be fetched. Retry for a second before panic'ing. Motivation and Context --- A brief delay between window creation and closing may help alleviate the error. How Has This Been Tested? --- Error isn't present locally so 🤞🏻 --- src-tauri/src/commands.rs | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 941812334..3355b29f5 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -143,12 +143,28 @@ pub struct SignWsDataResponse { #[tauri::command] pub async fn close_splashscreen(app: tauri::AppHandle) { - let splashscreen_window = app - .get_webview_window("splashscreen") - .expect("no window labeled 'splashscreen' found"); - let main_window = app - .get_webview_window("main") - .expect("no window labeled 'main' found"); + let close_max_retries: u32 = 10; // Maximum number of retries + let retry_delay_ms: u64 = 100; // Delay between retries in milliseconds + + let mut retries = 0; + + let (splashscreen_window, main_window) = loop { + let splashscreen_window = app.get_webview_window("splashscreen"); + let main_window = app.get_webview_window("main"); + + if let (Some(splashscreen), Some(main)) = (splashscreen_window, main_window) { + break (splashscreen, main); + } + + retries += 1; + if retries >= close_max_retries { + error!(target: "LOG_TARGET", "Failed to fetch both 'splashscreen' and 'main' windows after {} retries", close_max_retries); + return; + } + + info!(target: "LOG_TARGET", "Failed to fetch both 'splashscreen' and 'main' windows. Retrying in {}ms", retry_delay_ms); + tokio::time::sleep(Duration::from_millis(retry_delay_ms)).await; + }; if let (Ok(window_position), Ok(window_size)) = ( splashscreen_window.outer_position(), @@ -170,6 +186,7 @@ pub async fn close_splashscreen(app: tauri::AppHandle) { main_window.show().expect("could not show"); } } + #[tauri::command] pub async fn download_and_start_installer( _missing_dependency: ExternalDependency,