Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix: dispatch space monitor ObjC calls to main thread

Louis Beaumont418826dfa4ce
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/space_monitor.rs b/apps/screenpipe-app-tauri/src-tauri/src/space_monitor.rs
index 3c80b6471..16ae2addb 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/space_monitor.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/space_monitor.rs
@@ -76,11 +76,16 @@ pub fn setup_space_listener(app: AppHandle) {
return;
}
debug!("macOS Space changed, hiding overlay");
- // Do NOT restore_frontmost_app here — the user intentionally
- // switched Spaces, so re-activating the previous app would
- // pull them back. Just clear the saved app and hide.
- crate::window_api::clear_frontmost_app();
- hide_main_window(&app_for_block);
+ // Dispatch to main thread — this notification callback can
+ // fire on any thread, and both clear_frontmost_app (ObjC
+ // release) and hide_main_window (NSPanel order_out) require
+ // the main thread to avoid autorelease pool corruption.
+ let app = app_for_block.clone();
+ let app_inner = app.clone();
+ let _ = app.run_on_main_thread(move || {
+ crate::window_api::clear_frontmost_app();
+ hide_main_window(&app_inner);
+ });
});
let block = block.copy();