Files
cstb-next/src/store/app.ts

48 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-11-11 10:04:00 +08:00
import { tauriStore } from "@/utils/persist"
import { create } from "zustand"
import { createJSONStorage, persist } from "zustand/middleware"
2024-09-26 16:58:40 +08:00
interface AppState {
2024-09-26 16:58:40 +08:00
version: string
hasUpdate: boolean
inited: boolean
notice: string
useMirror: boolean
}
interface AppAction {
2024-09-26 16:58:40 +08:00
setVersion: (version: string) => void
setHasUpdate: (hasUpdate: boolean) => void
setInited: (hasInit: boolean) => void
setNotice: (notice: string) => void
setUseMirror: (useMirror: boolean) => void
}
const STORE_NAME = "app"
const { /* store, */ storage } = tauriStore(STORE_NAME)
2024-09-26 16:58:40 +08:00
const useAppStore = create<AppState & AppAction>()(
2024-09-26 16:58:40 +08:00
persist(
2024-11-11 10:04:00 +08:00
(set /* , get */) => ({
2024-09-26 16:58:40 +08:00
version: "0.0.1",
hasUpdate: false,
inited: false,
2024-09-26 16:58:40 +08:00
notice: "Man! What can I say?",
useMirror: true,
setVersion: (version: string) => set(() => ({ version: version })),
2024-11-11 10:04:00 +08:00
setHasUpdate: (hasUpdate: boolean) =>
set(() => ({ hasUpdate: hasUpdate })),
setInited: (inited: boolean) => set(() => ({ inited: inited })),
setNotice: (notice: string) => set(() => ({ notice: notice })),
2024-11-11 10:04:00 +08:00
setUseMirror: (useMirror: boolean) =>
set(() => ({ useMirror: useMirror })),
2024-09-26 16:58:40 +08:00
}),
{
name: STORE_NAME, // name of item in the storage (must be unique)
2024-09-26 16:58:40 +08:00
storage: createJSONStorage(() => storage), // (optional) by default the 'localStorage' is used
},
2024-11-11 10:04:00 +08:00
),
)
2024-11-11 10:04:00 +08:00
export default useAppStore