From 824979b3b6077e5927c54c6ca7d17a217bfc87b8 Mon Sep 17 00:00:00 2001 From: 1zuna Date: Fri, 22 Mar 2024 22:52:15 +0100 Subject: [PATCH] fix: hold download_view until it is needed --- src-tauri/src/app/webview.rs | 27 ++++++++++----------------- src-tauri/tauri.conf.json | 11 +++++++++++ 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src-tauri/src/app/webview.rs b/src-tauri/src/app/webview.rs index 7f2325e..a7e3e3e 100644 --- a/src-tauri/src/app/webview.rs +++ b/src-tauri/src/app/webview.rs @@ -48,7 +48,7 @@ pub async fn open_download_page(url: &str, on_progress: &impl ProgressReceiver, match show_webview(download_page.clone(), window).await { Ok(url) => break url, Err(e) => { - log(&window, &format!("Failed to open download page: {}", e)); + log(&window, &format!("Failed to open download page: {:?}", e)); sleep(Duration::from_millis(500)).await; } } @@ -58,25 +58,18 @@ pub async fn open_download_page(url: &str, on_progress: &impl ProgressReceiver, } async fn show_webview(url: Url, window: &Arc>) -> Result { - let download_view = WebviewWindowBuilder::new( - window.lock() - .map_err(|_| anyhow!("Unable to lock window due to poisoned mutex"))? - .app_handle(), - "download_view", - WebviewUrl::External(url) - ).title("Download of LiquidBounce") - .center() - .focused(true) - .maximized(true) - .always_on_top(true) - .build() - .context("Failed to create download view")?; + // Find download_view window from the window manager + let mut download_view = window.lock() + .map_err(|_| anyhow!("Failed to lock window"))? + .get_webview_window("download_view") + .context("Failed to get download view window")?; + + // Redirect the download view to the download page + download_view.navigate(url); // Show and maximize the download view download_view.show() .context("Failed to show the download view")?; - download_view.maximize() - .context("Failed to maximize the download view")?; // Wait for the download to finish let download_link_cell = Arc::new(Mutex::new(None)); @@ -125,7 +118,7 @@ async fn show_webview(url: Url, window: &Arc>) -> Result