diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 1b0e6c4..b539dfc 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -237,7 +237,22 @@ async fn update_tray_menu( #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { - let builder = tauri::Builder::default() + let mut builder = tauri::Builder::default(); + + #[cfg(any(target_os = "macos", target_os = "windows", target_os = "linux"))] + { + builder = builder.plugin(tauri_plugin_single_instance::init( + |app, _args, _cwd| { + if let Some(window) = app.get_webview_window("main") { + let _ = window.unminimize(); + let _ = window.show(); + let _ = window.set_focus(); + } + }, + )); + } + + let builder = builder // 拦截窗口关闭:仅隐藏窗口,保持进程与托盘常驻 .on_window_event(|window, event| match event { tauri::WindowEvent::CloseRequested { api, .. } => {