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,