78 lines
2.9 KiB
Rust
78 lines
2.9 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;
|
|
use tauri_plugin_updater::UpdaterExt;
|
|
use tauri_plugin_dialog::{DialogExt, MessageDialogButtons, MessageDialogKind};
|
|
|
|
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_updater::Builder::new().build())
|
|
.plugin(tauri_plugin_dialog::init())
|
|
.plugin(tauri_plugin_localhost::Builder::new(port).build())
|
|
.plugin(tauri_plugin_window_state::Builder::default().build())
|
|
.plugin(tauri_plugin_opener::init())
|
|
.setup(move |app| {
|
|
let handle = app.handle().clone();
|
|
tauri::async_runtime::spawn(async move {
|
|
if let Ok(Some(update)) = handle.updater().unwrap().check().await {
|
|
let version = update.version.clone();
|
|
|
|
let should_update = handle
|
|
.dialog()
|
|
.message(format!(
|
|
"Version {} is available.\n\nWould you like to update now?",
|
|
version
|
|
))
|
|
.title("Update Available")
|
|
.kind(MessageDialogKind::Info)
|
|
.buttons(MessageDialogButtons::YesNo)
|
|
.blocking_show();
|
|
|
|
if should_update {
|
|
if update.download_and_install(|_, _| {}, || {}).await.is_ok() {
|
|
handle.restart();
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
// 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");
|
|
}
|