Files
cinny-mobile/src-tauri/src/lib.rs
Shenwei Wang 08fcd330e1 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>
2026-04-13 17:20:44 +10:00

50 lines
1.7 KiB
Rust

#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]
// mod menu;
use tauri::{webview::{NewWindowResponse, WebviewWindowBuilder}, WebviewUrl};
use tauri_plugin_opener::OpenerExt;
pub fn run() {
let port: u16 = 44548;
let context = tauri::generate_context!();
let builder = tauri::Builder::default();
// #[cfg(target_os = "macos")]
// {
// builder = builder.menu(menu::menu());
// }
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)]
let window_url = WebviewUrl::App(Default::default());
// Release: tauri-plugin-localhost serves bundled frontend assets on this port
#[cfg(not(debug_assertions))]
let window_url = {
let url = format!("http://localhost:{}", port).parse().unwrap();
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(())
})
.run(context)
.expect("error while building tauri application");
}