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: switching overlay modes without restart or crash

Louis Beaumont510a515a8bb0
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs b/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
index 4f94d83bd..1d5731b68 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
@@ -1,7 +1,5 @@
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]
@@ -345,33 +343,19 @@ 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)
+/// Hide the Main panel so the next shortcut press reconfigures it for the new mode.
pub fn reset_main_window(app_handle: tauri::AppHandle) {
- info!("reset_main_window: destroying Main panel/window for fresh recreation");
+ info!("reset_main_window: hiding Main panel for mode switch");
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")]
{
- // Hide the panel and close the webview so the next shortcut press
- // creates a fresh window with the new mode config.
- // NOTE: do NOT call window.destroy() on an NSPanel-backed window — it
- // triggers an ObjC exception ("Rust cannot catch foreign exceptions").
- // window.close() is safe and removes the webview from Tauri's registry.
+ use tauri_nspanel::ManagerExt;
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);
}
- if let Some(window) = app_clone.get_webview_window(label) {
- let _ = window.close();
- }
});
crate::window_api::reset_to_regular_and_refresh_tray(&app_handle);
}
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/main.rs b/apps/screenpipe-app-tauri/src-tauri/src/main.rs
index e6d8d29df..7963a7155 100755
--- a/apps/screenpipe-app-tauri/src-tauri/src/main.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/main.rs
@@ -4,8 +4,6 @@
use analytics::AnalyticsManager;
use commands::show_main_window;
use serde_json::json;
-#[cfg(target_os = "macos")]
-use tauri_nspanel::ManagerExt;
use std::env;
use std::fs::File;
use std::path::PathBuf;
@@ -305,13 +303,15 @@ async fn apply_shortcuts(app: &AppHandle, config: &ShortcutConfig) -> Result<(),
let _ = app.emit("shortcut-show", ());
#[cfg(target_os = "macos")]
{
- if let Ok(window) = app.get_webview_panel("main") {
+ // Check Tauri's webview registry (not nspanel's) so that after
+ // reset_main_window closes the webview, we create a fresh one.
+ if let Some(window) = app.get_webview_window("main") {
match window.is_visible() {
- true => {
+ Ok(true) => {
info!("window is visible, hiding main window");
hide_main_window(app)
}
- false => {
+ _ => {
info!(
"window is not visible or error checking visibility, showing main window"
);
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 fcd99a2a0..e7b41960a 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/window_api.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/window_api.rs
@@ -1,6 +1,7 @@
-use std::{path::PathBuf, str::FromStr};
+use std::{path::PathBuf, str::FromStr, sync::Mutex};
use axum::{extract::State, http::StatusCode, Json};
+use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
use tauri::{AppHandle, Emitter, LogicalSize, Manager, Size, WebviewUrl, WebviewWindow, WebviewWindowBuilder, Wry};
#[cfg(target_os = "macos")]
@@ -12,6 +13,10 @@ use tauri_nspanel::WebviewWindowExt;
use crate::{store::{OnboardingStore, SettingsStore}, ServerState};
+/// Tracks the overlay mode the Main window was last created with.
+/// When the setting changes, the show path detects the mismatch and recreates.
+static MAIN_CREATED_MODE: Lazy<Mutex<Option<String>>> = Lazy::new(|| Mutex::new(None));
+
/// Reset activation policy to Regular so dock icon and tray are visible.
#[cfg(target_os = "macos")]
pub fn reset_to_regular_and_refresh_tray(app: &AppHandle) {
@@ -318,6 +323,46 @@ impl ShowRewindWindow {
.unwrap_or_default()
.overlay_mode;
+ // If mode changed since last creation, reconfigure the panel in-place
+ {
+ let mut created = MAIN_CREATED_MODE.lock().unwrap();
+ if let Some(ref prev) = *created {
+ if *prev != overlay_mode {
+ info!("overlay mode changed from {} to {}, reconfiguring panel", prev, overlay_mode);
+ *created = Some(overlay_mode.clone());
+ drop(created);
+
+ #[cfg(target_os = "macos")]
+ {
+ let mode = overlay_mode.clone();
+ let app_clone = app.clone();
+ let win = window.clone();
+ let _ = app.run_on_main_thread(move || {
+ if let Ok(panel) = app_clone.get_webview_panel(RewindWindowId::Main.label()) {
+ use tauri_nspanel::cocoa::appkit::NSWindowCollectionBehavior;
+ if mode == "window" {
+ // Switch to window mode: resize, show decorations
+ let _ = win.set_size(LogicalSize::new(1200.0, 800.0));
+ let _ = win.center();
+ // titled | closable | miniaturizable | resizable
+ panel.set_style_mask(15);
+ } else {
+ // Switch to overlay mode: borderless
+ panel.set_style_mask(0);
+ }
+ panel.set_level(1001);
+ panel.set_collection_behaviour(
+ NSWindowCollectionBehavior::NSWindowCollectionBehaviorMoveToActiveSpace |
+ NSWindowCollectionBehavior::NSWindowCollectionBehaviorFullScreenAuxiliary
+ );
+ }
+ });
+ }
+ // Don't show yet — fall through to the mode-specific show logic below
+ }
+ }
+ }
+
if overlay_mode == "window" {
// Window mode: show the panel (same mechanism as overlay)
info!("showing main window (window mode)");
@@ -507,6 +552,8 @@ impl ShowRewindWindow {
.unwrap_or_default()
.unwrap_or_default()
.overlay_mode;
+ // Record what mode we're creating so we can detect changes later
+ *MAIN_CREATED_MODE.lock().unwrap() = Some(overlay_mode.clone());
let use_window_mode = overlay_mode == "window";
if use_window_mode {