Skip to content

Commit

Permalink
fix: start-up download_view
Browse files Browse the repository at this point in the history
  • Loading branch information
1zun4 committed Mar 22, 2024
1 parent 824979b commit 342a350
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
25 changes: 20 additions & 5 deletions src-tauri/src/app/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,23 @@ 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> {
// 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);
Expand All @@ -78,7 +91,8 @@ async fn show_webview(url: Url, window: &Arc<Mutex<tauri::Window>>) -> Result<St
let cloned_cell = download_link_cell.clone();

download_view.on_window_event(move |event| {
if let tauri::WindowEvent::Destroyed = event {
if let tauri::WindowEvent::CloseRequested { api, .. } = event {
api.prevent_close();
close_request.store(true, Ordering::SeqCst);
}
});
Expand Down Expand Up @@ -110,6 +124,7 @@ async fn show_webview(url: Url, window: &Arc<Mutex<tauri::Window>>) -> Result<St
}

if cloned_close_request.load(Ordering::SeqCst) {
let _ = download_view.hide();
bail!("Download view was closed before the download link was received. \
Aborting download...");
}
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"windows": [
{
"title": "LiquidLauncher",
"label": "main",
"width": 1000,
"minWidth": 1000,
"height": 670,
Expand All @@ -34,11 +35,10 @@
"label": "download_view",
"url": "https://liquidbounce.net/",
"visible": false,
"resizable": true,
"maximized": true,
"alwaysOnTop": true,
"center": true,
"shadow": true
"parent": "main"
}
]
},
Expand Down

0 comments on commit 342a350

Please sign in to comment.