From 4a3ba58f65d12b4f7c7a97b42a5bb3bc0eb5f88b Mon Sep 17 00:00:00 2001 From: Adam <2363879+adamdotdevin@users.noreply.github.com> Date: Wed, 17 Dec 2025 13:10:57 -0600 Subject: chore: localStorage -> tauri store --- packages/desktop/src/utils/persist.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 packages/desktop/src/utils/persist.ts (limited to 'packages/desktop/src/utils') diff --git a/packages/desktop/src/utils/persist.ts b/packages/desktop/src/utils/persist.ts new file mode 100644 index 000000000..12b334f9f --- /dev/null +++ b/packages/desktop/src/utils/persist.ts @@ -0,0 +1,26 @@ +import { usePlatform } from "@/context/platform" +import { makePersisted } from "@solid-primitives/storage" +import { createResource, type Accessor } from "solid-js" +import type { SetStoreFunction, Store } from "solid-js/store" + +type InitType = Promise | string | null +type PersistedWithReady = [Store, SetStoreFunction, InitType, Accessor] + +export function persisted(key: string, store: [Store, SetStoreFunction]): PersistedWithReady { + const platform = usePlatform() + const [state, setState, init] = makePersisted(store, { name: key, storage: platform.storage?.() ?? localStorage }) + + // Create a resource that resolves when the store is initialized + // This integrates with Suspense and provides a ready signal + const isAsync = init instanceof Promise + const [ready] = createResource( + () => init, + async (initValue) => { + if (initValue instanceof Promise) await initValue + return true + }, + { initialValue: !isAsync }, + ) + + return [state, setState, init, () => ready() === true] +} -- cgit v1.2.3