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(windows): migrate timeline mode and verify escape (#6063)
Ezra Ellette8d27c1d69f46
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs b/apps/screenpipe-app-tauri/src-tauri/src/commands.rsindex ebff7e3dc..2a8116703 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/commands.rs@@ -3735,6 +3735,10 @@ pub async fn hide_notification_panel(app_handle: tauri::AppHandle) -> Result<(),#[tauri::command]#[specta::specta]pub fn register_window_shortcuts(app_handle: tauri::AppHandle) -> Result<(), String> {+ register_window_shortcuts_with_generation(app_handle).map(|_| ())+}++fn register_window_shortcuts_inner(app_handle: tauri::AppHandle) -> Result<(), String> {use tauri::Emitter;use tauri_plugin_global_shortcut::{Code, GlobalShortcutExt, Shortcut, ShortcutState};@@ -3743,40 +3747,50 @@ pub fn register_window_shortcuts(app_handle: tauri::AppHandle) -> Result<(), Str// Register Escape shortcut — emits event so frontend can decide// whether to collapse compact mode or fully close the windowlet escape_shortcut = Shortcut::new(None, Code::Escape);- if let Err(e) = global_shortcut.on_shortcut(escape_shortcut, |app, _, event| {- if matches!(event.state, ShortcutState::Pressed) {- if let Err(e) = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {- info!("Escape pressed, emitting escape-pressed event");- // Target the Main overlay webview explicitly. `app.emit` can be- // delivered only to the focused Tauri window; when Home stays- // focused while the fullscreen overlay is visible on top, the- // overlay never saw escape-pressed (and no keydown reaches it),- // so Esc looked broken until a focus change re-routed events.- let mut delivered = false;- for label in [RewindWindowId::Main.label(), "main-window"] {- if let Some(w) = app.get_webview_window(label) {- if w.is_visible().unwrap_or(false) {- let _ = app.emit_to(label, "escape-pressed", ());- delivered = true;- break;+ if global_shortcut.is_registered(escape_shortcut) {+ info!("Window-specific shortcut already registered and verified (Escape)");+ return Ok(());+ }++ global_shortcut+ .on_shortcut(escape_shortcut, |app, _, event| {+ if matches!(event.state, ShortcutState::Pressed) {+ if let Err(e) = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {+ info!("Escape pressed, emitting escape-pressed event");+ // Target the Main overlay webview explicitly. `app.emit` can be+ // delivered only to the focused Tauri window; when Home stays+ // focused while the fullscreen overlay is visible on top, the+ // overlay never saw escape-pressed (and no keydown reaches it),+ // so Esc looked broken until a focus change re-routed events.+ let mut delivered = false;+ for label in [RewindWindowId::Main.label(), "main-window"] {+ if let Some(w) = app.get_webview_window(label) {+ if w.is_visible().unwrap_or(false) {+ let _ = app.emit_to(label, "escape-pressed", ());+ delivered = true;+ break;+ }}}+ if !delivered {+ let _ = app.emit("escape-pressed", ());+ }+ })) {+ tracing::error!("panic in escape handler: {:?}", e);}- if !delivered {- let _ = app.emit("escape-pressed", ());- }- })) {- tracing::error!("panic in escape handler: {:?}", e);}- }- }) {- // Ignore "already registered" / duplicate registration errors.- // macOS Carbon API returns "RegisterEventHotKey failed" (not "already- // registered") when the hotkey is already active, so check both.- let msg = e.to_string();- if !msg.contains("already registered") && !msg.contains("RegisterEventHotKey failed") {- error!("Failed to register Escape shortcut: {}", e);- }+ })+ .map_err(|e| {+ let message = format!("Failed to register Escape shortcut: {e}");+ error!("{}", message);+ message+ })?;++ if !global_shortcut.is_registered(escape_shortcut) {+ let message =+ "Escape shortcut registration returned success but was not retained".to_string();+ error!("{}", message);+ return Err(message);}// NOTE: Search shortcut (Ctrl+Cmd+K) is registered ONLY as a global shortcut@@ -3784,7 +3798,7 @@ pub fn register_window_shortcuts(app_handle: tauri::AppHandle) -> Result<(), Str// Having it in both places caused it to be unregistered globally when the window// closed, breaking Ctrl+Cmd+K entirely until app restart.- info!("Window-specific shortcuts registered (Escape)");+ info!("Window-specific shortcut registered and verified (Escape)");Ok(())}@@ -3820,11 +3834,21 @@ pub fn unregister_window_shortcuts(app_handle: tauri::AppHandle) -> Result<(), Spub(crate) fn register_window_shortcuts_with_generation(app_handle: tauri::AppHandle,) -> Result<u64, String> {- register_window_shortcuts(app_handle.clone())?;+ // Invalidate delayed unregister work before touching the native hotkey.+ // Bumping afterward leaves a race where an old blur/close task can remove+ // the newly registered Escape handler between registration and the bump.let gen = WINDOW_SHORTCUTS_GEN.fetch_add(1, std::sync::atomic::Ordering::SeqCst).saturating_add(1);- info!("shortcut-sync: register generation bumped to {}", gen);+ info!("shortcut-sync: register generation started at {}", gen);+ register_window_shortcuts_inner(app_handle).map_err(|error| {+ error!(+ "shortcut-sync: Escape registration failed at generation {}: {}",+ gen, error+ );+ error+ })?;+ info!("shortcut-sync: register generation {} verified", gen);Ok(gen)}diff --git a/apps/screenpipe-app-tauri/src-tauri/src/store.rs b/apps/screenpipe-app-tauri/src-tauri/src/store.rsindex ccd9cd937..900639f55 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/store.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/store.rs@@ -2042,6 +2042,33 @@ fn restore_headed_mode_for_consumer(true}+const WINDOWS_TIMELINE_WINDOW_MODE_MIGRATION: &str =+ "windowsTimelineWindowModeMigrationV1";++/// Move existing Windows installs off the legacy borderless fullscreen overlay.+///+/// The marker makes this a one-time migration: after the first upgraded launch,+/// users can explicitly switch back to fullscreen without being overridden again.+fn migrate_windows_timeline_to_window_mode(settings: &mut SettingsStore) -> bool {+ if settings+ .extra+ .get(WINDOWS_TIMELINE_WINDOW_MODE_MIGRATION)+ .and_then(Value::as_bool)+ .unwrap_or(false)+ {+ return false;+ }++ if settings.overlay_mode == "fullscreen" {+ settings.overlay_mode = "window".to_string();+ }+ settings.extra.insert(+ WINDOWS_TIMELINE_WINDOW_MODE_MIGRATION.to_string(),+ Value::Bool(true),+ );+ true+}+pub fn init_store(app: &AppHandle) -> Result<SettingsStore, String> {println!("Initializing settings store");@@ -2059,14 +2086,14 @@ pub fn init_store(app: &AppHandle) -> Result<SettingsStore, String> {.unwrap_or(false);let is_new_store;- let (mut store, mut should_save) = match SettingsStore::get(app) {+ let (mut store, mut should_save, can_run_settings_migrations) = match SettingsStore::get(app) {Ok(Some(store)) => {is_new_store = false;- (store, should_persist_restart_notification_migration)+ (store, should_persist_restart_notification_migration, true)}Ok(None) => {is_new_store = true;- (SettingsStore::default(), true) // New store, save defaults+ (SettingsStore::default(), true, true) // New store, save defaults}Err(e) => {is_new_store = false;@@ -2078,7 +2105,7 @@ pub fn init_store(app: &AppHandle) -> Result<SettingsStore, String> {"Failed to deserialize settings, using defaults (store not overwritten): {}",e);- (SettingsStore::default(), false)+ (SettingsStore::default(), false, false)}};@@ -2162,6 +2189,16 @@ pub fn init_store(app: &AppHandle) -> Result<SettingsStore, String> {should_save = true;}+ if cfg!(target_os = "windows")+ && can_run_settings_migrations+ && migrate_windows_timeline_to_window_mode(&mut store)+ {+ tracing::info!(+ "settings migration: selected window mode for the Windows timeline overlay"+ );+ should_save = true;+ }+if should_save {if let Err(e) = store.save(app) {// Non-fatal — logged as warn (not error) so Sentry doesn't pick it up.@@ -2570,6 +2607,40 @@ mod tests {assert!(enterprise.headless_record_only);}+ #[test]+ fn windows_timeline_migration_moves_legacy_fullscreen_to_window_once() {+ let mut settings = SettingsStore {+ overlay_mode: "fullscreen".to_string(),+ ..Default::default()+ };++ assert!(migrate_windows_timeline_to_window_mode(&mut settings));+ assert_eq!(settings.overlay_mode, "window");+ assert_eq!(+ settings.extra.get(WINDOWS_TIMELINE_WINDOW_MODE_MIGRATION),+ Some(&Value::Bool(true))+ );++ settings.overlay_mode = "fullscreen".to_string();+ assert!(!migrate_windows_timeline_to_window_mode(&mut settings));+ assert_eq!(settings.overlay_mode, "fullscreen");+ }++ #[test]+ fn windows_timeline_migration_marks_existing_window_mode_complete() {+ let mut settings = SettingsStore {+ overlay_mode: "window".to_string(),+ ..Default::default()+ };++ assert!(migrate_windows_timeline_to_window_mode(&mut settings));+ assert_eq!(settings.overlay_mode, "window");+ assert_eq!(+ settings.extra.get(WINDOWS_TIMELINE_WINDOW_MODE_MIGRATION),+ Some(&Value::Bool(true))+ );+ }+#[test]fn remote_log_collection_defaults_to_disabled() {assert!(!SettingsStore::default().remote_log_collection_enabled);