Skip to content

Commit

Permalink
fix: retry window fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
brianp committed Dec 18, 2024
1 parent 57a3086 commit 7f2a381
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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,
Expand Down

0 comments on commit 7f2a381

Please sign in to comment.