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: dynamically register/unregister window shortcuts to avoid blocking other apps

Louis Beaumont93c5e52251e3
diff --git a/screenpipe-app-tauri/src-tauri/src/commands.rs b/screenpipe-app-tauri/src-tauri/src/commands.rs
index e85c26193..53bad01ec 100644
--- a/screenpipe-app-tauri/src-tauri/src/commands.rs
+++ b/screenpipe-app-tauri/src-tauri/src/commands.rs
@@ -42,6 +42,10 @@ pub fn show_main_window(app_handle: &tauri::AppHandle, _overlay: bool) {
if let Err(e) = window.set_focus() {
error!("Failed to set focus on main window: {}", e);
}
+
+ // Register window-specific shortcuts (Escape, Cmd+K, Cmd+L)
+ // These are only active while the overlay is visible
+ let _ = register_window_shortcuts(app_handle.clone());
}
Err(e) => {
error!("ShowRewindWindow::Main.show failed: {}", e);
@@ -52,6 +56,10 @@ pub fn show_main_window(app_handle: &tauri::AppHandle, _overlay: bool) {
#[tauri::command]
#[specta::specta]
pub fn hide_main_window(app_handle: &tauri::AppHandle) {
+ // Unregister window-specific shortcuts first (Escape, Cmd+K, Cmd+L)
+ // This allows these keys to work normally in other apps
+ let _ = unregister_window_shortcuts(app_handle.clone());
+
ShowRewindWindow::Main.close(app_handle).unwrap();
}
@@ -528,4 +536,97 @@ pub async fn hide_shortcut_reminder(app_handle: tauri::AppHandle) -> Result<(),
let _ = window.hide();
}
Ok(())
+}
+
+/// Register window-specific shortcuts (Escape, Cmd+K, Cmd+L) when main window is visible
+/// These should only be active when the overlay is open to avoid blocking other apps
+#[tauri::command]
+#[specta::specta]
+pub fn register_window_shortcuts(app_handle: tauri::AppHandle) -> Result<(), String> {
+ use tauri_plugin_global_shortcut::{Code, GlobalShortcutExt, Modifiers, Shortcut, ShortcutState};
+ use tauri::Emitter;
+
+ let global_shortcut = app_handle.global_shortcut();
+
+ // Register Escape shortcut to hide the main timeline window
+ let 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) {
+ info!("Escape pressed, hiding main window");
+ hide_main_window(app);
+ }
+ }) {
+ // Ignore "already registered" errors - shortcut may already be active
+ if !e.to_string().contains("already registered") {
+ error!("Failed to register Escape shortcut: {}", e);
+ }
+ }
+
+ // Register Cmd+K (macOS) / Ctrl+K (Windows/Linux) to open search
+ #[cfg(target_os = "macos")]
+ let search_shortcut = Shortcut::new(Some(Modifiers::SUPER), Code::KeyK);
+ #[cfg(not(target_os = "macos"))]
+ let search_shortcut = Shortcut::new(Some(Modifiers::CONTROL), Code::KeyK);
+
+ if let Err(e) = global_shortcut.on_shortcut(search_shortcut, |app, _, event| {
+ if matches!(event.state, ShortcutState::Pressed) {
+ info!("Search shortcut triggered (Cmd+K / Ctrl+K)");
+ let _ = app.emit("open-search", ());
+ }
+ }) {
+ if !e.to_string().contains("already registered") {
+ error!("Failed to register search shortcut: {}", e);
+ }
+ }
+
+ // Register Cmd+L (macOS) / Ctrl+L (Windows/Linux) to open AI chat
+ #[cfg(target_os = "macos")]
+ let chat_shortcut = Shortcut::new(Some(Modifiers::SUPER), Code::KeyL);
+ #[cfg(not(target_os = "macos"))]
+ let chat_shortcut = Shortcut::new(Some(Modifiers::CONTROL), Code::KeyL);
+
+ if let Err(e) = global_shortcut.on_shortcut(chat_shortcut, |app, _, event| {
+ if matches!(event.state, ShortcutState::Pressed) {
+ info!("Chat shortcut triggered (Cmd+L / Ctrl+L)");
+ let _ = app.emit("open-chat", ());
+ }
+ }) {
+ if !e.to_string().contains("already registered") {
+ error!("Failed to register chat shortcut: {}", e);
+ }
+ }
+
+ info!("Window-specific shortcuts registered (Escape, Cmd+K, Cmd+L)");
+ Ok(())
+}
+
+/// Unregister window-specific shortcuts when main window is hidden
+/// This allows Escape, Cmd+K, Cmd+L to work normally in other apps
+#[tauri::command]
+#[specta::specta]
+pub fn unregister_window_shortcuts(app_handle: tauri::AppHandle) -> Result<(), String> {
+ use tauri_plugin_global_shortcut::{Code, GlobalShortcutExt, Modifiers, Shortcut};
+
+ let global_shortcut = app_handle.global_shortcut();
+
+ // Unregister Escape
+ let escape_shortcut = Shortcut::new(None, Code::Escape);
+ let _ = global_shortcut.unregister(escape_shortcut);
+
+ // Unregister Cmd+K / Ctrl+K
+ #[cfg(target_os = "macos")]
+ let search_shortcut = Shortcut::new(Some(Modifiers::SUPER), Code::KeyK);
+ #[cfg(not(target_os = "macos"))]
+ let search_shortcut = Shortcut::new(Some(Modifiers::CONTROL), Code::KeyK);
+ let _ = global_shortcut.unregister(search_shortcut);
+
+ // Unregister Cmd+L / Ctrl+L
+ #[cfg(target_os = "macos")]
+ let chat_shortcut = Shortcut::new(Some(Modifiers::SUPER), Code::KeyL);
+ #[cfg(not(target_os = "macos"))]
+ let chat_shortcut = Shortcut::new(Some(Modifiers::CONTROL), Code::KeyL);
+ let _ = global_shortcut.unregister(chat_shortcut);
+
+ info!("Window-specific shortcuts unregistered");
+ Ok(())
}
\ No newline at end of file
diff --git a/screenpipe-app-tauri/src-tauri/src/main.rs b/screenpipe-app-tauri/src-tauri/src/main.rs
index b73277a54..90332b6b2 100755
--- a/screenpipe-app-tauri/src-tauri/src/main.rs
+++ b/screenpipe-app-tauri/src-tauri/src/main.rs
@@ -280,80 +280,9 @@ async fn apply_shortcuts(app: &AppHandle, config: &ShortcutConfig) -> Result<(),
)
.await?;
- // Register Escape shortcut to hide the main timeline window
- let 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) {
- info!("Escape pressed, hiding main window");
- hide_main_window(app);
- }
- }) {
- warn!("Failed to register Escape shortcut: {}", e);
- }
-
- // Register Cmd+K (macOS) / Ctrl+K (Windows/Linux) to open search when main window is visible
- #[cfg(target_os = "macos")]
- let search_shortcut = Shortcut::new(Some(Modifiers::SUPER), Code::KeyK);
- #[cfg(not(target_os = "macos"))]
- let search_shortcut = Shortcut::new(Some(Modifiers::CONTROL), Code::KeyK);
-
- if let Err(e) = global_shortcut.on_shortcut(search_shortcut, |app, _, event| {
- if matches!(event.state, ShortcutState::Pressed) {
- // Only open search if main window is visible
- #[cfg(target_os = "macos")]
- {
- if let Ok(window) = app.get_webview_panel("main") {
- if window.is_visible() {
- info!("Cmd+K pressed, opening search");
- let _ = app.emit("open-search", ());
- }
- }
- }
- #[cfg(not(target_os = "macos"))]
- {
- if let Some(window) = app.get_webview_window("main") {
- if window.is_visible().unwrap_or(false) {
- info!("Ctrl+K pressed, opening search");
- let _ = app.emit("open-search", ());
- }
- }
- }
- }
- }) {
- warn!("Failed to register search shortcut: {}", e);
- }
-
- // Register Cmd+L (macOS) / Ctrl+L (Windows/Linux) to open AI chat when main window is visible
- #[cfg(target_os = "macos")]
- let chat_shortcut = Shortcut::new(Some(Modifiers::SUPER), Code::KeyL);
- #[cfg(not(target_os = "macos"))]
- let chat_shortcut = Shortcut::new(Some(Modifiers::CONTROL), Code::KeyL);
-
- if let Err(e) = global_shortcut.on_shortcut(chat_shortcut, |app, _, event| {
- if matches!(event.state, ShortcutState::Pressed) {
- // Only open chat if main window is visible
- #[cfg(target_os = "macos")]
- {
- if let Ok(window) = app.get_webview_panel("main") {
- if window.is_visible() {
- info!("Cmd+L pressed, opening AI chat");
- let _ = app.emit("open-chat", ());
- }
- }
- }
- #[cfg(not(target_os = "macos"))]
- {
- if let Some(window) = app.get_webview_window("main") {
- if window.is_visible().unwrap_or(false) {
- info!("Ctrl+L pressed, opening AI chat");
- let _ = app.emit("open-chat", ());
- }
- }
- }
- }
- }) {
- warn!("Failed to register chat shortcut: {}", e);
- }
+ // NOTE: Escape, Cmd+K, Cmd+L shortcuts are now registered dynamically
+ // via register_window_shortcuts/unregister_window_shortcuts commands
+ // This prevents them from blocking other apps when the overlay is closed
Ok(())
}
@@ -768,6 +697,9 @@ async fn main() {
// Shortcut reminder commands
commands::show_shortcut_reminder,
commands::hide_shortcut_reminder,
+ // Window-specific shortcut commands (dynamic registration)
+ commands::register_window_shortcuts,
+ commands::unregister_window_shortcuts,
// Commands from tray.rs
set_tray_unhealth_icon,
set_tray_health_icon,
@@ -863,6 +795,9 @@ async fn main() {
// Shortcut reminder commands
commands::show_shortcut_reminder,
commands::hide_shortcut_reminder,
+ // Window-specific shortcut commands (dynamic registration)
+ commands::register_window_shortcuts,
+ commands::unregister_window_shortcuts,
// Overlay commands (Windows)
commands::enable_overlay_click_through,
commands::disable_overlay_click_through,