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): exclude screenpipe overlays from screen capture (#2147)

Louis Beaumontdca1c4737501
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs b/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
index 9d4c902dd..eb1934739 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
@@ -515,9 +515,15 @@ pub async fn show_shortcut_reminder(
// Use to_panel() on window_clone directly instead of get_webview_panel
// This avoids race conditions with panel registration
if let Ok(panel) = window_clone.to_panel() {
+ use objc::{msg_send, sel, sel_impl};
+
// Level 1001 = above CGShieldingWindowLevel, shows over fullscreen
panel.set_level(1001);
panel.set_style_mask(0);
+
+ // Exclude from screen capture (NSWindowSharingNone = 0)
+ let _: () = unsafe { msg_send![&*panel, setSharingType: 0_u64] };
+
panel.set_collection_behaviour(
NSWindowCollectionBehavior::NSWindowCollectionBehaviorCanJoinAllSpaces |
NSWindowCollectionBehavior::NSWindowCollectionBehaviorIgnoresCycle |
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 f69a3c4c9..564d726aa 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/window_api.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/window_api.rs
@@ -619,6 +619,10 @@ impl ShowRewindWindow {
// Disable window dragging by clicking on background
let _: () = unsafe { msg_send![&*panel, setMovableByWindowBackground: false] };
+ // Exclude from screen capture so the overlay doesn't appear
+ // in screenshots of other apps (NSWindowSharingNone = 0)
+ let _: () = unsafe { msg_send![&*panel, setSharingType: 0_u64] };
+
panel.set_collection_behaviour(
NSWindowCollectionBehavior::NSWindowCollectionBehaviorCanJoinAllSpaces |
NSWindowCollectionBehavior::NSWindowCollectionBehaviorIgnoresCycle |
@@ -736,6 +740,9 @@ impl ShowRewindWindow {
// Enable dragging by clicking anywhere on the window background
let _: () = unsafe { msg_send![&*panel, setMovableByWindowBackground: true] };
+ // Exclude from screen capture (NSWindowSharingNone = 0)
+ let _: () = unsafe { msg_send![&*panel, setSharingType: 0_u64] };
+
panel.set_collection_behaviour(
NSWindowCollectionBehavior::NSWindowCollectionBehaviorCanJoinAllSpaces |
NSWindowCollectionBehavior::NSWindowCollectionBehaviorFullScreenAuxiliary
@@ -784,6 +791,20 @@ impl ShowRewindWindow {
#[cfg(target_os = "macos")]
let builder = builder.hidden_title(true);
let window = builder.build()?;
+
+ // Exclude from screen capture (NSWindowSharingNone = 0)
+ #[cfg(target_os = "macos")]
+ {
+ use raw_window_handle::HasWindowHandle;
+ if let Ok(handle) = window.window_handle() {
+ if let raw_window_handle::RawWindowHandle::AppKit(appkit_handle) = handle.as_raw() {
+ use objc::{msg_send, sel, sel_impl};
+ let ns_window = appkit_handle.ns_window.as_ptr() as *mut objc::runtime::Object;
+ let _: () = unsafe { msg_send![ns_window, setSharingType: 0_u64] };
+ }
+ }
+ }
+
window
}
};
diff --git a/crates/screenpipe-db/src/db.rs b/crates/screenpipe-db/src/db.rs
index 8ee604379..9875bd031 100644
--- a/crates/screenpipe-db/src/db.rs
+++ b/crates/screenpipe-db/src/db.rs
@@ -3,7 +3,7 @@ use image::DynamicImage;
use libsqlite3_sys::sqlite3_auto_extension;
use sqlite_vec::sqlite3_vec_init;
use sqlx::migrate::MigrateDatabase;
-use sqlx::sqlite::{SqlitePool, SqlitePoolOptions};
+use sqlx::sqlite::{SqliteConnectOptions, SqlitePool, SqlitePoolOptions};
use sqlx::Column;
use sqlx::Error as SqlxError;
use sqlx::Row;
@@ -60,36 +60,22 @@ impl DatabaseManager {
sqlx::Sqlite::create_database(&connection_string).await?;
}
+ let connect_options: SqliteConnectOptions = connection_string
+ .parse::<SqliteConnectOptions>()?
+ // busy_timeout is per-connection; setting it here ensures ALL pooled
+ // connections wait before returning SQLITE_BUSY ("database is locked").
+ .busy_timeout(Duration::from_secs(10))
+ .pragma("journal_mode", "WAL")
+ .pragma("cache_size", "-64000") // 64 MB page cache
+ .pragma("mmap_size", "268435456") // 256 MB memory-mapped I/O
+ .pragma("temp_store", "MEMORY");
+
let pool = SqlitePoolOptions::new()
// SQLite only allows a single writer; keep the pool modest to reduce write contention.
.max_connections(10)
.min_connections(3) // Minimum number of idle connections
.acquire_timeout(Duration::from_secs(10))
- .connect(&connection_string)
- .await?;
-
- // Enable WAL mode
- sqlx::query("PRAGMA journal_mode = WAL;")
- .execute(&pool)
- .await?;
-
- // Give writers time to wait for the lock instead of failing immediately.
- sqlx::query("PRAGMA busy_timeout = 5000;")
- .execute(&pool)
- .await?;
-
- // Optimize SQLite for search performance
- // cache_size: -64000 = 64MB page cache (negative = KB)
- // mmap_size: 256MB memory-mapped I/O for faster reads
- // temp_store: keep temp tables in memory
- sqlx::query("PRAGMA cache_size = -64000;")
- .execute(&pool)
- .await?;
- sqlx::query("PRAGMA mmap_size = 268435456;")
- .execute(&pool)
- .await?;
- sqlx::query("PRAGMA temp_store = MEMORY;")
- .execute(&pool)
+ .connect_with(connect_options)
.await?;
let db_manager = DatabaseManager { pool };