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(windows overlay): busy cursor, lost drag, dead transcript, dropped alert

louis030195eae7925280e0
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs b/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
index b6dfc6b93..a5a73e40a 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
@@ -3455,10 +3455,13 @@ pub async fn show_notification_panel(
// so gating after them would let a repeat surface on the pill anyway.
let notification_title =
crate::notifications::gate::title_from_payload(&payload).unwrap_or_default();
+ let notification_body =
+ crate::notifications::gate::body_from_payload(&payload).unwrap_or_default();
if crate::notifications::gate::repeat_suppressed_now(
notification_type.as_deref(),
notification_pipe.as_deref(),
&notification_title,
+ &notification_body,
) {
info!(
"show_notification_panel: suppressed (repeat within cooldown, type={:?})",
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/native_overlay_win.rs b/apps/screenpipe-app-tauri/src-tauri/src/native_overlay_win.rs
index 0a2754708..dda3353ad 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/native_overlay_win.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/native_overlay_win.rs
@@ -35,7 +35,8 @@ use crate::native_shortcut_reminder::MeetingOverlayPanelState;
static NATIVE: OnceLock<Native> = OnceLock::new();
static ACTION_CB: Mutex<Option<extern "C" fn(*const c_char)>> = Mutex::new(None);
static VISIBLE: AtomicBool = AtomicBool::new(false);
-static FEEDERS_STARTED: AtomicBool = AtomicBool::new(false);
+static METRICS_FEED_STARTED: AtomicBool = AtomicBool::new(false);
+static MEETING_FEED_STARTED: AtomicBool = AtomicBool::new(false);
struct Native {
overlay: Overlay,
@@ -245,20 +246,34 @@ pub fn set_action_callback(cb: extern "C" fn(*const c_char)) {
// MARK: engine feeds
-/// Connect the two websockets the pill reads from. Started once; both reconnect
-/// on their own, because the engine restarts far more often than the overlay.
+/// Connect the two websockets the pill reads from. Each is started once and
+/// reconnects on its own, because the engine restarts far more often than the
+/// overlay.
+///
+/// Tracked per feed, and only once a URL actually exists. `show` runs at
+/// startup and the URLs are absent until the engine has bound its port, so a
+/// single shared "already started" flag was consumed by that first empty call
+/// — the sockets were then never opened for the rest of the session. That is a
+/// pill with a dead audio meter and, because meeting state and transcript lines
+/// both arrive on the meeting socket, no live transcript card at all.
fn start_feeders(metrics_url: Option<&str>, events_url: Option<&str>) {
- if FEEDERS_STARTED.swap(true, Ordering::SeqCst) {
- return;
- }
- if let Some(url) = metrics_url.map(str::to_string) {
+ if let Some(url) = claim_feed(metrics_url, &METRICS_FEED_STARTED) {
tauri::async_runtime::spawn(async move { metrics_feeder(url).await });
}
- if let Some(url) = events_url.map(str::to_string) {
+ if let Some(url) = claim_feed(events_url, &MEETING_FEED_STARTED) {
tauri::async_runtime::spawn(async move { meeting_feeder(url).await });
}
}
+/// The URL to connect, if this call is the one that should open the socket.
+///
+/// The order matters: a missing URL must leave the flag alone. Claiming it
+/// first is what silently disabled both feeds for a whole session.
+fn claim_feed(url: Option<&str>, started: &AtomicBool) -> Option<String> {
+ let url = url?.to_string();
+ (!started.swap(true, Ordering::SeqCst)).then_some(url)
+}
+
/// Reconnecting websocket loop shared by both feeders.
async fn feed<F>(url: String, name: &'static str, mut on_message: F)
where
@@ -411,3 +426,35 @@ async fn meeting_feeder(url: String) {
})
.await;
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ /// `show` runs at startup, before the engine has bound its port, so the
+ /// first call carries no URLs. Claiming the "already started" flag there
+ /// meant the socket was never opened for the rest of the session — a pill
+ /// with a dead audio meter and no live transcript, because meeting state
+ /// and transcript lines both arrive on that socket.
+ #[test]
+ fn a_feed_with_no_url_yet_does_not_burn_its_one_chance() {
+ let started = AtomicBool::new(false);
+
+ assert_eq!(claim_feed(None, &started), None, "nothing to connect to");
+ assert!(
+ !started.load(Ordering::SeqCst),
+ "the flag must survive a call that had no url"
+ );
+
+ assert_eq!(
+ claim_feed(Some("ws://127.0.0.1:3030/ws/metrics"), &started).as_deref(),
+ Some("ws://127.0.0.1:3030/ws/metrics"),
+ "the call that finally has a url opens the socket"
+ );
+ assert_eq!(
+ claim_feed(Some("ws://127.0.0.1:3030/ws/metrics"), &started),
+ None,
+ "and only that one does — the feed reconnects on its own"
+ );
+ }
+}
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/notifications/gate.rs b/apps/screenpipe-app-tauri/src-tauri/src/notifications/gate.rs
index ff775e31f..ed74577a0 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/notifications/gate.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/notifications/gate.rs
@@ -244,10 +244,17 @@ pub fn suppressed_now(
// So: one ledger of when each distinct alert last surfaced, consulted at the
// same choke point as the reduced states.
//
-// Keyed on `(type, pipe, title)`, not on type alone. Our type vocabulary is
-// coarse — `pipe`, `system`, `meeting` — so a type-only cooldown would let one
-// chatty pipe mute every other pipe's alerts. The triple is the narrowest
-// identity that still collapses a genuine repeat.
+// Keyed on `(type, pipe, title, body)`, not on type alone. Our type vocabulary
+// is coarse — `pipe`, `system`, `meeting` — so a type-only cooldown would let
+// one chatty pipe mute every other pipe's alerts.
+//
+// The body is in the identity because for some producers it carries the only
+// thing that differs between two genuinely distinct alerts. A meeting alert
+// with no calendar match is titled "meeting detected" whatever the meeting is
+// and names it in the body, so keying on the title alone made the second
+// meeting inside the five-minute window an "identical repeat" and dropped it —
+// taking its "open note" button with it. Two alerts that agree on all four
+// fields really are the same alert; two that differ in the body are not.
/// How long an identical alert stays muted after it surfaces.
///
@@ -277,12 +284,18 @@ pub fn repeat_cooldown_ms(notification_type: Option<&str>) -> i64 {
/// Identity of an alert for repeat purposes. `\u{1}` can't appear in a JSON
/// string value, so the parts can't run together to forge a collision.
-pub fn repeat_key(notification_type: Option<&str>, pipe_name: Option<&str>, title: &str) -> String {
+pub fn repeat_key(
+ notification_type: Option<&str>,
+ pipe_name: Option<&str>,
+ title: &str,
+ body: &str,
+) -> String {
format!(
- "{}\u{1}{}\u{1}{}",
+ "{}\u{1}{}\u{1}{}\u{1}{}",
notification_type.unwrap_or(""),
pipe_name.unwrap_or(""),
- title
+ title,
+ body
)
}
@@ -351,6 +364,7 @@ pub fn repeat_suppressed_now(
notification_type: Option<&str>,
pipe_name: Option<&str>,
title: &str,
+ body: &str,
) -> bool {
if matches!(notification_type, Some(t) if is_critical_type(t)) {
return false;
@@ -360,7 +374,7 @@ pub fn repeat_suppressed_now(
if title.trim().is_empty() {
return false;
}
- let key = repeat_key(notification_type, pipe_name, title);
+ let key = repeat_key(notification_type, pipe_name, title, body);
let cooldown = repeat_cooldown_ms(notification_type);
let now_ms = chrono::Local::now().timestamp_millis();
let mut guard = ledger().lock().unwrap_or_else(|e| e.into_inner());
@@ -377,6 +391,12 @@ pub fn title_from_payload(payload: &str) -> Option<String> {
json_field(payload, "title")
}
+/// Extract the `body` field. Part of the repeat identity — see the module
+/// notes above for why the title alone is not enough.
+pub fn body_from_payload(payload: &str) -> Option<String> {
+ json_field(payload, "body")
+}
+
/// Extract the `pipe_name` field from a notification panel payload JSON string.
pub fn pipe_name_from_payload(payload: &str) -> Option<String> {
json_field(payload, "pipe_name")
@@ -716,33 +736,74 @@ mod tests {
assert_eq!(repeat_cooldown_ms(None), DEFAULT_REPEAT_COOLDOWN_MS);
}
- /// The reason the key is a triple: our types are coarse, so two pipes
- /// posting the same title must not silence each other.
+ /// The reason the key is not just the type: our types are coarse, so two
+ /// pipes posting the same title must not silence each other.
#[test]
fn key_separates_pipes_types_and_titles() {
- let a = repeat_key(Some("pipe"), Some("alpha"), "run finished");
- let b = repeat_key(Some("pipe"), Some("beta"), "run finished");
- let c = repeat_key(Some("system"), Some("alpha"), "run finished");
- let d = repeat_key(Some("pipe"), Some("alpha"), "run failed");
+ let a = repeat_key(Some("pipe"), Some("alpha"), "run finished", "");
+ let b = repeat_key(Some("pipe"), Some("beta"), "run finished", "");
+ let c = repeat_key(Some("system"), Some("alpha"), "run finished", "");
+ let d = repeat_key(Some("pipe"), Some("alpha"), "run failed", "");
assert_ne!(a, b);
assert_ne!(a, c);
assert_ne!(a, d);
- assert_eq!(a, repeat_key(Some("pipe"), Some("alpha"), "run finished"));
+ assert_eq!(
+ a,
+ repeat_key(Some("pipe"), Some("alpha"), "run finished", "")
+ );
}
/// Field values can't run together to forge a collision.
#[test]
fn key_parts_cannot_be_confused() {
assert_ne!(
- repeat_key(Some("pipe"), Some("a"), "b"),
- repeat_key(Some("pipe"), Some("ab"), "")
+ repeat_key(Some("pipe"), Some("a"), "b", ""),
+ repeat_key(Some("pipe"), Some("ab"), "", "")
+ );
+ assert_ne!(
+ repeat_key(Some("pipe"), Some("p"), "a", "b"),
+ repeat_key(Some("pipe"), Some("p"), "ab", "")
+ );
+ }
+
+ /// A second meeting is not a repeat of the first.
+ ///
+ /// Without a calendar match every meeting alert is titled "meeting
+ /// detected" and names the call in the body, so a title-only identity made
+ /// the next meeting inside the five-minute window an identical repeat and
+ /// dropped it — along with the "open note" button that is the whole point
+ /// of the alert. Observed in the wild before this was keyed on the body.
+ #[test]
+ fn a_different_meeting_is_not_a_repeat() {
+ let mut ledger = empty_ledger();
+ let cooldown = repeat_cooldown_ms(Some("meeting"));
+ let first = repeat_key(
+ Some("meeting"),
+ None,
+ "meeting detected",
+ "screenpipe is saving this meeting for transcription: Google Meet",
+ );
+ let second = repeat_key(
+ Some("meeting"),
+ None,
+ "meeting detected",
+ "screenpipe is saving this meeting for transcription: standup",
+ );
+ assert!(!check_and_record(&mut ledger, first.clone(), 0, cooldown));
+ assert!(
+ !check_and_record(&mut ledger, second, 60_000, cooldown),
+ "a different meeting must still reach the user"
+ );
+ assert!(
+ check_and_record(&mut ledger, first, 60_000, cooldown),
+ "the same meeting re-firing is still collapsed"
);
}
#[test]
fn ledger_drops_the_echo_and_reopens_after_the_cooldown() {
let mut ledger = empty_ledger();
- let key = repeat_key(Some("system"), None, "disk filling up");
+ let key = repeat_key(Some("system"), None, "disk filling up", "");
assert!(!check_and_record(&mut ledger, key.clone(), 0, 600_000));
assert!(check_and_record(&mut ledger, key.clone(), 60_000, 600_000));
assert!(check_and_record(&mut ledger, key.clone(), 599_999, 600_000));
@@ -754,7 +815,7 @@ mod tests {
#[test]
fn suppressed_echoes_do_not_extend_the_window() {
let mut ledger = empty_ledger();
- let key = repeat_key(Some("pipe"), Some("p"), "t");
+ let key = repeat_key(Some("pipe"), Some("p"), "t", "");
assert!(!check_and_record(&mut ledger, key.clone(), 0, 90_000));
for t in (10_000..90_000).step_by(10_000) {
assert!(check_and_record(&mut ledger, key.clone(), t, 90_000));
@@ -769,7 +830,7 @@ mod tests {
fn ledger_stays_bounded_and_keeps_serving_new_keys() {
let mut ledger = empty_ledger();
for i in 0..(MAX_LEDGER_ENTRIES * 2) {
- let key = repeat_key(Some("pipe"), Some("p"), &format!("title {i}"));
+ let key = repeat_key(Some("pipe"), Some("p"), &format!("title {i}"), "");
assert!(
!check_and_record(&mut ledger, key, i as i64, DEFAULT_REPEAT_COOLDOWN_MS),
"a never-seen alert must always be delivered"
@@ -787,9 +848,14 @@ mod tests {
#[test]
fn critical_types_are_never_repeat_suppressed() {
for t in CRITICAL_TYPES {
- assert!(!repeat_suppressed_now(Some(t), None, "recording stopped"));
+ assert!(!repeat_suppressed_now(
+ Some(t),
+ None,
+ "recording stopped",
+ ""
+ ));
assert!(
- !repeat_suppressed_now(Some(t), None, "recording stopped"),
+ !repeat_suppressed_now(Some(t), None, "recording stopped", ""),
"{t} must survive an immediate re-fire"
);
}
@@ -799,8 +865,8 @@ mod tests {
/// unrelated alerts into one.
#[test]
fn untitled_alerts_are_not_capped() {
- assert!(!repeat_suppressed_now(Some("pipe"), Some("p"), ""));
- assert!(!repeat_suppressed_now(Some("pipe"), Some("p"), " "));
+ assert!(!repeat_suppressed_now(Some("pipe"), Some("p"), "", ""));
+ assert!(!repeat_suppressed_now(Some("pipe"), Some("p"), " ", ""));
}
#[test]
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/notifications/routes.rs b/apps/screenpipe-app-tauri/src-tauri/src/notifications/routes.rs
index 54fc7a0b1..3c923bea1 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/notifications/routes.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/notifications/routes.rs
@@ -193,13 +193,16 @@ pub async fn send_notification(
}));
}
- // Repeat gate: same type + pipe + title, again, inside its cooldown. A
+ // Repeat gate: the same alert, again, inside its cooldown. A
// condition-driven producer re-fires while its condition holds; drop the
- // echo here rather than expecting every producer to latch for itself.
+ // echo here rather than expecting every producer to latch for itself. The
+ // body is part of the identity because for some producers it carries the
+ // only thing that tells two distinct alerts apart — see the gate's notes.
if super::gate::repeat_suppressed_now(
Some(resolved_type.as_str()),
source.pipe_name.as_deref(),
&payload.title,
+ &payload.body,
) {
debug!("notify: skipped (identical alert already shown recently)");
return Ok(Json(ApiResponse {
diff --git a/crates/screenpipe-overlay-win/src/window.rs b/crates/screenpipe-overlay-win/src/window.rs
index df9e3b8a9..7b9882b6a 100644
--- a/crates/screenpipe-overlay-win/src/window.rs
+++ b/crates/screenpipe-overlay-win/src/window.rs
@@ -43,12 +43,13 @@ use windows::Win32::UI::Input::KeyboardAndMouse::{
};
use windows::Win32::UI::WindowsAndMessaging::{
CreateWindowExW, DefWindowProcW, DestroyWindow, DispatchMessageW, GetCursorPos, GetMessageW,
- GetWindowLongPtrW, GetWindowRect, KillTimer, PostMessageW, PostQuitMessage, RegisterClassExW,
- SetTimer, SetWindowLongPtrW, SetWindowPos, ShowWindow, TranslateMessage, UpdateLayeredWindow,
- CS_HREDRAW, CS_VREDRAW, GWLP_USERDATA, HWND_TOPMOST, MSG, SWP_NOACTIVATE, SWP_NOSIZE, SW_HIDE,
- SW_SHOWNOACTIVATE, ULW_ALPHA, WINDOWPOS, WM_APP, WM_DESTROY, WM_DISPLAYCHANGE, WM_DPICHANGED,
- WM_LBUTTONDOWN, WM_LBUTTONUP, WM_MOUSEMOVE, WM_SETTINGCHANGE, WM_TIMER, WM_WINDOWPOSCHANGING,
- WNDCLASSEXW, WS_EX_LAYERED, WS_EX_NOACTIVATE, WS_EX_TOOLWINDOW, WS_EX_TOPMOST, WS_POPUP,
+ GetWindowLongPtrW, GetWindowRect, KillTimer, LoadCursorW, PostMessageW, PostQuitMessage,
+ RegisterClassExW, SetTimer, SetWindowLongPtrW, SetWindowPos, ShowWindow, TranslateMessage,
+ UpdateLayeredWindow, CS_HREDRAW, CS_VREDRAW, GWLP_USERDATA, HWND_TOPMOST, IDC_ARROW, MSG,
+ SWP_NOACTIVATE, SWP_NOSIZE, SW_HIDE, SW_SHOWNOACTIVATE, ULW_ALPHA, WINDOWPOS, WM_APP,
+ WM_DESTROY, WM_DISPLAYCHANGE, WM_DPICHANGED, WM_LBUTTONDOWN, WM_LBUTTONUP, WM_MOUSEMOVE,
+ WM_SETTINGCHANGE, WM_TIMER, WM_WINDOWPOSCHANGING, WNDCLASSEXW, WS_EX_LAYERED, WS_EX_NOACTIVATE,
+ WS_EX_TOOLWINDOW, WS_EX_TOPMOST, WS_POPUP,
};
use crate::actions::{action_for, anchor_action};
@@ -218,6 +219,9 @@ struct Ctx {
/// because it must not expand the pill — it only suspends the toast's
/// self-dismiss and freezes the expansion the pointer arrived with.
toast_hovered: bool,
+ /// The last anchor the app pushed, so a re-push of the same value can be
+ /// told apart from the app actually asking the pill to move.
+ pushed_anchor: Option<Anchor>,
dragging: bool,
drag_offset: (i32, i32),
animating: bool,
@@ -245,6 +249,12 @@ fn run_message_loop(
style: CS_HREDRAW | CS_VREDRAW,
lpfnWndProc: Some(wndproc),
hInstance: instance.into(),
+ // A class with no cursor does not set one when the pointer enters,
+ // so the window inherits whatever the last window asked for. From a
+ // GUI process that is usually the app-starting cursor: hovering the
+ // pill showed a spinner, as if it were busy. Name the cursor and it
+ // is a plain arrow like every other control.
+ hCursor: LoadCursorW(None, IDC_ARROW)?,
lpszClassName: class,
..Default::default()
};
@@ -284,6 +294,7 @@ fn run_message_loop(
press_origin: None,
press_can_drag: false,
toast_hovered: false,
+ pushed_anchor: None,
dragging: false,
drag_offset: (0, 0),
animating: false,
@@ -634,6 +645,32 @@ fn mouse_dip(hwnd: HWND, lparam: LPARAM) -> (f32, f32) {
(x / scale, y / scale)
}
+/// Where the pill should sit after a state push, and the anchor to remember as
+/// the app's latest word on the subject.
+///
+/// Where the pill sits is the user's, decided by dragging it. But the app
+/// re-pushes its whole state constantly — the audio meter alone arrives many
+/// times a second — and its copy still holds the pre-drag anchor until it has
+/// persisted the new one and read it back. Taking the pushed value at face
+/// value therefore snapped the pill home within a frame of the drop, which is
+/// what a drag that "goes back" is. So an echo of the anchor the app already
+/// sent leaves the pill where the user put it, and only a *changed* anchor
+/// moves it: settings, a restore, another window.
+fn resolve_anchor(
+ pushed: Option<Anchor>,
+ incoming: Anchor,
+ window: Anchor,
+ dragging: bool,
+) -> (Anchor, Option<Anchor>) {
+ let app_moved_it = pushed != Some(incoming);
+ let applied = if app_moved_it && !dragging {
+ incoming
+ } else {
+ window
+ };
+ (applied, Some(incoming))
+}
+
/// Drain the command channel. Returns whether anything changed.
fn drain_commands(hwnd: HWND) -> (bool, bool) {
let Some(ctx) = (unsafe { ctx_of(hwnd) }) else {
@@ -655,9 +692,10 @@ fn drain_commands(hwnd: HWND) -> (bool, bool) {
s.pressed_control = ctx.state.pressed_control;
s.dragging = ctx.state.dragging;
s.drag_target = ctx.state.drag_target;
- if ctx.dragging {
- s.anchor = ctx.state.anchor;
- }
+ let (anchor, pushed) =
+ resolve_anchor(ctx.pushed_anchor, s.anchor, ctx.state.anchor, ctx.dragging);
+ s.anchor = anchor;
+ ctx.pushed_anchor = pushed;
// The caller does not own the notification either — it arrives
// through show_notification and leaves on its own schedule.
s.notification = ctx.state.notification.clone();
@@ -983,3 +1021,51 @@ extern "system" fn wndproc(hwnd: HWND, msg: u32, wparam: WPARAM, lparam: LPARAM)
}
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ /// Replays the drag that would not stick: the app's own copy of the state
+ /// is stale the moment the pointer is released, and it re-pushes that copy
+ /// continuously.
+ #[test]
+ fn a_dragged_pill_survives_the_apps_stale_state_pushes() {
+ // Startup: the app pushes the persisted anchor and the pill takes it.
+ let (anchor, pushed) =
+ resolve_anchor(None, Anchor::BottomRight, Anchor::BottomCenter, false);
+ assert_eq!(anchor, Anchor::BottomRight, "first push places the pill");
+
+ // The user drags it across the screen; the window now owns MiddleLeft.
+ let dragged = Anchor::MiddleLeft;
+
+ // The metrics feed pushes again, still carrying the pre-drag anchor.
+ let (anchor, pushed) = resolve_anchor(pushed, Anchor::BottomRight, dragged, false);
+ assert_eq!(anchor, dragged, "an echo must not drag the pill home");
+
+ // ...and keeps pushing, many times a second.
+ let (anchor, pushed) = resolve_anchor(pushed, Anchor::BottomRight, dragged, false);
+ assert_eq!(anchor, dragged);
+
+ // Settings genuinely move it: a *changed* anchor is obeyed.
+ let (anchor, pushed) = resolve_anchor(pushed, Anchor::TopLeft, dragged, false);
+ assert_eq!(anchor, Anchor::TopLeft);
+
+ // And once the app has caught up, echoing the dragged value is a no-op.
+ let (anchor, _) = resolve_anchor(pushed, Anchor::TopLeft, Anchor::TopLeft, false);
+ assert_eq!(anchor, Anchor::TopLeft);
+ }
+
+ /// A push landing mid-drag must never teleport the pill out from under the
+ /// pointer, even when the app really did change the anchor.
+ #[test]
+ fn nothing_moves_the_pill_while_it_is_being_dragged() {
+ let (anchor, _) = resolve_anchor(
+ Some(Anchor::BottomRight),
+ Anchor::TopLeft,
+ Anchor::MiddleRight,
+ true,
+ );
+ assert_eq!(anchor, Anchor::MiddleRight);
+ }
+}