From 0596b02f198ebe43703c3702f45eb2f1acdda431 Mon Sep 17 00:00:00 2001 From: Adam <2363879+adamdotdevin@users.noreply.github.com> Date: Tue, 20 Jan 2026 05:06:05 -0600 Subject: chore: cleanup --- packages/desktop/src/index.tsx | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'packages/desktop') diff --git a/packages/desktop/src/index.tsx b/packages/desktop/src/index.tsx index d6ee121af..3b3002967 100644 --- a/packages/desktop/src/index.tsx +++ b/packages/desktop/src/index.tsx @@ -89,11 +89,26 @@ const createPlatform = (password: Accessor): Platform => ({ length(): Promise } - const WRITE_DEBOUNCE_MS = 250 + const WRITE_DEBOUNCE_MS = 250 - const storeCache = new Map>() - const apiCache = new Map Promise }>() - const memoryCache = new Map() + const storeCache = new Map>() + const apiCache = new Map Promise }>() + const memoryCache = new Map() + + const flushAll = async () => { + const apis = Array.from(apiCache.values()) + await Promise.all(apis.map((api) => api.flush().catch(() => undefined))) + } + + if ("addEventListener" in globalThis) { + const handleVisibility = () => { + if (document.visibilityState !== "hidden") return + void flushAll() + } + + window.addEventListener("pagehide", () => void flushAll()) + document.addEventListener("visibilitychange", handleVisibility) + } const createMemoryStore = () => { const data = new Map() -- cgit v1.2.3