From f0bf02613332652b6d3393d840d215fe95355ac8 Mon Sep 17 00:00:00 2001 From: Developer Date: Wed, 8 Apr 2026 14:02:25 -0700 Subject: [PATCH] Handle ExitRequested to stop sidecar on macOS Cmd+Q On macOS, Cmd+Q triggers ExitRequested before Exit. If the app is force-quit or closed via Cmd+Q, the Exit event may not fire, leaving the sidecar process orphaned with ports 8080/8081 in use. Now handles both ExitRequested and Exit to ensure the sidecar is always stopped when the app closes. Co-Authored-By: Claude Opus 4.6 (1M context) --- src-tauri/src/lib.rs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index c938042..594993b 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -74,14 +74,25 @@ pub fn run() { .build(tauri::generate_context!()) .expect("error while building tauri application") .run(|app, event| { - if let tauri::RunEvent::Exit = event { - // Stop the sidecar when the app exits - if let Some(state) = app.try_state::() { - if let Ok(mut mgr) = state.0.lock() { - eprintln!("[app] Stopping sidecar on exit..."); - mgr.stop(); + match event { + tauri::RunEvent::Exit => { + if let Some(state) = app.try_state::() { + if let Ok(mut mgr) = state.0.lock() { + eprintln!("[app] Stopping sidecar on exit..."); + mgr.stop(); + } } } + tauri::RunEvent::ExitRequested { .. } => { + // Also stop sidecar on exit request (Cmd+Q on macOS) + if let Some(state) = app.try_state::() { + if let Ok(mut mgr) = state.0.lock() { + eprintln!("[app] Stopping sidecar on exit request..."); + mgr.stop(); + } + } + } + _ => {} } }); }