From 853e3b4ca9c2a02315277b59eddd7d45b4f8c4fd Mon Sep 17 00:00:00 2001 From: chenchen Date: Mon, 18 May 2026 16:35:34 +0800 Subject: [PATCH] feat: minimize to system tray on window close instead of quitting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When user clicks the X button, the app now hides to the system tray instead of exiting. Users can restore the window by clicking the tray icon or selecting "显示 Heicode" from the tray menu. To fully quit, use "退出 Heicode" from the tray menu. Co-Authored-By: Claude Opus 4.6 --- cc-haha/desktop/src-tauri/src/lib.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) 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 {