fix: enable tauri plugin opener (#559)

* fix: enable tauri plugin opener

* fix: add remote urls to make build work on Windows

* fix: update Cargo.lock

We need tauri v2.8.0 since which supports `WebviewBuilder::on_new_window`

* fix: handle `window.open()` using `WebviewBuilder::on_new_window`

---------

Co-authored-by: Krishan <33421343+kfiven@users.noreply.github.com>
This commit is contained in:
Shenwei Wang
2026-04-13 15:20:44 +08:00
committed by GitHub
parent 0a5f14508c
commit 08fcd330e1
8 changed files with 9588 additions and 2041 deletions

View File

@@ -5,7 +5,8 @@
// mod menu;
use tauri::{webview::WebviewWindowBuilder, WebviewUrl};
use tauri::{webview::{NewWindowResponse, WebviewWindowBuilder}, WebviewUrl};
use tauri_plugin_opener::OpenerExt;
pub fn run() {
let port: u16 = 44548;
@@ -20,6 +21,7 @@ pub fn run() {
builder
.plugin(tauri_plugin_localhost::Builder::new(port).build())
.plugin(tauri_plugin_window_state::Builder::default().build())
.plugin(tauri_plugin_opener::init())
.setup(move |app| {
// Dev: use devUrl from tauri.conf.json (http://localhost:8080) to support HMR
#[cfg(debug_assertions)]
@@ -32,8 +34,13 @@ pub fn run() {
WebviewUrl::External(url)
};
let app_handle = app.handle().clone();
WebviewWindowBuilder::new(app, "main".to_string(), window_url)
.title("Cinny")
.on_new_window(move |url, _features| {
let _ = app_handle.opener().open_url(url.as_str(), None::<&str>);
NewWindowResponse::Deny
})
.build()?;
Ok(())
})