From 342a3506272a85ae6914565f1c2b5ca69b7acc6d Mon Sep 17 00:00:00 2001 From: 1zuna Date: Fri, 22 Mar 2024 22:49:51 +0000 Subject: [PATCH] fix: start-up download_view --- src-tauri/src/app/webview.rs | 25 ++++++++++++++++++++----- src-tauri/tauri.conf.json | 4 ++-- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src-tauri/src/app/webview.rs b/src-tauri/src/app/webview.rs index a7e3e3e..0469372 100644 --- a/src-tauri/src/app/webview.rs +++ b/src-tauri/src/app/webview.rs @@ -59,10 +59,23 @@ pub async fn open_download_page(url: &str, on_progress: &impl ProgressReceiver, async fn show_webview(url: Url, window: &Arc>) -> Result { // 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")?; + let mut download_view = { + let window = window.lock() + .map_err(|_| anyhow!("Failed to lock window"))?; + + match window.get_webview_window("download_view") { + Some(window) => Ok(window), + None => { + // todo: do not hardcode index + let config = window.config().app.windows.get(1) + .context("Unable to find window config")?; + + WebviewWindowBuilder::from_config(window.app_handle(), config) + .map_err(|e| anyhow!("Failed to build window: {:?}", e))? + .build() + }, + } + }?; // Redirect the download view to the download page download_view.navigate(url); @@ -78,7 +91,8 @@ async fn show_webview(url: Url, window: &Arc>) -> Result>) -> Result