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): overlay blink-and-comeback on shortcut toggle

Louis Beaumont09a180702ed1
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs b/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
index 3bbd8bfc5..4ca8a5bcb 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
@@ -185,11 +185,39 @@ pub fn update_show_screenpipe_shortcut(
return Ok(());
}
- // Register the new shortcut
+ // Register the new shortcut with toggle logic (show if hidden, hide if visible)
if let Err(e) = app_handle.global_shortcut().on_shortcut(
show_window_shortcut,
move |app_handle, _event, _shortcut| {
- show_main_window(app_handle, true);
+ #[cfg(target_os = "macos")]
+ {
+ use crate::window_api::main_label_for_mode;
+ use crate::store::SettingsStore;
+ let mode = SettingsStore::get(app_handle)
+ .unwrap_or_default()
+ .unwrap_or_default()
+ .overlay_mode;
+ let label = main_label_for_mode(&mode);
+ if let Some(window) = app_handle.get_webview_window(label) {
+ match window.is_visible() {
+ Ok(true) => hide_main_window(app_handle),
+ _ => show_main_window(app_handle, true),
+ }
+ } else {
+ show_main_window(app_handle, true);
+ }
+ }
+ #[cfg(not(target_os = "macos"))]
+ {
+ if let Some(window) = app_handle.get_webview_window("main") {
+ match window.is_visible() {
+ Ok(true) => hide_main_window(app_handle),
+ _ => show_main_window(app_handle, true),
+ }
+ } else {
+ show_main_window(app_handle, true);
+ }
+ }
},
) {
info!("failed to register shortcut: {}", e);
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 8153b26a2..f6a486f9a 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/window_api.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/window_api.rs
@@ -1282,20 +1282,36 @@ impl ShowRewindWindow {
if id.label() == RewindWindowId::Main.label() {
#[cfg(target_os = "macos")]
{
- // Hide whichever main panel is active (could be "main" or "main-window")
- // Restore the previously frontmost app to prevent Space switching.
- restore_frontmost_app();
+ // Hide whichever main panel is active (could be "main" or "main-window").
+ //
+ // IMPORTANT: order_out MUST happen BEFORE restore_frontmost_app().
+ // Previously restore ran first (synchronous) while order_out was
+ // dispatched async. This caused a focus bounce: the panel lost key
+ // status (alpha→0), then NSNonactivatingPanelMask let it reassert
+ // key (alpha→1), and only THEN did order_out run — creating a
+ // visible "blink and comes back" artifact.
+ //
+ // By doing both inside one run_on_main_thread_safe closure with
+ // order_out first, the panel is off-screen before the previous app
+ // is reactivated, so no focus events can bounce back to it.
let app_clone = app.clone();
run_on_main_thread_safe(app, move || {
+ use objc::{msg_send, sel, sel_impl};
for label in &["main", "main-window"] {
if let Ok(panel) = app_clone.get_webview_panel(label) {
if panel.is_visible() {
+ // Alpha=0 first for instant visual hide
+ unsafe {
+ let _: () = msg_send![&*panel, setAlphaValue: 0.0f64];
+ }
panel.order_out(None);
}
}
}
+ // Now that the panel is off-screen, safely restore the
+ // previous app without triggering focus events on our panel.
+ restore_frontmost_app();
});
-
}
#[cfg(not(target_os = "macos"))]