From 5c90de84de351c5cad0cc61987ebd0e362f542c1 Mon Sep 17 00:00:00 2001 From: Shantur Rathore Date: Thu, 2 Apr 2026 17:15:25 +0100 Subject: [PATCH] fix tauri window shutdown behavior --- packages/tauri-app/src-tauri/src/main.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/tauri-app/src-tauri/src/main.rs b/packages/tauri-app/src-tauri/src/main.rs index f15481a5..8a193817 100644 --- a/packages/tauri-app/src-tauri/src/main.rs +++ b/packages/tauri-app/src-tauri/src/main.rs @@ -523,11 +523,24 @@ fn main() { event: tauri::WindowEvent::CloseRequested { api, .. }, .. } => { - // Ensure we have time to stop the CLI process before the app exits. + // Let windows close normally. App shutdown is handled only after the + // last window is actually gone so remote windows can outlive `main`. + let _ = api; + } + tauri::RunEvent::WindowEvent { + event: tauri::WindowEvent::Destroyed, + .. + } => { + if !app_handle.webview_windows().is_empty() { + return; + } + + // Stop the CLI only when the final window is gone and the app is + // truly exiting. if QUIT_REQUESTED.swap(true, Ordering::SeqCst) { return; } - api.prevent_close(); + let app = app_handle.clone(); std::thread::spawn(move || { if let Some(state) = app.try_state::() {