54 lines
1.5 KiB
Rust
54 lines
1.5 KiB
Rust
#![cfg_attr(
|
|
all(not(debug_assertions), target_os = "windows"),
|
|
windows_subsystem = "windows"
|
|
)]
|
|
|
|
use tauri::{
|
|
webview::{NewWindowResponse, WebviewWindowBuilder},
|
|
WebviewUrl,
|
|
};
|
|
use tauri_plugin_opener::OpenerExt;
|
|
|
|
const LOCALHOST_PORT: u16 = 44_548;
|
|
|
|
fn main_window_url() -> WebviewUrl {
|
|
#[cfg(debug_assertions)]
|
|
{
|
|
WebviewUrl::default()
|
|
}
|
|
|
|
#[cfg(not(debug_assertions))]
|
|
{
|
|
let url = format!("http://localhost:{LOCALHOST_PORT}")
|
|
.parse()
|
|
.expect("failed to parse localhost app URL");
|
|
WebviewUrl::External(url)
|
|
}
|
|
}
|
|
|
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
|
pub fn run() {
|
|
tauri::Builder::default()
|
|
.plugin(tauri_plugin_localhost::Builder::new(LOCALHOST_PORT).build())
|
|
.plugin(tauri_plugin_notification::init())
|
|
.plugin(tauri_plugin_opener::init())
|
|
.setup(|app| {
|
|
let app_handle = app.handle().clone();
|
|
let builder = WebviewWindowBuilder::new(app, "main", main_window_url());
|
|
|
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
|
let builder = builder.title("Cinny");
|
|
|
|
builder
|
|
.on_new_window(move |url, _features| {
|
|
let _ = app_handle.opener().open_url(url.as_str(), None::<&str>);
|
|
NewWindowResponse::Deny
|
|
})
|
|
.build()?;
|
|
|
|
Ok(())
|
|
})
|
|
.run(tauri::generate_context!())
|
|
.expect("error while building tauri application");
|
|
}
|