2024-09-21 02:25:23 +08:00
|
|
|
import { create } from 'zustand'
|
2024-09-26 16:58:40 +08:00
|
|
|
import { tauriStore } from '@/utils/persist'
|
|
|
|
|
import { createJSONStorage, persist } from 'zustand/middleware'
|
|
|
|
|
|
2024-09-21 02:25:23 +08:00
|
|
|
|
|
|
|
|
interface AppState {
|
2024-09-26 16:58:40 +08:00
|
|
|
version: string
|
2024-09-21 02:25:23 +08:00
|
|
|
hasUpdate: boolean
|
|
|
|
|
hasInit: boolean
|
|
|
|
|
notice: string
|
|
|
|
|
useMirror: boolean
|
2024-09-26 16:58:40 +08:00
|
|
|
setVersion: (version: string) => void
|
2024-09-21 02:25:23 +08:00
|
|
|
init: () => void
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-26 16:58:40 +08:00
|
|
|
const { /* store, */storage } = tauriStore("app-test")
|
|
|
|
|
|
|
|
|
|
const useAppStore = create<AppState>()(
|
|
|
|
|
persist(
|
|
|
|
|
(set, get) => ({
|
|
|
|
|
version: "0.0.1",
|
|
|
|
|
hasUpdate: false,
|
|
|
|
|
hasInit: false,
|
|
|
|
|
notice: "Man! What can I say?",
|
|
|
|
|
useMirror: true,
|
|
|
|
|
setVersion: (version: string) => set(() => ({ version: version })),
|
|
|
|
|
init: () => {
|
|
|
|
|
console.log('init')
|
|
|
|
|
console.log(get().version)
|
|
|
|
|
// const version = await store.get("version")
|
|
|
|
|
// set(() => ({ version: version }))
|
|
|
|
|
},
|
|
|
|
|
// increasePopulation: () => set((state) => ({ bears: state.bears + 1 })),
|
|
|
|
|
}),
|
|
|
|
|
{
|
|
|
|
|
name: 'app', // name of item in the storage (must be unique)
|
|
|
|
|
storage: createJSONStorage(() => storage), // (optional) by default the 'localStorage' is used
|
|
|
|
|
},
|
|
|
|
|
))
|
2024-09-21 02:25:23 +08:00
|
|
|
|
|
|
|
|
export default useAppStore
|