diff --git a/crates/app-tauri/src/lib.rs b/crates/app-tauri/src/lib.rs index 6ebcf91..42ac4c0 100644 --- a/crates/app-tauri/src/lib.rs +++ b/crates/app-tauri/src/lib.rs @@ -124,6 +124,8 @@ pub fn run() { let _ = model_servers.stop_on_app_exit().await; }); } + + close_non_main_webview_windows(&handle); } }); } @@ -253,3 +255,39 @@ pub fn run() { .run(tauri::generate_context!()) .expect("error while running IdeA Tauri application"); } + +fn close_non_main_webview_windows(handle: &tauri::AppHandle) { + for (label, window) in handle.webview_windows() { + if !should_close_with_main_window(&label) { + continue; + } + + let _ = window.close(); + } +} + +fn should_close_with_main_window(label: &str) -> bool { + label != "main" +} + +#[cfg(test)] +mod tests { + use super::should_close_with_main_window; + + #[test] + fn main_window_close_does_not_target_main_again() { + assert!(!should_close_with_main_window("main")); + } + + #[test] + fn main_window_close_targets_detached_view_windows() { + assert!(should_close_with_main_window( + "view-work-00000000-0000-0000-0000-000000000001" + )); + } + + #[test] + fn main_window_close_targets_other_auxiliary_windows() { + assert!(should_close_with_main_window("settings")); + } +}