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: shortcut reminder + chat visible on all Spaces, prevent space monitor race

Louis Beaumontb6aa5c287f10
diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
index 0e2f56fb3..c5826c2bf 100755
--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
@@ -5514,6 +5514,54 @@ dependencies = [
"libc",
]
+[[package]]
+name = "libpulse-binding"
+version = "2.30.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "909eb3049e16e373680fe65afe6e2a722ace06b671250cc4849557bc57d6a397"
+dependencies = [
+ "bitflags 2.10.0",
+ "libc",
+ "libpulse-sys",
+ "num-derive",
+ "num-traits",
+ "winapi",
+]
+
+[[package]]
+name = "libpulse-simple-binding"
+version = "2.29.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b7bebef0381c8e3e4b23cc24aaf36fab37472bece128de96f6a111efa464cfef"
+dependencies = [
+ "libpulse-binding",
+ "libpulse-simple-sys",
+ "libpulse-sys",
+]
+
+[[package]]
+name = "libpulse-simple-sys"
+version = "1.22.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3bd96888fe37ad270d16abf5e82cccca1424871cf6afa2861824d2a52758eebc"
+dependencies = [
+ "libpulse-sys",
+ "pkg-config",
+]
+
+[[package]]
+name = "libpulse-sys"
+version = "1.23.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d74371848b22e989f829cc1621d2ebd74960711557d8b45cfe740f60d0a05e61"
+dependencies = [
+ "libc",
+ "num-derive",
+ "num-traits",
+ "pkg-config",
+ "winapi",
+]
+
[[package]]
name = "libredox"
version = "0.1.12"
@@ -9048,7 +9096,7 @@ dependencies = [
[[package]]
name = "screenpipe-app"
-version = "2.0.371"
+version = "2.0.374"
dependencies = [
"anyhow",
"async-stream",
@@ -9161,6 +9209,8 @@ dependencies = [
"hound",
"knf-rs",
"lazy_static",
+ "libpulse-binding",
+ "libpulse-simple-binding",
"libsamplerate-sys",
"log",
"ndarray 0.16.1",
@@ -13189,6 +13239,7 @@ name = "whisper-rs"
version = "0.15.1"
source = "git+https://codeberg.org/tazz4843/whisper-rs.git?rev=d38738df8dc54b12d2918494586ba0817c3cb12f#d38738df8dc54b12d2918494586ba0817c3cb12f"
dependencies = [
+ "libc",
"tracing",
"whisper-rs-sys",
]
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs b/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
index 61d7ae3e6..3619673e8 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
@@ -644,14 +644,16 @@ pub async fn show_shortcut_reminder(
// Exclude from screen capture (NSWindowSharingNone = 0)
let _: () = unsafe { msg_send![&*panel, setSharingType: 0_u64] };
+ // CanJoinAllSpaces: visible on ALL Spaces simultaneously
+ // (not MoveToActiveSpace which only follows the active Space)
panel.set_collection_behaviour(
- NSWindowCollectionBehavior::NSWindowCollectionBehaviorMoveToActiveSpace |
+ NSWindowCollectionBehavior::NSWindowCollectionBehaviorCanJoinAllSpaces |
NSWindowCollectionBehavior::NSWindowCollectionBehaviorIgnoresCycle |
NSWindowCollectionBehavior::NSWindowCollectionBehaviorFullScreenAuxiliary
);
// Order front regardless to show above fullscreen
panel.order_front_regardless();
- info!("Panel configured for fullscreen support");
+ info!("Panel configured for all-Spaces fullscreen support");
} else {
error!("Failed to get panel in main thread");
}
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 7a5165d89..67b2d4e2d 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/space_monitor.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/space_monitor.rs
@@ -2,11 +2,45 @@
//!
//! Listens for NSWorkspaceActiveSpaceDidChangeNotification to detect when
//! the user switches Spaces (virtual desktops) and hides the overlay.
+//!
+//! The suppress mechanism prevents a race condition: when we call
+//! `activateIgnoringOtherApps` to show a panel on a fullscreen Space,
+//! macOS fires a Space change notification. Without suppression, the
+//! space monitor would immediately hide the window we just showed.
use crate::commands::hide_main_window;
+use std::sync::atomic::{AtomicU64, Ordering};
use tauri::AppHandle;
use tracing::{debug, error};
+/// Timestamp (ms since UNIX epoch) until which Space change notifications
+/// should be ignored. Set by `suppress_space_monitor()` before activating.
+static SUPPRESS_UNTIL: AtomicU64 = AtomicU64::new(0);
+
+/// Call before `activateIgnoringOtherApps` to prevent the space monitor
+/// from hiding the overlay during the activation-triggered Space change.
+/// Suppresses for `duration_ms` milliseconds (default 500ms is plenty).
+pub fn suppress_space_monitor(duration_ms: u64) {
+ let now = std::time::SystemTime::now()
+ .duration_since(std::time::UNIX_EPOCH)
+ .unwrap_or_default()
+ .as_millis() as u64;
+ SUPPRESS_UNTIL.store(now + duration_ms, Ordering::Relaxed);
+ debug!("space monitor suppressed for {}ms", duration_ms);
+}
+
+fn is_suppressed() -> bool {
+ let until = SUPPRESS_UNTIL.load(Ordering::Relaxed);
+ if until == 0 {
+ return false;
+ }
+ let now = std::time::SystemTime::now()
+ .duration_since(std::time::UNIX_EPOCH)
+ .unwrap_or_default()
+ .as_millis() as u64;
+ now < until
+}
+
/// Sets up a listener for macOS Space changes.
/// When the active Space changes, hides the main overlay window.
pub fn setup_space_listener(app: AppHandle) {
@@ -35,6 +69,11 @@ pub fn setup_space_listener(app: AppHandle) {
// Create the block that will be called when space changes
let block = block::ConcreteBlock::new(move |_notification: id| {
+ // Ignore Space changes triggered by our own activateIgnoringOtherApps
+ if is_suppressed() {
+ debug!("macOS Space changed, but suppressed (self-activation)");
+ 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
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 d435bce5e..6d6c4c5c7 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/window_api.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/window_api.rs
@@ -444,6 +444,7 @@ impl ShowRewindWindow {
}
panel.make_first_responder(Some(panel.content_view()));
panel.order_front_regardless();
+ crate::space_monitor::suppress_space_monitor(500);
unsafe {
use tauri_nspanel::cocoa::base::id;
let ns_app: id = msg_send![objc::class!(NSApplication), sharedApplication];
@@ -527,6 +528,7 @@ impl ShowRewindWindow {
panel.order_front_regardless();
// Activate app so WKWebView receives keyboard input,
// then make panel key window.
+ crate::space_monitor::suppress_space_monitor(500);
unsafe {
let ns_app: id = msg_send![objc::class!(NSApplication), sharedApplication];
let _: () = msg_send![ns_app, activateIgnoringOtherApps: true];
@@ -642,6 +644,7 @@ impl ShowRewindWindow {
);
// Activate so the chat panel appears on the current
// fullscreen Space and receives keyboard input.
+ crate::space_monitor::suppress_space_monitor(500);
unsafe {
use tauri_nspanel::cocoa::base::id;
let ns_app: id = msg_send![objc::class!(NSApplication), sharedApplication];
@@ -649,6 +652,12 @@ impl ShowRewindWindow {
}
panel.order_front_regardless();
panel.make_key_window();
+ // Remove MoveToActiveSpace now that the panel is shown.
+ // Keeps it pinned to THIS Space so it won't follow
+ // three-finger swipes (same pattern as main overlay).
+ panel.set_collection_behaviour(
+ NSWindowCollectionBehavior::NSWindowCollectionBehaviorFullScreenAuxiliary
+ );
}
});
@@ -762,6 +771,7 @@ impl ShowRewindWindow {
NSWindowCollectionBehavior::NSWindowCollectionBehaviorFullScreenAuxiliary
);
// Activate + show on correct Space (same as overlay/chat)
+ crate::space_monitor::suppress_space_monitor(500);
unsafe {
use tauri_nspanel::cocoa::base::id;
let ns_app: id = msg_send![objc::class!(NSApplication), sharedApplication];
@@ -1237,6 +1247,7 @@ impl ShowRewindWindow {
// Activate THEN show — same pattern as the fullscreen
// overlay's show_existing_main. This places the panel
// on the current fullscreen Space without Accessory mode.
+ crate::space_monitor::suppress_space_monitor(500);
unsafe {
use tauri_nspanel::cocoa::base::id;
let ns_app: id = msg_send![objc::class!(NSApplication), sharedApplication];
@@ -1244,6 +1255,13 @@ impl ShowRewindWindow {
}
panel.order_front_regardless();
panel.make_key_window();
+
+ // Remove MoveToActiveSpace now that the panel is shown.
+ // Keeps it pinned to THIS Space so it won't follow
+ // three-finger swipes (same pattern as main overlay).
+ panel.set_collection_behaviour(
+ NSWindowCollectionBehavior::NSWindowCollectionBehaviorFullScreenAuxiliary
+ );
}
});
}