feat: minimize to system tray on window close instead of quitting

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 <noreply@anthropic.com>
This commit is contained in:
2026-05-18 16:35:34 +08:00
co-authored by Claude Opus 4.6
parent bda36c44be
commit 853e3b4ca9
+8 -6
View File
@@ -1083,18 +1083,20 @@ 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 => {
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 {
has_visible_windows: false,