Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat: Improve window management on Windows platform (#1237)

Richie McIlroycc4da96d80e1
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() {