diff --git a/src/store/app.ts b/src/store/app.ts index e91f562..d9717fa 100644 --- a/src/store/app.ts +++ b/src/store/app.ts @@ -19,7 +19,7 @@ interface AppAction { } const STORE_NAME = "app" -const { /* store, */ storage } = tauriStore(STORE_NAME) +const { /* store, */ storage } = await tauriStore(STORE_NAME) const useAppStore = create()( persist( diff --git a/src/store/steam.ts b/src/store/steam.ts index b735dfb..2fe7cd4 100644 --- a/src/store/steam.ts +++ b/src/store/steam.ts @@ -31,7 +31,7 @@ interface SteamAction { } const STORE_NAME = "steam" -const { /* store, */ storage } = tauriStore(STORE_NAME) +const { /* store, */ storage } = await tauriStore(STORE_NAME) const useSteamStore = create()( persist( diff --git a/src/store/tool.ts b/src/store/tool.ts index 3cf1bf4..e288243 100644 --- a/src/store/tool.ts +++ b/src/store/tool.ts @@ -16,7 +16,7 @@ interface ToolAction { } const STORE_NAME = "tool" -const { /* store, */ storage } = tauriStore(STORE_NAME) +const { /* store, */ storage } = await tauriStore(STORE_NAME) const useToolStore = create()( persist( diff --git a/src/utils/persist.ts b/src/utils/persist.ts index 0fe80f4..a740ed3 100644 --- a/src/utils/persist.ts +++ b/src/utils/persist.ts @@ -6,31 +6,19 @@ import type { StateStorage } from "zustand/middleware" // 节流设置 export const THROTTLE_TIME = 300 -export const THROTTLE_TIME_STORE = 5000 +export const THROTTLE_TIME_STORE = 2000 export const THROTTLE_LEADING = true export const THROTTLE_TRAILING = true // 自定义Store覆盖get, set等方法,以适应tauri+zustand export async function tauriStore(name: string) { - const store = await Store.load(`${name || "store"}.settings.json`) - - // 自动保存 - const autoSave = throttle( - THROTTLE_TIME_STORE, - async () => { - await store.save() - }, - { - noTrailing: !THROTTLE_TRAILING, - noLeading: !THROTTLE_LEADING, - }, - ) + const store = await Store.load(`${name || "store"}.settings.json`, { + autoSave: THROTTLE_TIME_STORE, + }) const doSet = throttle( THROTTLE_TIME, - async (key: string, value: unknown) => { - await store.set(key, value) - }, + async (key: string, value: unknown) => await store.set(key, value), { noTrailing: !THROTTLE_TRAILING, noLeading: !THROTTLE_LEADING, @@ -39,12 +27,9 @@ export async function tauriStore(name: string) { const set = (key: string, value: unknown) => { doSet(key, value) - autoSave() } - const get = (key: string) => { - return store.get(key) - } + const get = async (key: string) => await store.get(key) // 自定义存储对象 const storage: StateStorage = { @@ -62,5 +47,5 @@ export async function tauriStore(name: string) { }, } - return { store, get, set, autoSave, storage } + return { store, get, set, storage } } diff --git a/tsconfig.json b/tsconfig.json index f2fff43..3dffd80 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,7 +12,7 @@ "forceConsistentCasingInFileNames": true, "noEmit": true, "esModuleInterop": true, - "module": "esnext", + "module": "ESNext", "moduleResolution": "node", "resolveJsonModule": true, "isolatedModules": true,