diff options
| author | Adam <[email protected]> | 2026-01-20 05:06:05 -0600 |
|---|---|---|
| committer | Adam <[email protected]> | 2026-01-20 05:39:54 -0600 |
| commit | 0596b02f198ebe43703c3702f45eb2f1acdda431 (patch) | |
| tree | 4714034a023a4e33d59b11931671960ac2c871df /packages/desktop/src | |
| parent | 5145b72c4abd71d51d493d4ee3744fa979d36c8b (diff) | |
| download | opencode-0596b02f198ebe43703c3702f45eb2f1acdda431.tar.gz opencode-0596b02f198ebe43703c3702f45eb2f1acdda431.zip | |
chore: cleanup
Diffstat (limited to 'packages/desktop/src')
| -rw-r--r-- | packages/desktop/src/index.tsx | 23 |
1 files changed, 19 insertions, 4 deletions
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<string | null>): Platform => ({ length(): Promise<number> } - const WRITE_DEBOUNCE_MS = 250 + const WRITE_DEBOUNCE_MS = 250 - const storeCache = new Map<string, Promise<StoreLike>>() - const apiCache = new Map<string, AsyncStorage & { flush: () => Promise<void> }>() - const memoryCache = new Map<string, StoreLike>() + const storeCache = new Map<string, Promise<StoreLike>>() + const apiCache = new Map<string, AsyncStorage & { flush: () => Promise<void> }>() + const memoryCache = new Map<string, StoreLike>() + + 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<string, string>() |
