fix(window): honour minimize-to-tray on the macOS close button

The macOS red close button always emitted app:force-quit, which exits
unconditionally and never checked the minimizeToTray setting — so on macOS
the window closed the app even with "Minimize to Tray" enabled. Route the
main-window close through window:close-requested on all platforms, so JS
decides hide-vs-exit from the setting (default off = unchanged quit). The
tray "Exit" item still force-quits.

Fixes #1103

(cherry picked from commit acd6f12aba)
This commit is contained in:
Psychotoxical
2026-06-16 21:00:18 +02:00
committed by cucadmuh
parent 961dba996c
commit 16e562b42d
+8 -17
View File
@@ -608,24 +608,15 @@ pub fn run() {
if let tauri::WindowEvent::CloseRequested { api, .. } = event { if let tauri::WindowEvent::CloseRequested { api, .. } = event {
if window.label() == "main" { if window.label() == "main" {
api.prevent_close(); api.prevent_close();
// All platforms: pause rendering, then let JS decide hide-to-tray
#[cfg(target_os = "macos")] // vs exit based on the minimizeToTray setting. macOS previously
{ // always force-quit on the red close button, ignoring the setting
// On macOS the red close button quits the app entirely. // (#1103). The tray "Exit" item still emits app:force-quit for an
// Route through JS so playback position + Orbit state get // unconditional quit.
// flushed; exit_app on the way back stops the audio engine. if let Some(w) = window.app_handle().get_webview_window("main") {
let _ = window.emit("app:force-quit", ()); let _ = w.eval(PAUSE_RENDERING_JS);
}
#[cfg(not(target_os = "macos"))]
{
// Pause rendering before JS decides whether to hide to tray or exit.
if let Some(w) = window.app_handle().get_webview_window("main") {
let _ = w.eval(PAUSE_RENDERING_JS);
}
// Let JS decide: minimize to tray or exit, based on user setting.
let _ = window.emit("window:close-requested", ());
} }
let _ = window.emit("window:close-requested", ());
} else if window.label() == "mini" { } else if window.label() == "mini" {
// Native close on the mini: hide instead of destroying so // Native close on the mini: hide instead of destroying so
// state is preserved, and restore the main window. // state is preserved, and restore the main window.