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
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix(macos): guard deferred makeFirstResponder with MAIN_PANEL_SHOWN check
Louis Beaumont3288bdb569cc
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/window_api.rs b/apps/screenpipe-app-tauri/src-tauri/src/window_api.rsindex 07827c4b9..897fcabe2 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/window_api.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/window_api.rs@@ -431,12 +431,13 @@ pub unsafe fn make_nswindow_webview_first_responder(ns_win: tauri_nspanel::cocoa// Also schedule on the next run-loop tick to win the race against any// deferred responder-chain reset triggered by makeKeyAndOrderFront.- // Uses performSelector:withObject:afterDelay: which automatically retains- // both receiver and argument — no manual retain/release needed, so no- // risk of SIGBUS from zombie objects if the window closes in between.- let _: () = msg_send![ns_win, performSelector: sel!(makeFirstResponder:)- withObject: wk_view- afterDelay: 0.0f64];+ // Only schedule if panel is currently shown — prevents re-activating+ // a panel that was hidden between now and the next tick.+ if MAIN_PANEL_SHOWN.load(std::sync::atomic::Ordering::SeqCst) {+ let _: () = msg_send![ns_win, performSelector: sel!(makeFirstResponder:)+ withObject: wk_view+ afterDelay: 0.0f64];+ }}}); // with_autorelease_pool}@@ -493,13 +494,18 @@ pub unsafe fn make_webview_first_responder(panel: &tauri_nspanel::raw_nspanel::R// Also schedule on the next run-loop tick to win the race against any// deferred responder-chain reset triggered by make_key_window().- // Uses performSelector:withObject:afterDelay: which automatically retains- // both receiver and argument — no manual retain/release needed, so no- // risk of SIGBUS from zombie objects if the panel closes in between.- let window: id = msg_send![panel.content_view(), window];- let _: () = msg_send![window, performSelector: sel!(makeFirstResponder:)- withObject: wk_view- afterDelay: 0.0f64];+ // Uses performSelector:afterDelay: but ONLY if the panel is currently+ // shown. The deferred call itself is safe (AppKit retains both objects),+ // and the cancel_deferred_first_responder no-op means the deferred call+ // may fire on a hidden panel — but MAIN_PANEL_SHOWN is set to false+ // BEFORE hide, so we only schedule the deferred call when we know the+ // panel is actively being shown right now.+ if MAIN_PANEL_SHOWN.load(std::sync::atomic::Ordering::SeqCst) {+ let window: id = msg_send![panel.content_view(), window];+ let _: () = msg_send![window, performSelector: sel!(makeFirstResponder:)+ withObject: wk_view+ afterDelay: 0.0f64];+ }}); // with_autorelease_pool}