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(); + } + } + } + }); }