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): remove tray while in search-only mode (#7737)
Ezra Ellette4115edc8b7c3
diff --git a/apps/screenpipe-app-tauri/e2e/search-only.e2e.ts b/apps/screenpipe-app-tauri/e2e/search-only.e2e.tsindex 91ad3aa8d..bd24959d6 100644--- a/apps/screenpipe-app-tauri/e2e/search-only.e2e.ts+++ b/apps/screenpipe-app-tauri/e2e/search-only.e2e.ts@@ -23,6 +23,8 @@ type State = {capture_running: boolean;webviews: string[];keep_search_after_quit: boolean;+ tray_registered: boolean;+ platform: string;};async function request(base: string,@@ -66,11 +68,14 @@ const counts = async () => {};const initial = await state();+assert(initial.platform, "The E2E app must report its target platform");+const windowsTray = initial.platform === "windows";assert(initial.keep_search_after_quit, "The preference defaults On");assert(initial.capture_intended && initial.capture_running,"Start real capture before running this check",);+assert(initial.tray_registered, "Normal recording has a native tray");const history = await request(api, "/search?limit=1&content_type=all");assert(history.data?.length > 0,@@ -86,7 +91,8 @@ for (let cycle = 0; cycle < 2; cycle++) {!s.entering &&!s.capture_intended &&!s.capture_running &&- s.webviews.length === 0+ s.webviews.length === 0 &&+ (!windowsTray || !s.tray_registered));}, "Quit stops capture and destroys webviews");assert.equal(@@ -94,6 +100,23 @@ for (let cycle = 0; cycle < 2; cycle++) {initial.pid,"Quit must retain the existing process",);+ if (windowsTray) {+ assert.equal(+ (await state()).tray_registered,+ false,+ "Quit removes the native tray registration",+ );+ assert.equal(+ (await request(control, "/e2e/search-only/recreate-tray", "POST")).accepted,+ true,+ "Native tray recreation completed",+ );+ assert.equal(+ (await state()).tray_registered,+ false,+ "Explicit tray recreation cannot resurrect search-only tray UI",+ );+ }assert((await request(api, "/search?limit=1&content_type=all")).data.length > 0,"External history request succeeds after Quit",@@ -136,6 +159,11 @@ for (let cycle = 0; cycle < 2; cycle++) {"Reopening resumes recording without a separate Start action",);assert.equal((await state()).pid, initial.pid);+ assert.equal(+ (await state()).tray_registered,+ true,+ "Manual reopen restores the native tray",+ );await until(async () => {const resumed = await counts();return Date.parse(resumed.lastFrame) > Date.parse(stopped.lastFrame);@@ -179,7 +207,8 @@ await until(async () => {s.search_only &&!s.capture_running &&!s.capture_intended &&- s.webviews.length === 0+ s.webviews.length === 0 &&+ (!windowsTray || !s.tray_registered));} catch {return false;@@ -202,7 +231,12 @@ assert.deepEqual(await request(control, "/e2e/search-only/reopen", "POST");await until(async () => {const s = await state();- return !s.search_only && s.capture_running && s.capture_intended;+ return (+ !s.search_only &&+ s.capture_running &&+ s.capture_intended &&+ s.tray_registered+ );}, "Manual reopen after an updater restart resumes capture");const recordingBeforeUpdate = await state();await request(control, "/e2e/search-only/restart", "POST");diff --git a/apps/screenpipe-app-tauri/src-tauri/src/main.rs b/apps/screenpipe-app-tauri/src-tauri/src/main.rsindex c05223d8d..a24619ad5 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/main.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/main.rs@@ -1488,6 +1488,10 @@ async fn main() {std::io::Error::other(e)})?;let search_only_startup = crate::search_only::initialize(from_autostart);+ #[cfg(target_os = "windows")]+ if search_only_startup {+ tray::sync_search_visibility(&app_handle)?;+ }#[cfg(feature = "e2e")]e2e::seeds::apply_settings(app.handle(), &mut store);@@ -2271,10 +2275,8 @@ async fn main() {app_handle.manage(update_manager.clone()); // Register for state::<Arc<UpdatesManager>>()// Setup tray- if let Some(_) = app_handle.tray_by_id("screenpipe_main") {- if let Err(e) = tray::setup_tray(&app_handle, update_manager.update_now_menu_item_ref()) {- error!("Failed to setup tray: {}", e);- }+ if let Err(e) = tray::setup_tray(&app_handle, update_manager.update_now_menu_item_ref()) {+ error!("Failed to setup tray: {}", e);}// Log tray icon position for diagnostics.diff --git a/apps/screenpipe-app-tauri/src-tauri/src/server.rs b/apps/screenpipe-app-tauri/src-tauri/src/server.rsindex 63cce4503..f850f5deb 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/server.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/server.rs@@ -381,6 +381,10 @@ pub async fn run_server(app_handle: tauri::AppHandle, port: u16) {.route("/e2e/search-only/resume", axum::routing::post(e2e_search_only_resume)).route("/e2e/search-only/stop-server", axum::routing::post(e2e_search_only_stop_server)).route("/e2e/search-only/restart", axum::routing::post(e2e_search_only_restart))+ .route(+ "/e2e/search-only/recreate-tray",+ axum::routing::post(e2e_search_only_recreate_tray),+ ).route("/e2e/updates/state", axum::routing::get(e2e_updates_state)).route("/e2e/updates/click", axum::routing::post(e2e_updates_click)).route(@@ -681,6 +685,8 @@ async fn e2e_search_only_state(State(state): State<ServerState>) -> impl IntoRes"capture_running": recording.capture.lock().await.is_some(),"webviews": app.webview_windows().keys().cloned().collect::<Vec<_>>(),"keep_search_after_quit": crate::search_only::keep_after_quit(app),+ "tray_registered": app.tray_by_id("screenpipe_main").is_some(),+ "platform": std::env::consts::OS,}))}@@ -721,6 +727,19 @@ async fn e2e_search_only_restart(State(state): State<ServerState>) -> impl IntoRJson(serde_json::json!({"result": result}))}+#[cfg(feature = "e2e")]+async fn e2e_search_only_recreate_tray(State(state): State<ServerState>) -> impl IntoResponse {+ crate::tray::recreate_tray(&state.app_handle);+ // This barrier runs after the queued recreation, so callers can inspect+ // the resulting native tray without guessing how long the main loop needs.+ let (tx, rx) = tokio::sync::oneshot::channel();+ let scheduled = state.app_handle.run_on_main_thread(move || {+ let _ = tx.send(());+ });+ let completed = scheduled.is_ok() && rx.await.is_ok();+ Json(serde_json::json!({"accepted": completed}))+}+/// Content-free updater state for the packaged e2e test: what the tray menu/// item says, whether a staged update exists, and where boot stands. No/// versions of anything private, no paths, no tokens.diff --git a/apps/screenpipe-app-tauri/src-tauri/src/tray.rs b/apps/screenpipe-app-tauri/src-tauri/src/tray.rsindex d4119d19d..37e4af7e4 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/tray.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/tray.rs@@ -1098,7 +1098,7 @@ pub fn remove_tray(app: &AppHandle) {if app_for_thread.tray_by_id("screenpipe_main").is_none() {return;}- info!("tray: removing icon (suppressed by enterprise policy)");+ info!("tray: removing suppressed icon");let _old = app_for_thread.remove_tray_by_id("screenpipe_main");drop(_old);});@@ -1134,6 +1134,11 @@ pub fn enforce_tray_visibility(app: &AppHandle) {remove_tray(app);return;}+ #[cfg(target_os = "windows")]+ if crate::search_only::is_active() {+ remove_tray(app);+ return;+ }let update_item = UPDATE_MENU_ITEM.lock()@@ -1257,6 +1262,19 @@ pub fn setup_tray(app: &AppHandle, update_item: Option<&tauri::menu::MenuItem<Wr/// Confirmed Quit leaves no tray UI. Reopening restores the same tray item./// Call on the main thread, including after a search-only updater relaunch.+#[cfg(target_os = "windows")]+pub(crate) fn sync_search_visibility(app: &AppHandle) -> Result<()> {+ if crate::search_only::is_active() {+ // tray-icon 0.23.1 registers hidden icons again on TaskbarCreated.+ // Remove the native object so an Explorer restart cannot resurrect it.+ remove_tray(app);+ } else if app.tray_by_id("screenpipe_main").is_none() {+ enforce_tray_visibility(app);+ }+ Ok(())+}++#[cfg(not(target_os = "windows"))]pub(crate) fn sync_search_visibility(app: &AppHandle) -> Result<()> {if let Some(tray) = app.tray_by_id("screenpipe_main") {tray.set_visible(!crate::search_only::is_active())?;@@ -1312,7 +1330,16 @@ fn recreate_tray_on_main_thread(app: &AppHandle) {// the next poll. Take it down instead and stop.if tray_suppressed_by_policy() {if app.tray_by_id("screenpipe_main").is_some() {- info!("recreate_tray: suppressed by enterprise policy, removing instead");+ info!("recreate_tray: tray suppressed, removing instead");+ let _old = app.remove_tray_by_id("screenpipe_main");+ drop(_old);+ }+ return;+ }+ #[cfg(target_os = "windows")]+ if crate::search_only::is_active() {+ if app.tray_by_id("screenpipe_main").is_some() {+ info!("recreate_tray: search-only, removing instead");let _old = app.remove_tray_by_id("screenpipe_main");drop(_old);}