From b91fe876f9206c31681e7c6a2007e2d3cb356343 Mon Sep 17 00:00:00 2001 From: Developer Date: Wed, 8 Apr 2026 11:54:53 -0700 Subject: [PATCH] Stop sidecar process when the app exits The sidecar process was orphaned when the Tauri app closed, leaving ports 8080/8081 in use. On next launch the new sidecar couldn't bind those ports and failed to start. Added RunEvent::Exit handler that stops the sidecar before the app process terminates. Co-Authored-By: Claude Opus 4.6 (1M context) --- src-tauri/src/lib.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 2421457..c938042 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -71,6 +71,17 @@ pub fn run() { sidecar::reset_sidecar, write_log, ]) - .run(tauri::generate_context!()) - .expect("error while running tauri application"); + .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(); + } + } + } + }); }