Skip to content

Commit

Permalink
fix: hold download_view until it is needed
Browse files Browse the repository at this point in the history
  • Loading branch information
1zun4 committed Mar 22, 2024
1 parent 5b309ea commit 824979b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
27 changes: 10 additions & 17 deletions src-tauri/src/app/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -58,25 +58,18 @@ pub async fn open_download_page(url: &str, on_progress: &impl ProgressReceiver,
}

async fn show_webview(url: Url, window: &Arc<Mutex<tauri::Window>>) -> Result<String> {
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));
Expand Down Expand Up @@ -125,7 +118,7 @@ async fn show_webview(url: Url, window: &Arc<Mutex<tauri::Window>>) -> Result<St
.context("Download view was closed unexpected")?;
};

let _ = download_view.destroy();
let _ = download_view.hide();

Ok(url)
}
11 changes: 11 additions & 0 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@
]
},
"shadow": true
},
{
"title": "LiquidBounce Download",
"label": "download_view",
"url": "https://liquidbounce.net/",
"visible": false,
"resizable": true,
"maximized": true,
"alwaysOnTop": true,
"center": true,
"shadow": true
}
]
},
Expand Down

0 comments on commit 824979b

Please sign in to comment.