From b0dc95a956821d76804a89f46033a9675b36adc2 Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Fri, 17 Oct 2025 21:13:56 +0100 Subject: [PATCH] feat: Improve window management on Windows platform Refines logic for reopening and focusing the main window when certain windows are closed, specifically on Windows. Adds helper functions to check for open editor windows and to reopen the main window if needed. --- apps/desktop/src-tauri/src/lib.rs | 54 +++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs index 3ae2cdeae..53b8a4986 100644 --- a/apps/desktop/src-tauri/src/lib.rs +++ b/apps/desktop/src-tauri/src/lib.rs @@ -2386,10 +2386,34 @@ pub async fn run(recording_logging_handle: LoggingHandle, logs_dir: PathBuf) { window_ids.ids.lock().unwrap().retain(|(_, _id)| *_id != id); tokio::spawn(EditorInstances::remove(window.clone())); + + #[cfg(target_os = "windows")] + if CapWindowId::Settings.get(&app).is_none() { + reopen_main_window(&app); + } } - CapWindowId::Settings - | CapWindowId::Upgrade - | CapWindowId::ModeSelect => { + CapWindowId::Settings => { + for (label, window) in app.webview_windows() { + if let Ok(id) = CapWindowId::from_str(&label) + && matches!( + id, + CapWindowId::TargetSelectOverlay { .. } + | CapWindowId::Main + | CapWindowId::Camera + ) + { + let _ = window.show(); + } + } + + #[cfg(target_os = "windows")] + if !has_open_editor_window(&app) { + reopen_main_window(&app); + } + + return; + } + CapWindowId::Upgrade | CapWindowId::ModeSelect => { for (label, window) in app.webview_windows() { if let Ok(id) = CapWindowId::from_str(&label) && matches!( @@ -2508,6 +2532,30 @@ pub async fn run(recording_logging_handle: LoggingHandle, logs_dir: PathBuf) { }); } +#[cfg(target_os = "windows")] +fn has_open_editor_window(app: &AppHandle) -> bool { + app.webview_windows() + .keys() + .any(|label| matches!(CapWindowId::from_str(label), Ok(CapWindowId::Editor { .. }))) +} + +#[cfg(target_os = "windows")] +fn reopen_main_window(app: &AppHandle) { + if let Some(main) = CapWindowId::Main.get(app) { + let _ = main.show(); + let _ = main.set_focus(); + } else { + let handle = app.clone(); + tokio::spawn(async move { + let _ = ShowCapWindow::Main { + init_target_mode: None, + } + .show(&handle) + .await; + }); + } +} + async fn resume_uploads(app: AppHandle) -> Result<(), String> { let recordings_dir = recordings_path(&app); if !recordings_dir.exists() {