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) <noreply@anthropic.com>
This commit is contained in:
@@ -71,6 +71,17 @@ pub fn run() {
|
|||||||
sidecar::reset_sidecar,
|
sidecar::reset_sidecar,
|
||||||
write_log,
|
write_log,
|
||||||
])
|
])
|
||||||
.run(tauri::generate_context!())
|
.build(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.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::<sidecar::ManagedSidecar>() {
|
||||||
|
if let Ok(mut mgr) = state.0.lock() {
|
||||||
|
eprintln!("[app] Stopping sidecar on exit...");
|
||||||
|
mgr.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user