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
fix: window mode now uses NSPanel (shows above fullscreen apps)
Louis Beaumonte5a675be81c5
diff --git a/apps/screenpipe-app-tauri/components/settings/general-settings.tsx b/apps/screenpipe-app-tauri/components/settings/general-settings.tsxindex a02b302a8..e54feae84 100644--- a/apps/screenpipe-app-tauri/components/settings/general-settings.tsx+++ b/apps/screenpipe-app-tauri/components/settings/general-settings.tsx@@ -216,10 +216,10 @@ export default function GeneralSettings() {key={option.value}onClick={async () => {handleSettingsChange({ overlayMode: option.value });- // Close existing Main window so it gets recreated with the new mode+ // Destroy existing Main panel so it gets recreated with the new modetry {- const { commands } = await import("@/lib/utils/tauri");- await commands.closeWindow("Main");+ const { invoke } = await import("@tauri-apps/api/core");+ await invoke("reset_main_window");} catch (_) {}toast({title: "overlay mode updated",diff --git a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs b/apps/screenpipe-app-tauri/src-tauri/src/commands.rsindex 2dbab77bc..6ee97b830 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/commands.rs@@ -1,5 +1,7 @@use crate::{window_api::ShowRewindWindow, store::OnboardingStore, store::SettingsStore, parse_shortcut};use tauri::{Manager, Emitter};+#[cfg(target_os = "macos")]+use tauri_nspanel::ManagerExt;use tracing::{error, info, warn, debug};#[tauri::command]@@ -40,34 +42,18 @@ pub fn set_tray_health_icon(app_handle: tauri::AppHandle) {pub fn show_main_window(app_handle: &tauri::AppHandle, _overlay: bool) {info!("show_main_window called, attempting to show Main window");- let overlay_mode = crate::store::SettingsStore::get(app_handle)- .unwrap_or_default()- .unwrap_or_default()- .overlay_mode;- let is_window_mode = overlay_mode == "window";-- // In overlay mode, close Settings (transparent overlay would show Settings through)- // In window mode, no need — it's an opaque window- if !is_window_mode {- let _ = ShowRewindWindow::Settings { page: None }.close(app_handle);- }+ // Close Settings window if open (transparent overlay would show it through)+ let _ = ShowRewindWindow::Settings { page: None }.close(app_handle);match ShowRewindWindow::Main.show(app_handle) {Ok(window) => {info!("ShowRewindWindow::Main.show succeeded, window label: {}", window.label());-- if is_window_mode {- // Window mode: focus the window on all platforms including macOS- if let Err(e) = window.set_focus() {- error!("Failed to set focus on main window: {}", e);- }- } else {- // Overlay mode: Don't call set_focus() on macOS as it causes space switching- // The panel's order_front_regardless() already handles visibility- #[cfg(not(target_os = "macos"))]- if let Err(e) = window.set_focus() {- error!("Failed to set focus on main window: {}", e);- }+ // Don't call set_focus() on macOS — both overlay and window modes use+ // NSPanel with order_front_regardless() which handles visibility correctly.+ // Calling set_focus() causes macOS space switching.+ #[cfg(not(target_os = "macos"))]+ if let Err(e) = window.set_focus() {+ error!("Failed to set focus on main window: {}", e);}// Register window-specific shortcuts (Escape, Ctrl+Cmd+K) on a separate task@@ -357,6 +343,45 @@ pub async fn close_window(}// Permission recovery command+#[tauri::command]+#[specta::specta]+/// Destroy the Main window/panel so it gets recreated fresh (e.g. after switching overlay mode)+pub fn reset_main_window(app_handle: tauri::AppHandle) {+ info!("reset_main_window: destroying Main panel/window for fresh recreation");+ let label = crate::window_api::RewindWindowId::Main.label();++ // Unregister shortcuts+ let app_clone = app_handle.clone();+ std::thread::spawn(move || {+ std::thread::sleep(std::time::Duration::from_millis(10));+ let _ = unregister_window_shortcuts(app_clone);+ });++ #[cfg(target_os = "macos")]+ {+ // Try panel first, then regular window+ let app_clone = app_handle.clone();+ let _ = app_handle.run_on_main_thread(move || {+ if let Ok(panel) = app_clone.get_webview_panel(label) {+ panel.order_out(None);+ // Released when closed+ panel.released_when_closed(true);+ }+ if let Some(window) = app_clone.get_webview_window(label) {+ let _ = window.destroy();+ }+ });+ crate::window_api::reset_to_regular_and_refresh_tray(&app_handle);+ }++ #[cfg(not(target_os = "macos"))]+ {+ if let Some(window) = app_handle.get_webview_window(label) {+ let _ = window.destroy();+ }+ }+}+#[tauri::command]#[specta::specta]pub async fn show_permission_recovery_window(app_handle: tauri::AppHandle) -> Result<(), String> {diff --git a/apps/screenpipe-app-tauri/src-tauri/src/main.rs b/apps/screenpipe-app-tauri/src-tauri/src/main.rsindex fb5ccf51e..5b97ff522 100755--- a/apps/screenpipe-app-tauri/src-tauri/src/main.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/main.rs@@ -945,6 +945,7 @@ async fn main() {commands::update_show_screenpipe_shortcut,commands::show_window,commands::close_window,+ commands::reset_main_window,commands::set_window_size,// Onboarding commandscommands::get_onboarding_status,@@ -1084,6 +1085,7 @@ async fn main() {commands::open_pipe_window,commands::show_window,commands::close_window,+ commands::reset_main_window,commands::set_window_size,// Permission recovery commandscommands::show_permission_recovery_window,@@ -1626,17 +1628,8 @@ async fn main() {if let Ok(window_id) = RewindWindowId::from_str(label.as_str()) {match window_id {RewindWindowId::Settings => {- // In overlay mode, closing Settings also cleans up the transparent- // overlay panel. In window mode, Main is a normal window — keep it.- let overlay_mode = crate::store::SettingsStore::get(&app_handle)- .unwrap_or_default()- .unwrap_or_default()- .overlay_mode;- if overlay_mode != "window" {- if let Some(window) = RewindWindowId::Main.get(&app_handle) {- let _ = window.destroy();- }- }+ // Closing Settings hides the Main panel (it's always a panel now)+ let _ = ShowRewindWindow::Main.close(&app_handle);return;}diff --git a/apps/screenpipe-app-tauri/src-tauri/src/window_api.rs b/apps/screenpipe-app-tauri/src-tauri/src/window_api.rsindex 59d55f9de..9df7340c4 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/window_api.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/window_api.rs@@ -319,36 +319,30 @@ impl ShowRewindWindow {.overlay_mode;if overlay_mode == "window" {- // Window mode: show and focus the normal window+ // Window mode: show the panel (same mechanism as overlay)info!("showing main window (window mode)");- window.show().ok();-#[cfg(target_os = "macos")]{- // Activate the app and bring window to front on the current space- use objc::{msg_send, sel, sel_impl};- use tauri_nspanel::cocoa::base::{id, nil};let app_clone = app.clone();- let _ = app.run_on_main_thread(move || {- unsafe {- let ns_app: id = msg_send![objc::class!(NSApplication), sharedApplication];- // activateIgnoringOtherApps brings our app to front- let _: () = msg_send![ns_app, activateIgnoringOtherApps: true];- }- // Also use Tauri's set_focus for good measure- if let Some(w) = RewindWindowId::Main.get(&app_clone) {- w.set_focus().ok();+ app.run_on_main_thread(move || {+ if let Ok(panel) = app_clone.get_webview_panel(RewindWindowId::Main.label()) {+ use tauri_nspanel::cocoa::appkit::NSWindowCollectionBehavior;+ panel.set_level(1001);+ panel.set_collection_behaviour(+ NSWindowCollectionBehavior::NSWindowCollectionBehaviorCanJoinAllSpaces |+ NSWindowCollectionBehavior::NSWindowCollectionBehaviorFullScreenAuxiliary+ );+ panel.order_front_regardless();+ let _ = app_clone.emit("window-focused", true);}- let _ = app_clone.emit("window-focused", true);- });+ }).ok();}-#[cfg(not(target_os = "macos"))]{+ window.show().ok();window.set_focus().ok();let _ = app.emit("window-focused", true);}-return Ok(window);}@@ -518,40 +512,109 @@ impl ShowRewindWindow {if use_window_mode {// ============================================================- // Window mode: normal resizable window with title bar- // Created hidden — shown after webview loads to avoid black flash.+ // Window mode: NSPanel at normal size (not fullscreen).+ // Still uses NSPanel so it can appear above fullscreen apps.+ // Created hidden — shown after webview + panel setup.// ============================================================- let app_clone = app.clone();- let builder = self.window_builder(app, "/")- .title("screenpipe")- .inner_size(1200.0, 800.0)- .min_inner_size(800.0, 600.0)- .decorations(true)- .visible(false) // hidden until content loads- .focused(false)- .transparent(false)- .visible_on_all_workspaces(true)- .on_page_load(move |win, payload| {- if matches!(payload.event(), tauri::webview::PageLoadEvent::Finished) {- win.show().ok();- win.set_focus().ok();- #[cfg(target_os = "macos")]- {++ #[cfg(target_os = "macos")]+ let window = {+ let app_clone = app.clone();+ let builder = self.window_builder(app, "/")+ .title("screenpipe")+ .inner_size(1200.0, 800.0)+ .min_inner_size(800.0, 600.0)+ .decorations(true)+ .visible(false)+ .focused(false)+ .transparent(false)+ .visible_on_all_workspaces(true)+ .on_page_load(move |win, payload| {+ if matches!(payload.event(), tauri::webview::PageLoadEvent::Finished) {+ // Panel setup already done — just show & activate+ win.show().ok();+ win.set_focus().ok();use objc::{msg_send, sel, sel_impl};use tauri_nspanel::cocoa::base::id;unsafe {let ns_app: id = msg_send![objc::class!(NSApplication), sharedApplication];let _: () = msg_send![ns_app, activateIgnoringOtherApps: true];}+ let _ = app_clone.emit("window-focused", true);}- let _ = app_clone.emit("window-focused", true);- }- });+ });+ builder.build()?+ };++ // Windows/Linux: normal window+ #[cfg(not(target_os = "macos"))]+ let window = {+ let app_clone = app.clone();+ let builder = self.window_builder(app, "/")+ .title("screenpipe")+ .inner_size(1200.0, 800.0)+ .min_inner_size(800.0, 600.0)+ .decorations(true)+ .visible(false)+ .focused(false)+ .transparent(false)+ .on_page_load(move |win, payload| {+ if matches!(payload.event(), tauri::webview::PageLoadEvent::Finished) {+ win.show().ok();+ win.set_focus().ok();+ let _ = app_clone.emit("window-focused", true);+ }+ });+ builder.build()?+ };++ // Convert to NSPanel on macOS (same as overlay) so it+ // can appear above fullscreen apps#[cfg(target_os = "macos")]- let builder = builder- .hidden_title(false)- .title_bar_style(tauri::TitleBarStyle::Visible);- let window = builder.build()?;+ {+ if let Ok(_panel) = window.to_panel() {+ info!("Converted window-mode main to panel");+ let window_clone = window.clone();+ app.run_on_main_thread(move || {+ use tauri_nspanel::cocoa::appkit::NSWindowCollectionBehavior;+ use objc::{msg_send, sel, sel_impl};++ if let Ok(panel) = window_clone.to_panel() {+ // Same level as overlay — above fullscreen+ panel.set_level(1001);+ panel.released_when_closed(true);+ // Keep decorations! Don't call set_style_mask(0)+ // Enable dragging by title bar (normal window behavior)+ let _: () = unsafe { msg_send![&*panel, setMovableByWindowBackground: false] };+ // Exclude from screen capture+ let _: () = unsafe { msg_send![&*panel, setSharingType: 0_u64] };+ panel.set_collection_behaviour(+ NSWindowCollectionBehavior::NSWindowCollectionBehaviorCanJoinAllSpaces |+ NSWindowCollectionBehavior::NSWindowCollectionBehaviorFullScreenAuxiliary+ );+ }+ }).ok();+ }+ }++ // Auto-hide on focus loss + handle display changes+ let app_clone = app.clone();+ let window_clone = window.clone();+ window.on_window_event(move |event| {+ match event {+ tauri::WindowEvent::Focused(is_focused) => {+ if !is_focused {+ info!("Window-mode main lost focus, hiding");+ #[cfg(target_os = "macos")]+ reset_to_regular_and_refresh_tray(&app_clone);+ let _ = app_clone.emit("window-focused", false);+ } else {+ let _ = app_clone.emit("window-focused", true);+ }+ }+ _ => {}+ }+ });return Ok(window);}@@ -834,7 +897,6 @@ impl ShowRewindWindow {.min_inner_size(400.0, 500.0).focused(true).always_on_top(true)- .visible_on_all_workspaces(true).hidden_title(true);let window = builder.build()?;@@ -858,7 +920,7 @@ impl ShowRewindWindow {let _: () = unsafe { msg_send![&*panel, setSharingType: 0_u64] };panel.set_collection_behaviour(- NSWindowCollectionBehavior::NSWindowCollectionBehaviorCanJoinAllSpaces |+ NSWindowCollectionBehavior::NSWindowCollectionBehaviorMoveToActiveSpace |NSWindowCollectionBehavior::NSWindowCollectionBehaviorFullScreenAuxiliary);@@ -937,23 +999,9 @@ impl ShowRewindWindow {pub fn close(&self, app: &AppHandle) -> tauri::Result<()> {let id = self.id();if id.label() == RewindWindowId::Main.label() {- // Check overlay mode to decide close behavior- let overlay_mode = SettingsStore::get(app)- .unwrap_or_default()- .unwrap_or_default()- .overlay_mode;-- if overlay_mode == "window" {- // Window mode: destroy the window so it gets recreated fresh- if let Some(window) = id.get(app) {- window.destroy().ok();- }- return Ok(());- }-- // Overlay mode: hide the panel (keep it alive for fast re-show)#[cfg(target_os = "macos")]{+ // Try to hide the panel (works for both overlay and window-mode panels)let app_clone = app.clone();app.run_on_main_thread(move || {if let Ok(panel) = app_clone.get_webview_panel(RewindWindowId::Main.label()) {@@ -961,16 +1009,14 @@ impl ShowRewindWindow {}}).ok();- // Reset to Regular activation policy when hiding the panel- // so other windows (like Settings) work normallyreset_to_regular_and_refresh_tray(app);}#[cfg(not(target_os = "macos"))]{- if let Some(window) = id.get(app) {- window.close().ok();- }+ if let Some(window) = id.get(app) {+ window.close().ok();+ }}return Ok(());diff --git a/crates/screenpipe-vision/src/capture_screenshot_by_window.rs b/crates/screenpipe-vision/src/capture_screenshot_by_window.rsindex ee9cd6f63..c5f315921 100644--- a/crates/screenpipe-vision/src/capture_screenshot_by_window.rs+++ b/crates/screenpipe-vision/src/capture_screenshot_by_window.rs@@ -23,6 +23,9 @@ use crate::monitor::SafeMonitor;use crate::monitor::macos_version::use_sck_rs;use url::Url;+#[cfg(target_os = "macos")]+use std::collections::HashMap;+const BROWSER_NAMES: [&str; 9] = ["chrome", "firefox", "safari", "edge", "brave", "arc", "chromium", "vivaldi", "opera",];@@ -373,6 +376,72 @@ struct WindowData {image_buffer: image::RgbaImage,}+/// Build a map of window_id -> kCGWindowLayer for all on-screen windows.+/// Normal app windows have layer 0; floating panels, overlays, status items+/// and always-on-top windows have layer > 0.+#[cfg(target_os = "macos")]+fn get_window_levels() -> HashMap<u32, i32> {+ use core_foundation::base::TCFType;+ use core_foundation::number::CFNumber;+ use core_foundation::string::CFString;+ use core_graphics::window::{+ copy_window_info, kCGWindowListOptionOnScreenOnly, kCGWindowListExcludeDesktopElements,+ kCGNullWindowID,+ };++ let mut levels = HashMap::new();++ let options = kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements;+ if let Some(window_list) = copy_window_info(options, kCGNullWindowID) {+ let count = unsafe { core_foundation::array::CFArrayGetCount(window_list.as_concrete_TypeRef()) };+ for i in 0..count {+ unsafe {+ let dict_ref = core_foundation::array::CFArrayGetValueAtIndex(+ window_list.as_concrete_TypeRef(),+ i,+ );+ if dict_ref.is_null() {+ continue;+ }+ let dict = dict_ref as core_foundation::dictionary::CFDictionaryRef;++ // Get kCGWindowNumber+ let num_key = CFString::new("kCGWindowNumber");+ let mut value = std::ptr::null();+ if core_foundation::dictionary::CFDictionaryGetValueIfPresent(+ dict,+ num_key.as_concrete_TypeRef() as *const _,+ &mut value,+ ) != 0 && !value.is_null()+ {+ let cf_num =+ CFNumber::wrap_under_get_rule(value as core_foundation::number::CFNumberRef);+ if let Some(window_id) = cf_num.to_i64() {+ // Get kCGWindowLayer+ let layer_key = CFString::new("kCGWindowLayer");+ let mut layer_value = std::ptr::null();+ if core_foundation::dictionary::CFDictionaryGetValueIfPresent(+ dict,+ layer_key.as_concrete_TypeRef() as *const _,+ &mut layer_value,+ ) != 0 && !layer_value.is_null()+ {+ let layer_num = CFNumber::wrap_under_get_rule(+ layer_value as core_foundation::number::CFNumberRef,+ );+ if let Some(layer) = layer_num.to_i64() {+ levels.insert(window_id as u32, layer as i32);+ }+ }+ }+ }+ }+ }+ }++ levels+}+/// Get all visible windows using the appropriate backend#[cfg(target_os = "macos")]fn get_all_windows() -> Result<Vec<WindowData>, Box<dyn Error>> {@@ -589,6 +658,83 @@ pub async fn capture_all_visible_windows(return Err(Box::new(CaptureError::NoWindows));}+ // On macOS, detect overlay-only apps (all windows at layer > 0) so we can+ // demote them from "focused" status. Apps like Wispr Flow have always-on-top+ // overlay windows that macOS reports as the "active application", polluting+ // capture data. Normal app windows are at layer 0; floating panels, status+ // items, and overlays are at layer > 0.+ #[cfg(target_os = "macos")]+ let overlay_pids: HashSet<u32> = {+ let mut pid_layers: HashMap<u32, Vec<i32>> = HashMap::new();+ use core_foundation::base::TCFType;+ use core_foundation::number::CFNumber;+ use core_foundation::string::CFString;+ use core_graphics::window::{+ copy_window_info, kCGNullWindowID, kCGWindowListExcludeDesktopElements,+ kCGWindowListOptionOnScreenOnly,+ };+ let options = kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements;+ if let Some(window_list) = copy_window_info(options, kCGNullWindowID) {+ let count = unsafe {+ core_foundation::array::CFArrayGetCount(window_list.as_concrete_TypeRef())+ };+ for i in 0..count {+ unsafe {+ let dict_ref = core_foundation::array::CFArrayGetValueAtIndex(+ window_list.as_concrete_TypeRef(),+ i,+ );+ if dict_ref.is_null() {+ continue;+ }+ let dict = dict_ref as core_foundation::dictionary::CFDictionaryRef;++ let pid_key = CFString::new("kCGWindowOwnerPID");+ let mut pid_val = std::ptr::null();+ if !core_foundation::dictionary::CFDictionaryGetValueIfPresent(+ dict,+ pid_key.as_concrete_TypeRef() as *const _,+ &mut pid_val,+ ) || pid_val.is_null()+ {+ continue;+ }+ let pid_num = CFNumber::wrap_under_get_rule(+ pid_val as core_foundation::number::CFNumberRef,+ );+ let Some(w_pid) = pid_num.to_i64() else {+ continue;+ };++ let layer_key = CFString::new("kCGWindowLayer");+ let mut layer_val = std::ptr::null();+ if core_foundation::dictionary::CFDictionaryGetValueIfPresent(+ dict,+ layer_key.as_concrete_TypeRef() as *const _,+ &mut layer_val,+ ) && !layer_val.is_null()+ {+ let layer_num = CFNumber::wrap_under_get_rule(+ layer_val as core_foundation::number::CFNumberRef,+ );+ if let Some(layer) = layer_num.to_i64() {+ pid_layers+ .entry(w_pid as u32)+ .or_default()+ .push(layer as i32);+ }+ }+ }+ }+ }+ // PIDs where ALL on-screen windows are overlay-level (layer > 0)+ pid_layers+ .into_iter()+ .filter(|(_, layers)| !layers.is_empty() && layers.iter().all(|&l| l > 0))+ .map(|(pid, _)| pid)+ .collect()+ };+// Process the captured datafor window_data in windows_data {let WindowData {@@ -603,6 +749,20 @@ pub async fn capture_all_visible_windows(image_buffer,} = window_data;+ // On macOS, demote overlay-only apps from "focused" status.+ // If an app has ONLY overlay-level windows (all kCGWindowLayer > 0),+ // it's a floating overlay like Wispr Flow — don't treat as focused.+ #[cfg(target_os = "macos")]+ let is_focused = if is_focused && overlay_pids.contains(&(process_id as u32)) {+ debug!(+ "Demoting overlay app '{}' ('{}') from focused - all windows are layer > 0",+ app_name, window_name+ );+ false+ } else {+ is_focused+ };+// Convert to DynamicImagelet image = DynamicImage::ImageRgba8(image_buffer);