Skip to content

Commit 595eb0f

Browse files
committed
fix(download/webview): creation on use instead of on load
Creates a new webview window with a new index on each use. This will solve issues regarding redirection.
1 parent a306095 commit 595eb0f

File tree

4 files changed

+25
-65
lines changed

4 files changed

+25
-65
lines changed

src-tauri/capabilities/download_view.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"remote": {
55
"urls": ["https://dl.liquidbounce.net", "https://dl.ccbluex.net"]
66
},
7-
"windows": ["download_view"],
7+
"windows": ["download_view-*"],
88
"local": false,
99
"permissions": [
1010
"core:event:default"

src-tauri/src/app/webview.rs

Lines changed: 22 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ use std::{
3030
},
3131
time::Duration,
3232
};
33-
use tauri::{Listener, Manager, Url, WebviewWindowBuilder};
33+
use tauri::{Listener, Manager, Url, WebviewUrl, WebviewWindowBuilder, WindowEvent};
3434
use tokio::time::sleep;
35-
use tracing::{debug, error, info};
35+
use tracing::{debug, info};
3636

3737
use super::gui::ShareableWindow;
3838

@@ -42,8 +42,7 @@ pub async fn open_download_page(
4242
url: &str,
4343
launcher_data: &LauncherData<ShareableWindow>,
4444
) -> Result<String> {
45-
let download_page: Url = format!("{}&liquidlauncher=1", url)
46-
.parse()
45+
let download_page: Url = url.parse()
4746
.context("Failed to parse download page URL")?;
4847

4948
let mut count = 0;
@@ -77,47 +76,23 @@ pub async fn open_download_page(
7776
}
7877

7978
async fn show_webview(url: Url, window: &Arc<Mutex<tauri::Window>>) -> Result<String> {
80-
// Find download_view window from the window manager
81-
let download_view = {
82-
let window = window
83-
.lock()
84-
.map_err(|_| anyhow!("Failed to lock window"))?;
85-
86-
match window.get_webview_window("download_view") {
87-
Some(window) => Ok(window),
88-
None => {
89-
// todo: do not hardcode index
90-
let config = window
91-
.config()
92-
.app
93-
.windows
94-
.get(1)
95-
.context("Unable to find window config")?;
96-
97-
WebviewWindowBuilder::from_config(window.app_handle(), config)
98-
.map_err(|e| anyhow!("Failed to build window: {:?}", e))?
99-
.build()
100-
}
101-
}
102-
}?;
103-
104-
// Redirect the download view to the download page
105-
if let Err(e) = download_view.navigate(url.clone()) {
106-
error!("Failed to navigate to download page: {:?}", e);
107-
}
108-
109-
// We do this in case the navigation fails, e.g., on macOS
110-
if let Err(e) = download_view.eval(&format!("window.location.href = '{}'", url)) {
111-
error!("Failed to navigate to download page using JS: {:?}", e);
112-
}
113-
114-
// Show and maximize the download view
115-
download_view
116-
.show()
117-
.context("Failed to show the download view")?;
118-
download_view
119-
.maximize()
120-
.context("Failed to maximize the download view")?;
79+
let window = window
80+
.lock()
81+
.map_err(|_| anyhow!("Failed to lock window"))?;
82+
let app = window.app_handle();
83+
let main_window = window.get_webview_window("main")
84+
.ok_or_else(|| anyhow!("Failed to get window"))?;
85+
let len = app.webview_windows().len();
86+
87+
let download_view = WebviewWindowBuilder::new(app, format!("download_view-{}", len), WebviewUrl::External(url))
88+
.title("Download of LiquidBounce JAR")
89+
.visible(true)
90+
.always_on_top(true)
91+
.maximized(true)
92+
.center()
93+
.parent(&main_window)?
94+
.build()?;
95+
drop(window);
12196

12297
// Wait for the download to finish
12398
let pid_cell = Arc::new(Mutex::new(None));
@@ -126,7 +101,7 @@ async fn show_webview(url: Url, window: &Arc<Mutex<tauri::Window>>) -> Result<St
126101
let cloned_cell = pid_cell.clone();
127102

128103
download_view.on_window_event(move |event| {
129-
if let tauri::WindowEvent::CloseRequested { api, .. } = event {
104+
if let WindowEvent::CloseRequested { api, .. } = event {
130105
api.prevent_close();
131106
close_request.store(true, Ordering::SeqCst);
132107
}
@@ -171,7 +146,7 @@ async fn show_webview(url: Url, window: &Arc<Mutex<tauri::Window>>) -> Result<St
171146
.context("Download view was closed unexpected")?;
172147
};
173148

174-
let _ = download_view.hide();
149+
let _ = download_view.destroy();
175150

176151
Ok(pid)
177152
}

src-tauri/tauri.conf.json

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,6 @@
2929
]
3030
},
3131
"shadow": true
32-
},
33-
{
34-
"title": "LiquidBounce Download",
35-
"label": "download_view",
36-
"url": "https://liquidbounce.net/download",
37-
"visible": false,
38-
"maximized": true,
39-
"alwaysOnTop": true,
40-
"center": true,
41-
"parent": "main"
4232
}
4333
]
4434
},

yarn.lock

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,9 @@
328328
"@tauri-apps/cli-win32-ia32-msvc" "2.3.1"
329329
"@tauri-apps/cli-win32-x64-msvc" "2.3.1"
330330

331-
"@tauri-apps/plugin-clipboard-manager@^2.2.2":
331+
"@tauri-apps/plugin-clipboard-manager@^2":
332332
version "2.2.2"
333-
resolved "https://registry.npmjs.org/@tauri-apps/plugin-clipboard-manager/-/plugin-clipboard-manager-2.2.2.tgz"
333+
resolved "https://registry.yarnpkg.com/@tauri-apps/plugin-clipboard-manager/-/plugin-clipboard-manager-2.2.2.tgz#19559f2b80dd6c692b4e7b884515b5b693ca9791"
334334
integrity sha512-bZvDLMqfcNmsw7Ag8I49jlaCjdpDvvlJHnpp6P+Gg/3xtpSERdwlDxm7cKGbs2mj46dsw4AuG3RoAgcpwgioUA==
335335
dependencies:
336336
"@tauri-apps/api" "^2.0.0"
@@ -471,11 +471,6 @@ is-reference@^3.0.0, is-reference@^3.0.1:
471471
dependencies:
472472
"@types/estree" "*"
473473

474-
jwt-decode@^4.0.0:
475-
version "4.0.0"
476-
resolved "https://registry.npmjs.org/jwt-decode/-/jwt-decode-4.0.0.tgz"
477-
integrity sha512-+KJGIyHgkGuIq3IEBNftfhW/LfWhXUIY6OmyVWjliu5KH1y0fw7VQ8YndE2O4qZdMSd9SqbnC8GOcZEy0Om7sA==
478-
479474
kleur@^4.1.5:
480475
version "4.1.5"
481476
resolved "https://registry.npmjs.org/kleur/-/kleur-4.1.5.tgz"

0 commit comments

Comments
 (0)