rename
This commit is contained in:
33
apps/desktop/src-tauri/src/lib.rs
Normal file
33
apps/desktop/src-tauri/src/lib.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use tauri::Manager;
|
||||
|
||||
// 模块声明
|
||||
mod commands;
|
||||
mod sidecar;
|
||||
|
||||
use sidecar::SidecarProcess;
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_shell::init())
|
||||
.setup(|app| {
|
||||
// 注册全局状态
|
||||
app.manage(SidecarProcess(std::sync::Mutex::new(None)));
|
||||
|
||||
// 启动 Sidecar 进程
|
||||
let app_handle = app.handle().clone();
|
||||
sidecar::spawn_sidecar(app_handle);
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.invoke_handler(tauri::generate_handler![commands::greet])
|
||||
.build(tauri::generate_context!())
|
||||
.expect("error while building tauri application")
|
||||
.run(|app_handle, event| {
|
||||
// 监听应用退出事件,清理 Sidecar 进程
|
||||
if let tauri::RunEvent::Exit = event {
|
||||
// 只在 Exit 事件时清理,避免重复执行
|
||||
sidecar::cleanup_sidecar_process(app_handle);
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user