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(updates): survive boot-time webview race, hydrate banner on mount
Louis Beaumont68a7b8f4a191
diff --git a/apps/screenpipe-app-tauri/app/home/page.tsx b/apps/screenpipe-app-tauri/app/home/page.tsxindex ae0e0f859..b4cb60236 100644--- a/apps/screenpipe-app-tauri/app/home/page.tsx+++ b/apps/screenpipe-app-tauri/app/home/page.tsx@@ -30,7 +30,7 @@ import { useChatStore, type SessionStatus } from "@/lib/stores/chat-store";import { useOverlayData } from "@/app/shortcut-reminder/use-overlay-data";import { cn } from "@/lib/utils";import { AppSidebar, SidebarProvider, useSidebarContext } from "@/components/app-sidebar";-import { UpdateBanner, useUpdateListener } from "@/components/update-banner";+import { UpdateBanner } from "@/components/update-banner";import { usePlatform } from "@/lib/hooks/use-platform";import { useIsFullscreen } from "@/lib/hooks/use-is-fullscreen";import { FeedbackSection } from "@/components/settings/feedback-section";@@ -88,7 +88,6 @@ const SETTINGS_SECTIONS = new Set<string>([]);function HomeContent() {- useUpdateListener();const router = useRouter();const { isMac } = usePlatform();// In fullscreen, macOS hides the traffic lights — collapse thediff --git a/apps/screenpipe-app-tauri/app/overlay/page.tsx b/apps/screenpipe-app-tauri/app/overlay/page.tsxindex fb625ed30..41804684c 100644--- a/apps/screenpipe-app-tauri/app/overlay/page.tsx+++ b/apps/screenpipe-app-tauri/app/overlay/page.tsx@@ -19,7 +19,7 @@ import { useHealthCheck } from "@/lib/hooks/use-health-check";import { commands } from "@/lib/utils/tauri";import localforage from "localforage";import { LoginDialog } from "@/components/login-dialog";-import { UpdateBanner, useUpdateListener } from "@/components/update-banner";+import { UpdateBanner } from "@/components/update-banner";import { useIsEnterpriseBuild } from "@/lib/hooks/use-is-enterprise-build";import { ModelDownloadTracker } from "@/components/model-download-tracker";import Timeline from "@/components/rewind/timeline";@@ -90,9 +90,6 @@ export default function OverlayPage() {const [logsSent, setLogsSent] = useState(false);const isProcessingRef = useRef(false);- // Listen for update events from Rust backend- useUpdateListener();-// Optimistic UI: track if user has any data (cached or live)const { frames, isConnected, loadFromCache } = useTimelineStore();const [hasAnyData, setHasAnyData] = useState(false);diff --git a/apps/screenpipe-app-tauri/app/providers.tsx b/apps/screenpipe-app-tauri/app/providers.tsxindex 370ea1220..f283ee212 100644--- a/apps/screenpipe-app-tauri/app/providers.tsx+++ b/apps/screenpipe-app-tauri/app/providers.tsx@@ -14,6 +14,18 @@ import { AuthGuard } from "@/lib/auth-guard";import { forwardRef } from "react";import { NuqsAdapter } from "nuqs/adapters/next/app";import { invoke } from "@tauri-apps/api/core";+import { useUpdateListener } from "@/components/update-banner";++/// Global mount point for the updater event listener. Lives here (not in+/// per-page hooks) so the listener is registered for the lifetime of the+/// app — the `update-available` event fires once when the bundle download+/// completes, and if the listener wasn't mounted at that moment the banner+/// would never appear. The hook also hydrates from `get_pending_update` on+/// mount so a late-mounting webview still picks up an event it missed.+function UpdateListenerMount() {+ useUpdateListener();+ return null;+}export const Providers = forwardRef<HTMLDivElement,@@ -102,6 +114,7 @@ export const Providers = forwardRef<<ThemeProvider defaultTheme="system" storageKey="screenpipe-ui-theme"><ChangelogDialogProvider><PermissionMonitorProvider>+ <UpdateListenerMount /><PostHogProvider client={posthog}>{children}</PostHogProvider></PermissionMonitorProvider></ChangelogDialogProvider>diff --git a/apps/screenpipe-app-tauri/components/update-banner.tsx b/apps/screenpipe-app-tauri/components/update-banner.tsxindex 75039bcf0..79ae23c55 100644--- a/apps/screenpipe-app-tauri/components/update-banner.tsx+++ b/apps/screenpipe-app-tauri/components/update-banner.tsx@@ -251,7 +251,19 @@ export function UpdateBanner({ className, compact = false, variant = "default" });}-// Hook to listen for update events from Rust+interface PendingUpdateSnapshot {+ version: string;+ body: string;+ downloaded: boolean;+ auth_required: boolean;+}++// Hook to listen for update events from Rust.+// Mounted globally in app/providers.tsx so it survives route changes and+// catches the `update-available` event regardless of which page is open+// when the download finishes. On mount, it also pulls the current pending+// state from Rust so it can recover if the event fired before this hook+// registered (boot-time webview race).export function useUpdateListener() {const { setIsVisible, setUpdateInfo, setAuthRequired } = useUpdateBanner();@@ -277,6 +289,22 @@ export function useUpdateListener() {unlistenAuth = await listen<AuthRequiredInfo>("update-auth-required", (event) => {setAuthRequired(event.payload);});++ // Hydrate from Rust in case the event fired before we mounted.+ try {+ const pending = await invoke<PendingUpdateSnapshot | null>("get_pending_update");+ if (pending) {+ if (pending.auth_required) {+ setAuthRequired({ version: pending.version, message: "sign in to get the latest update" });+ } else if (pending.downloaded) {+ setUpdateInfo({ version: pending.version, body: pending.body });+ setIsVisible(true);+ }+ }+ } catch (e) {+ // Command not registered yet (older Rust side) or app not ready.+ // Fall back to event-driven path silently.+ }};setupListeners();diff --git a/apps/screenpipe-app-tauri/src-tauri/src/main.rs b/apps/screenpipe-app-tauri/src-tauri/src/main.rsindex 39857cc44..53b3d1c89 100755--- a/apps/screenpipe-app-tauri/src-tauri/src/main.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/main.rs@@ -1013,6 +1013,7 @@ async fn main() {.invoke_handler(tauri::generate_handler![commands::is_enterprise_build_cmd,enterprise_install_metadata::get_enterprise_install_metadata,+ updates::get_pending_update,commands::get_local_api_config,commands::regenerate_api_auth_key,commands::set_api_auth_key,diff --git a/apps/screenpipe-app-tauri/src-tauri/src/updates.rs b/apps/screenpipe-app-tauri/src-tauri/src/updates.rsindex f91df1046..0a11ffc1a 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/updates.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/updates.rs@@ -151,6 +151,19 @@ fn enterprise_updates_managed_locally(app: &tauri::AppHandle) -> bool {}}+/// Snapshot of a pending update, exposed to the frontend via+/// `get_pending_update`. The banner queries this on mount so it can hydrate+/// state even when the `update-available` event fires before React mounts.+#[derive(Clone, serde::Serialize)]+pub struct PendingUpdateSnapshot {+ pub version: String,+ pub body: String,+ /// True once the bundle is downloaded and the app is ready to restart.+ pub downloaded: bool,+ /// True when download failed with 401/403 — user must sign in.+ pub auth_required: bool,+}+pub struct UpdatesManager {interval: Duration,update_available: Arc<Mutex<bool>>,@@ -158,6 +171,11 @@ pub struct UpdatesManager {/// None for enterprise builds (no in-app update UI).update_menu_item: Option<MenuItem<Wry>>,update_installed: Arc<Mutex<bool>>,+ /// Latest pending update info, mirrored to the frontend on demand. None+ /// until an update is detected; populated before download, then flipped+ /// to downloaded=true once the bundle lands. Survives webview-mount+ /// races that would otherwise lose the `update-available` event.+ pending_update: Arc<Mutex<Option<PendingUpdateSnapshot>>>,/// Prevents concurrent check_for_updates calls (boot check + periodic race)is_checking: AtomicBool,}@@ -183,6 +201,7 @@ impl UpdatesManager {interval: Duration::from_secs(interval_minutes * 60),update_available: Arc::new(Mutex::new(false)),update_installed: Arc::new(Mutex::new(false)),+ pending_update: Arc::new(Mutex::new(None)),app: app.clone(),update_menu_item,is_checking: AtomicBool::new(false),@@ -289,6 +308,12 @@ impl UpdatesManager {}if let Ok(Some(update)) = check_result {*self.update_available.lock().await = true;+ *self.pending_update.lock().await = Some(PendingUpdateSnapshot {+ version: update.version.clone(),+ body: update.body.clone().unwrap_or_default(),+ downloaded: false,+ auth_required: false,+ });let auto_update = SettingsStore::get(&self.app).ok()@@ -391,6 +416,9 @@ impl UpdatesManager {match download_result {Ok(_) => {*self.update_installed.lock().await = true;+ if let Some(snap) = self.pending_update.lock().await.as_mut() {+ snap.downloaded = true;+ }if let Some(ref item) = self.update_menu_item {item.set_enabled(true)?;item.set_text("Restart to update")?;@@ -404,6 +432,9 @@ impl UpdatesManager {|| err_str.contains("Forbidden"){warn!("update download requires authentication: {}", err_str);+ if let Some(snap) = self.pending_update.lock().await.as_mut() {+ snap.auth_required = true;+ }let _ = self.app.emit("update-auth-required",serde_json::json!({@@ -514,6 +545,12 @@ impl UpdatesManager {*self.update_installed.lock().await}+ /// Read the current pending update snapshot, for the frontend banner to+ /// hydrate when its listener mounts late and misses the event.+ pub async fn pending_update_snapshot(&self) -> Option<PendingUpdateSnapshot> {+ self.pending_update.lock().await.clone()+ }+/// Show dialog explaining auto-updates are not available for source buildsasync fn show_source_build_dialog(&self) -> Result<(), Box<dyn std::error::Error>> {let (tx, rx) = oneshot::channel();@@ -666,6 +703,18 @@ fn check_whats_new(app: &tauri::AppHandle) {});}+/// Hydrate the frontend banner state on mount. The `update-available` event+/// is broadcast once when the download completes — if the React app isn't+/// mounted yet (boot race) or the listener lives on a route the user hasn't+/// visited yet, that event is lost. The banner calls this command on mount+/// to pick up state it may have missed.+#[tauri::command]+pub async fn get_pending_update(+ state: tauri::State<'_, Arc<UpdatesManager>>,+) -> Result<Option<PendingUpdateSnapshot>, ()> {+ Ok(state.pending_update_snapshot().await)+}+pub fn start_update_check(app: &tauri::AppHandle,interval_minutes: u64,