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
wip: remove NSWindowDidBecomeKeyNotification observer, fix chat pre-creation, other agent changes
Louis Beaumonte5e61639da2f
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/main.rs b/apps/screenpipe-app-tauri/src-tauri/src/main.rsindex bc21519e6..4165efd10 100755--- a/apps/screenpipe-app-tauri/src-tauri/src/main.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/main.rs@@ -1725,10 +1725,6 @@ async fn main() {// recognizer callback (in window_api.rs) can emit Tauri events.crate::window_api::init_magnify_handler(app.handle().clone());- // Register NSWindowDidBecomeKeyNotification observer for first-responder fix.- // This replaces performSelector:afterDelay: which leaked deferred calls.- #[cfg(target_os = "macos")]- crate::window_api::register_become_key_observer();}// Logging setup@@ -1975,14 +1971,16 @@ async fn main() {info!("Pre-creating chat panel for fullscreen Space support");match ShowRewindWindow::Chat.show(&app_handle_chat) {Ok(_window) => {- // The show() call makes the panel visible (order_front +- // make_key). Hide it immediately so it's pre-created but- // not visible. Without this, is_visible() returns true- // and the chat shortcut toggle always hides instead of shows.- use tauri_nspanel::ManagerExt;- if let Ok(panel) = app_handle_chat.get_webview_panel("chat") {- panel.order_out(None);- }+ // The show() call dispatches panel config to the main+ // thread. We must also hide on the main thread, AND+ // wait for the show() config to complete first.+ let app_for_hide = app_handle_chat.clone();+ let _ = app_handle_chat.run_on_main_thread(move || {+ use tauri_nspanel::ManagerExt;+ if let Ok(panel) = app_for_hide.get_webview_panel("chat") {+ panel.order_out(None);+ }+ });info!("Chat panel pre-created (hidden, panel configured)");}Err(e) => {diff --git a/apps/screenpipe-app-tauri/src-tauri/src/window_api.rs b/apps/screenpipe-app-tauri/src-tauri/src/window_api.rsindex cfd1ef8fa..0c6b3f78b 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/window_api.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/window_api.rs@@ -490,91 +490,6 @@ pub unsafe fn make_webview_first_responder(panel: &tauri_nspanel::raw_nspanel::R}); // with_autorelease_pool}-/// Register a global `NSWindowDidBecomeKeyNotification` observer that sets the-/// WKWebView as first responder whenever any of our windows becomes key.-///-/// This replaces the old `performSelector:afterDelay:` approach which leaked-/// deferred calls on every show/hide cycle, eventually breaking panel toggling.-///-/// Why this works:-/// - AppKit fires `NSWindowDidBecomeKeyNotification` AFTER it finishes its own-/// responder-chain setup — no race condition-/// - No deferred calls to leak or cancel-/// - No raw pointer capture — we find the WKWebView fresh each time-/// - The observer lives on NSNotificationCenter, not the panel, so no-/// deallocation crash-#[cfg(target_os = "macos")]-pub fn register_become_key_observer() {- use block::ConcreteBlock;- use objc::{class, msg_send, sel, sel_impl};- use tauri_nspanel::cocoa::base::{id, nil};- use tauri_nspanel::cocoa::foundation::{NSArray, NSString};-- unsafe {- let center: id = msg_send![class!(NSNotificationCenter), defaultCenter];- let name = NSString::alloc(nil).init_str("NSWindowDidBecomeKeyNotification");-- let block = ConcreteBlock::new(move |notification: id| {- with_autorelease_pool(|| {- let window: id = msg_send![notification, object];- if window == nil {- return;- }-- // Only act on visible windows (alpha > 0) to avoid re-activating- // panels that are in the process of being hidden.- let alpha: f64 = msg_send![window, alphaValue];- if alpha < 0.5 {- return;- }-- // Find WKWebView in the window's content view- let content_view: id = msg_send![window, contentView];- if content_view == nil {- return;- }-- let wk_class: *const objc::runtime::Class = class!(WKWebView);- let mut wk_view: id = nil;- let mut queue: Vec<id> = vec![content_view];- while let Some(view) = queue.pop() {- let is_wk: bool = msg_send![view, isKindOfClass: wk_class];- if is_wk {- wk_view = view;- break;- }- let subviews: id = msg_send![view, subviews];- if subviews != nil {- let count: u64 = NSArray::count(subviews);- for i in 0..count {- let child: id = NSArray::objectAtIndex(subviews, i);- queue.push(child);- }- }- }-- if wk_view != nil {- let _: () = msg_send![window, makeFirstResponder: wk_view];- }- });- });- let block = block.copy();-- let _: id = msg_send![- center,- addObserverForName: name- object: nil- queue: nil- usingBlock: &*block- ];-- // Leak the block intentionally — observer lives for app lifetime- std::mem::forget(block);- }-- info!("NSWindowDidBecomeKeyNotification observer registered for first-responder fix");-}-/// Shared panel visibility sequence — the single source of truth for making an/// NSPanel visible and interactive. Call this **on the main thread** after any/// mode-specific pre-show setup (collection behavior, screen positioning, etc.).diff --git a/crates/screenpipe-a11y/examples/linux_test.rs b/crates/screenpipe-a11y/examples/linux_test.rsindex 27d97e97a..a37dc41ef 100644--- a/crates/screenpipe-a11y/examples/linux_test.rs+++ b/crates/screenpipe-a11y/examples/linux_test.rs@@ -53,8 +53,8 @@ fn main() {);}}- Ok(TreeWalkResult::Skipped) => {- println!("Window skipped (incognito/private or filtered).");+ Ok(TreeWalkResult::Skipped(reason)) => {+ println!("Window skipped ({}).", reason);}Ok(TreeWalkResult::NotFound) => {println!("No focused window found (or no text content).");diff --git a/crates/screenpipe-a11y/src/tree/linux.rs b/crates/screenpipe-a11y/src/tree/linux.rsindex 0dc46610e..5cc046a10 100644--- a/crates/screenpipe-a11y/src/tree/linux.rs+++ b/crates/screenpipe-a11y/src/tree/linux.rs@@ -16,7 +16,7 @@//! - Enable with: `gsettings set org.gnome.desktop.interface toolkit-accessibility true`use super::{- AccessibilityTreeNode, NodeBounds, TreeSnapshot, TreeWalkResult, TreeWalkerConfig,+ AccessibilityTreeNode, NodeBounds, SkipReason, TreeSnapshot, TreeWalkResult, TreeWalkerConfig,TreeWalkerPlatform, TruncationReason,};use anyhow::{Context, Result};@@ -866,7 +866,7 @@ impl TreeWalkerPlatform for LinuxTreeWalker {// Skip incognito / private browsing windows (localized title check)if self.config.ignore_incognito_windows && crate::incognito::is_title_private(&window_title){- return Ok(TreeWalkResult::Skipped);+ return Ok(TreeWalkResult::Skipped(SkipReason::Incognito));}let app_lower = app_name.to_lowercase();@@ -877,7 +877,7 @@ impl TreeWalkerPlatform for LinuxTreeWalker {let p = pattern.to_lowercase();app_lower.contains(&p) || window_lower.contains(&p)}) {- return Ok(TreeWalkResult::Skipped);+ return Ok(TreeWalkResult::Skipped(SkipReason::UserIgnored));}// Apply user-configured included windows (whitelist)@@ -887,7 +887,7 @@ impl TreeWalkerPlatform for LinuxTreeWalker {app_lower.contains(&p) || window_lower.contains(&p)});if !matches {- return Ok(TreeWalkResult::Skipped);+ return Ok(TreeWalkResult::Skipped(SkipReason::NotInIncludeList));}}diff --git a/crates/screenpipe-a11y/src/tree/macos.rs b/crates/screenpipe-a11y/src/tree/macos.rsindex f6372450e..d71a913de 100644--- a/crates/screenpipe-a11y/src/tree/macos.rs+++ b/crates/screenpipe-a11y/src/tree/macos.rs@@ -5,7 +5,8 @@//! macOS accessibility tree walker using cidre AX APIs.use super::{- AccessibilityTreeNode, TreeSnapshot, TreeWalkResult, TreeWalkerConfig, TreeWalkerPlatform,+ AccessibilityTreeNode, SkipReason, TreeSnapshot, TreeWalkResult, TreeWalkerConfig,+ TreeWalkerPlatform,};use anyhow::Result;use chrono::Utc;@@ -222,7 +223,7 @@ impl MacosTreeWalker {"loginwindow",];if EXCLUDED_APPS.iter().any(|ex| app_lower.contains(ex)) {- return Ok(TreeWalkResult::Skipped);+ return Ok(TreeWalkResult::Skipped(SkipReason::ExcludedApp));}// Apply user-configured ignored windows (check app name)@@ -230,7 +231,7 @@ impl MacosTreeWalker {let p = pattern.to_lowercase();app_lower.contains(&p)}) {- return Ok(TreeWalkResult::Skipped);+ return Ok(TreeWalkResult::Skipped(SkipReason::UserIgnored));}// 2. Get the focused window via AX API@@ -267,7 +268,7 @@ impl MacosTreeWalker {.incognito_detector.is_incognito(&app_name, 0, &window_name){- return Ok(TreeWalkResult::Skipped);+ return Ok(TreeWalkResult::Skipped(SkipReason::Incognito));}// Apply user-configured ignored windows (also check window title)@@ -276,7 +277,7 @@ impl MacosTreeWalker {let p = pattern.to_lowercase();window_lower.contains(&p)}) {- return Ok(TreeWalkResult::Skipped);+ return Ok(TreeWalkResult::Skipped(SkipReason::UserIgnored));}// Apply user-configured included windows (also check window title)@@ -290,7 +291,7 @@ impl MacosTreeWalker {window_lower.contains(&p)});if !matches_app && !matches_window {- return Ok(TreeWalkResult::Skipped);+ return Ok(TreeWalkResult::Skipped(SkipReason::NotInIncludeList));}}diff --git a/crates/screenpipe-a11y/src/tree/mod.rs b/crates/screenpipe-a11y/src/tree/mod.rsindex cd8c56115..8e3ef0136 100644--- a/crates/screenpipe-a11y/src/tree/mod.rs+++ b/crates/screenpipe-a11y/src/tree/mod.rs@@ -190,12 +190,36 @@ impl Default for TreeWalkerConfig {pub enum TreeWalkResult {/// Successfully walked the tree and captured a snapshot.Found(TreeSnapshot),- /// Window was skipped due to incognito/private browsing or user filters.- Skipped,+ /// Window was skipped due to incognito/private browsing, excluded apps, or user filters.+ Skipped(SkipReason),/// No focused window found or tree walk produced no text.NotFound,}+/// Reason a window was skipped during tree walk.+#[derive(Debug, Clone)]+pub enum SkipReason {+ /// Incognito or private browsing window detected.+ Incognito,+ /// App is in the hardcoded exclusion list (e.g. screenpipe, keychain access).+ ExcludedApp,+ /// User-configured ignored window pattern matched.+ UserIgnored,+ /// User-configured included window whitelist didn't match.+ NotInIncludeList,+}++impl std::fmt::Display for SkipReason {+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {+ match self {+ SkipReason::Incognito => write!(f, "incognito/private browsing"),+ SkipReason::ExcludedApp => write!(f, "excluded app"),+ SkipReason::UserIgnored => write!(f, "user-configured ignored window"),+ SkipReason::NotInIncludeList => write!(f, "not in included windows list"),+ }+ }+}+/// Platform-specific tree walker trait.pub trait TreeWalkerPlatform: Send {/// Walk the focused window's accessibility tree.diff --git a/crates/screenpipe-a11y/src/tree/windows.rs b/crates/screenpipe-a11y/src/tree/windows.rsindex 98af0170c..fba300450 100644--- a/crates/screenpipe-a11y/src/tree/windows.rs+++ b/crates/screenpipe-a11y/src/tree/windows.rs@@ -8,7 +8,7 @@//! the focused window's tree and extract all visible text — matching macOS behavior.use super::{- AccessibilityTreeNode, NodeBounds, TreeSnapshot, TreeWalkResult, TreeWalkerConfig,+ AccessibilityTreeNode, NodeBounds, SkipReason, TreeSnapshot, TreeWalkResult, TreeWalkerConfig,TreeWalkerPlatform,};use crate::events::AccessibilityNode;@@ -186,7 +186,7 @@ impl TreeWalkerPlatform for WindowsTreeWalker {// Skip excluded appslet app_lower = app_name.to_lowercase();if EXCLUDED_APPS.iter().any(|ex| app_lower.contains(ex)) {- return Ok(TreeWalkResult::Skipped);+ return Ok(TreeWalkResult::Skipped(SkipReason::ExcludedApp));}// Get window title@@ -199,7 +199,7 @@ impl TreeWalkerPlatform for WindowsTreeWalker {// Skip incognito / private browsing windows (localized title check)if self.config.ignore_incognito_windows && crate::incognito::is_title_private(&window_name){- return Ok(TreeWalkResult::Skipped);+ return Ok(TreeWalkResult::Skipped(SkipReason::Incognito));}// Apply user-configured ignored windows (check app name and window title)@@ -208,7 +208,7 @@ impl TreeWalkerPlatform for WindowsTreeWalker {let p = pattern.to_lowercase();app_lower.contains(&p) || window_lower.contains(&p)}) {- return Ok(TreeWalkResult::Skipped);+ return Ok(TreeWalkResult::Skipped(SkipReason::UserIgnored));}// Apply user-configured included windows (whitelist mode)@@ -218,7 +218,7 @@ impl TreeWalkerPlatform for WindowsTreeWalker {app_lower.contains(&p) || window_lower.contains(&p)});if !matches {- return Ok(TreeWalkResult::Skipped);+ return Ok(TreeWalkResult::Skipped(SkipReason::NotInIncludeList));}}diff --git a/crates/screenpipe-engine/src/event_driven_capture.rs b/crates/screenpipe-engine/src/event_driven_capture.rsindex c8549a944..0f278e12b 100644--- a/crates/screenpipe-engine/src/event_driven_capture.rs+++ b/crates/screenpipe-engine/src/event_driven_capture.rs@@ -631,10 +631,10 @@ async fn do_capture(use screenpipe_a11y::tree::TreeWalkResult;let tree_snapshot = match tree_walk_result {TreeWalkResult::Found(snap) => Some(snap),- TreeWalkResult::Skipped => {+ TreeWalkResult::Skipped(reason) => {warn!(- "skipping capture: window filtered (incognito/private) on monitor {}",- monitor_id+ "skipping capture: window filtered ({}) on monitor {}",+ reason, monitor_id);return Ok(CaptureOutput {result: None,diff --git a/crates/screenpipe-engine/src/paired_capture.rs b/crates/screenpipe-engine/src/paired_capture.rsindex 66753012c..a5c1b9456 100644--- a/crates/screenpipe-engine/src/paired_capture.rs+++ b/crates/screenpipe-engine/src/paired_capture.rs@@ -326,9 +326,9 @@ pub fn walk_accessibility_tree(config: &TreeWalkerConfig) -> screenpipe_a11y::tr);TreeWalkResult::Found(snapshot)}- Ok(TreeWalkResult::Skipped) => {- debug!("tree walk: window skipped (incognito/filtered)");- TreeWalkResult::Skipped+ Ok(TreeWalkResult::Skipped(reason)) => {+ debug!("tree walk: window skipped ({})", reason);+ TreeWalkResult::Skipped(reason)}Ok(TreeWalkResult::NotFound) => {debug!("tree walk: no focused window found");