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: remove dispatch_async_f deferred first-responder calls

Louis Beaumontce639dfcd38a
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/window_api.rs b/apps/screenpipe-app-tauri/src-tauri/src/window_api.rs
index 5ef455383..c1b3ba042 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/window_api.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/window_api.rs
@@ -426,52 +426,8 @@ pub unsafe fn make_nswindow_webview_first_responder(ns_win: tauri_nspanel::cocoa
// Attach pinch-to-zoom gesture recognizer (same as NSPanel overlay)
attach_magnify_gesture_to_view(wk_view);
- // Set first responder immediately (handles the common case)
+ // Set first responder immediately
let _: () = msg_send![ns_win, makeFirstResponder: wk_view];
-
- // Also schedule on the next run-loop tick to win the race against any
- // deferred responder-chain reset triggered by makeKeyAndOrderFront.
- // Same pattern as make_webview_first_responder for NSPanel.
- //
- // SAFETY: retain both objects so they survive until the callback fires.
- // Without this, hiding/closing the panel between now and the next tick
- // would leave dangling pointers → use-after-free → SIGSEGV in
- // objc_autoreleasePoolPop.
- let _: () = msg_send![ns_win, retain];
- let _: () = msg_send![wk_view, retain];
- let win_id = ns_win as usize;
- let wk_id = wk_view as usize;
- extern "C" {
- static _dispatch_main_q: std::ffi::c_void;
- fn dispatch_async_f(
- queue: *const std::ffi::c_void,
- context: *mut std::ffi::c_void,
- work: extern "C" fn(*mut std::ffi::c_void),
- );
- }
- struct Ctx {
- win_id: usize,
- wk_id: usize,
- }
- extern "C" fn set_responder(ctx: *mut std::ffi::c_void) {
- with_autorelease_pool(|| unsafe {
- use objc::{msg_send, sel, sel_impl};
- use tauri_nspanel::cocoa::base::id;
- let ctx = Box::from_raw(ctx as *mut Ctx);
- let window: id = ctx.win_id as id;
- let wk: id = ctx.wk_id as id;
- let _: () = msg_send![window, makeFirstResponder: wk];
- // Balance the retains from when we scheduled this callback
- let _: () = msg_send![window, release];
- let _: () = msg_send![wk, release];
- });
- }
- let ctx = Box::into_raw(Box::new(Ctx { win_id, wk_id }));
- dispatch_async_f(
- &_dispatch_main_q,
- ctx as *mut std::ffi::c_void,
- set_responder,
- );
}
}); // with_autorelease_pool
}
@@ -523,55 +479,8 @@ pub unsafe fn make_webview_first_responder(panel: &tauri_nspanel::raw_nspanel::R
// before WebKit's internal multi-process routing claims them.
attach_magnify_gesture_to_view(wk_view);
- // Set first responder immediately (handles the common case)
+ // Set first responder immediately
panel.make_first_responder(Some(wk_view));
-
- // Also schedule on the next run-loop tick to win the race against any
- // deferred responder-chain reset triggered by make_key_window().
- // We use dispatch_async(main_queue) so our call lands after AppKit's
- // deferred responder chain updates from the current event.
- //
- // SAFETY: retain both objects so they survive until the callback fires.
- // Without this, hiding/closing the panel between now and the next tick
- // would leave dangling pointers → use-after-free → SIGSEGV.
- let window: id = msg_send![panel.content_view(), window];
- let _: () = msg_send![window, retain];
- let _: () = msg_send![wk_view, retain];
- let panel_id = window as usize;
- let wk_id = wk_view as usize;
- extern "C" {
- // dispatch_get_main_queue() is a C macro, not a real symbol.
- // The actual global is _dispatch_main_q provided by libSystem.
- static _dispatch_main_q: std::ffi::c_void;
- fn dispatch_async_f(
- queue: *const std::ffi::c_void,
- context: *mut std::ffi::c_void,
- work: extern "C" fn(*mut std::ffi::c_void),
- );
- }
- struct Ctx {
- panel_id: usize,
- wk_id: usize,
- }
- extern "C" fn set_responder(ctx: *mut std::ffi::c_void) {
- with_autorelease_pool(|| unsafe {
- use objc::{msg_send, sel, sel_impl};
- use tauri_nspanel::cocoa::base::id;
- let ctx = Box::from_raw(ctx as *mut Ctx);
- let window: id = ctx.panel_id as id;
- let wk: id = ctx.wk_id as id;
- let _: () = msg_send![window, makeFirstResponder: wk];
- // Balance the retains from when we scheduled this callback
- let _: () = msg_send![window, release];
- let _: () = msg_send![wk, release];
- });
- }
- let ctx = Box::into_raw(Box::new(Ctx { panel_id, wk_id }));
- dispatch_async_f(
- &_dispatch_main_q,
- ctx as *mut std::ffi::c_void,
- set_responder,
- );
}); // with_autorelease_pool
}