Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: retry window fetching #1291

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading