From ce3a216242e0b3b355b35986829e9575f4186985 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Wed, 6 May 2026 07:03:27 +0200 Subject: [PATCH] Implement graceful shutdown for backend sidecar on exit --- src-tauri/src/main.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 29e222e..4999d9d 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -785,8 +785,14 @@ fn open_external_link(app: AppHandle, url: String) -> Result { } } +fn shutdown_backend_sidecar(app: &AppHandle) { + if let Some(sidecar) = app.try_state::() { + sidecar.shutdown(); + } +} + fn main() { - tauri::Builder::default() + let app = tauri::Builder::default() .menu(|handle| tauri::menu::Menu::default(handle)) .plugin(tauri_plugin_dialog::init()) .plugin(tauri_plugin_opener::init()) @@ -815,6 +821,15 @@ fn main() { open_path, open_external_link ]) - .run(tauri::generate_context!()) - .expect("failed to run Heimgeist Tauri desktop shell"); + .build(tauri::generate_context!()) + .expect("failed to build Heimgeist Tauri desktop shell"); + + app.run(|app_handle, event| { + if matches!( + event, + tauri::RunEvent::ExitRequested { .. } | tauri::RunEvent::Exit + ) { + shutdown_backend_sidecar(app_handle); + } + }); }