mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-03-23 05:09:45 +08:00
68 lines
2.0 KiB
Rust
68 lines
2.0 KiB
Rust
//! @file src/main.rs
|
|
//! @desc 主模块,用于启动应用
|
|
//! @since Beta v0.5.2
|
|
|
|
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
|
|
|
use tauri::{Emitter, Manager};
|
|
mod client;
|
|
mod commands;
|
|
mod plugins;
|
|
mod utils;
|
|
|
|
// 窗口事件处理
|
|
fn window_event_handler(app: &tauri::Window, event: &tauri::WindowEvent) {
|
|
match event {
|
|
tauri::WindowEvent::CloseRequested { api, .. } => {
|
|
api.prevent_close();
|
|
if app.label() == "TeyvatGuide" {
|
|
// 子窗口 label 的数组
|
|
const SUB_WINDOW_LABELS: [&str; 3] = ["Sub_window", "Dev_JSON", "mhy_client"];
|
|
for label in SUB_WINDOW_LABELS.iter() {
|
|
let sub = app.get_webview_window(label);
|
|
if sub.is_some() {
|
|
sub.unwrap().destroy().unwrap();
|
|
}
|
|
}
|
|
}
|
|
app.destroy().unwrap();
|
|
}
|
|
_ => {}
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
tauri::Builder::default()
|
|
.on_window_event(move |app, event| window_event_handler(app, event))
|
|
.plugin(tauri_plugin_single_instance::init(|app, argv, _cwd| {
|
|
app.emit("active_deep_link", argv).unwrap();
|
|
}))
|
|
.plugin(tauri_plugin_deep_link::init())
|
|
.plugin(tauri_plugin_dialog::init())
|
|
.plugin(tauri_plugin_fs::init())
|
|
.plugin(tauri_plugin_http::init())
|
|
.plugin(tauri_plugin_os::init())
|
|
.plugin(tauri_plugin_process::init())
|
|
.plugin(tauri_plugin_shell::init())
|
|
.plugin(tauri_plugin_sql::Builder::default().build())
|
|
.plugin(plugins::build_log_plugin())
|
|
.setup(|_app| {
|
|
let _window = _app.get_webview_window("TeyvatGuide");
|
|
#[cfg(debug_assertions)]
|
|
if _window.is_some() {
|
|
_window.unwrap().open_devtools();
|
|
}
|
|
Ok(())
|
|
})
|
|
.invoke_handler(tauri::generate_handler![
|
|
commands::init_app,
|
|
commands::create_window,
|
|
commands::execute_js,
|
|
commands::get_dir_size,
|
|
client::create_mhy_client,
|
|
])
|
|
.run(tauri::generate_context!())
|
|
.expect("error while running tauri application");
|
|
}
|