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(macos): keyboard input not working in main window opened from tray

Louis Beaumontf0c09676ff29
diff --git a/apps/screenpipe-app-tauri/app/layout.tsx b/apps/screenpipe-app-tauri/app/layout.tsx
index 30056dee3..d6fdd3103 100644
--- a/apps/screenpipe-app-tauri/app/layout.tsx
+++ b/apps/screenpipe-app-tauri/app/layout.tsx
@@ -95,12 +95,11 @@ export default function RootLayout({
const focusWatchdog = setInterval(() => {
// Only check when the window is visible and focused
if (document.hidden || !document.hasFocus()) return;
- // If we haven't seen a keystroke in 10s and the active element is body
- // (not an input), something may be wrong — but don't interfere if user
- // is just using the mouse. Only recover if user recently clicked (mouse
- // activity without keyboard suggests potential stuck state).
+ // If we haven't seen a keystroke in 2s and the active element is body
+ // (not an input), the WKWebView may have lost first-responder status.
+ // Recover quickly — 10s was too long and left typing broken after tray open.
const now = Date.now();
- const noRecentKeys = now - lastKeyTime > 10_000;
+ const noRecentKeys = now - lastKeyTime > 2_000;
const activeIsBody = document.activeElement === document.body || !document.activeElement;
if (noRecentKeys && activeIsBody) {
callNativeFocusRecovery();
diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml b/apps/screenpipe-app-tauri/src-tauri/Cargo.toml
index ab5298e16..f737d61b8 100644
--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml
+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "screenpipe-app"
-version = "2.1.7"
+version = "2.1.8"
description = "24/7 memory for your desktop. 100% local."
authors = ["you"]
license = ""
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 701cc934b..5714cb19a 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/window_api.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/window_api.rs
@@ -716,6 +716,7 @@ impl ShowRewindWindow {
run_on_main_thread_safe(app, move || {
if let Ok(panel) = app_clone.get_webview_panel(&lbl) {
use tauri_nspanel::cocoa::appkit::NSWindowCollectionBehavior;
+ use tauri_nspanel::cocoa::base::id;
use objc::{msg_send, sel, sel_impl};
panel.set_level(1001);
panel.set_collection_behaviour(
@@ -728,6 +729,12 @@ impl ShowRewindWindow {
save_frontmost_app();
unsafe {
let _: () = msg_send![&*panel, setAlphaValue: 1.0f64];
+ // Activate the app so keyboard events route to the WKWebView.
+ // NSNonactivatingPanelMask prevents the app from becoming
+ // frontmost on its own, so without this the webview never
+ // receives keyboard input when opened from the tray menu.
+ let ns_app: id = msg_send![objc::class!(NSApplication), sharedApplication];
+ let _: () = msg_send![ns_app, activateIgnoringOtherApps: true];
}
panel.order_front_regardless();
panel.make_key_window();
@@ -1076,6 +1083,7 @@ impl ShowRewindWindow {
let app_for_emit = window_clone.app_handle().clone();
run_on_main_thread_safe(app, move || {
use tauri_nspanel::cocoa::appkit::NSWindowCollectionBehavior;
+ use tauri_nspanel::cocoa::base::id;
use objc::{msg_send, sel, sel_impl};
if let Ok(panel) = window_clone.to_panel() {
@@ -1100,6 +1108,11 @@ impl ShowRewindWindow {
NSWindowCollectionBehavior::NSWindowCollectionBehaviorMoveToActiveSpace |
NSWindowCollectionBehavior::NSWindowCollectionBehaviorFullScreenAuxiliary
);
+ // Activate the app so keyboard events route to the WKWebView.
+ unsafe {
+ let ns_app: id = msg_send![objc::class!(NSApplication), sharedApplication];
+ let _: () = msg_send![ns_app, activateIgnoringOtherApps: true];
+ }
panel.order_front_regardless();
panel.make_key_window();
// Set WKWebView as first responder AFTER make_key_window
@@ -1165,9 +1178,16 @@ impl ShowRewindWindow {
#[cfg(target_os = "macos")]
{
use objc::{msg_send, sel, sel_impl};
+ use tauri_nspanel::cocoa::base::id;
if let Ok(panel) = app_clone.get_webview_panel("main-window") {
unsafe {
let _: () = msg_send![&*panel, setAlphaValue: 1.0f64];
+ // Activate the app so keyboard events
+ // route to the WKWebView (same reason as
+ // show_existing_main — NonActivatingPanel
+ // won't activate the app on its own).
+ let ns_app: id = msg_send![objc::class!(NSApplication), sharedApplication];
+ let _: () = msg_send![ns_app, activateIgnoringOtherApps: true];
}
// Ensure panel is key window before setting first
// responder, otherwise magnifyWithEvent: won't