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) <noreply@anthropic.com>
This commit is contained in:
@@ -74,8 +74,8 @@ 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
|
||||
match event {
|
||||
tauri::RunEvent::Exit => {
|
||||
if let Some(state) = app.try_state::<sidecar::ManagedSidecar>() {
|
||||
if let Ok(mut mgr) = state.0.lock() {
|
||||
eprintln!("[app] Stopping sidecar on exit...");
|
||||
@@ -83,5 +83,16 @@ pub fn run() {
|
||||
}
|
||||
}
|
||||
}
|
||||
tauri::RunEvent::ExitRequested { .. } => {
|
||||
// Also stop sidecar on exit request (Cmd+Q on macOS)
|
||||
if let Some(state) = app.try_state::<sidecar::ManagedSidecar>() {
|
||||
if let Ok(mut mgr) = state.0.lock() {
|
||||
eprintln!("[app] Stopping sidecar on exit request...");
|
||||
mgr.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user