diff --git a/cc-haha/desktop/src-tauri/src/lib.rs b/cc-haha/desktop/src-tauri/src/lib.rs index 926cd06..f8b83d8 100644 --- a/cc-haha/desktop/src-tauri/src/lib.rs +++ b/cc-haha/desktop/src-tauri/src/lib.rs @@ -1083,17 +1083,19 @@ pub fn run() { .expect("error while building tauri application"); app.run(|app_handle, event| match event { - // Close (×) on the main window now means "really quit" rather than - // "minimize to tray". Mark the app as quitting so any cleanup paths - // that check is_quitting do the right thing; the tray icon stays - // available for users who explicitly choose 「显示 Heicode」/「退出 Heicode」 - // from the tray menu. RunEvent::WindowEvent { label, - event: WindowEvent::CloseRequested { .. }, + event: WindowEvent::CloseRequested { api, .. }, .. } if label == MAIN_WINDOW_LABEL => { - mark_app_quitting(app_handle); + if should_hide_to_tray(app_handle, &label) { + api.prevent_close(); + if let Some(window) = app_handle.get_webview_window(MAIN_WINDOW_LABEL) { + let _ = window.hide(); + } + } else { + mark_app_quitting(app_handle); + } } #[cfg(target_os = "macos")] RunEvent::Reopen {