2024-09-27 10:38:40 +08:00
|
|
|
import { tauriStore } from '@/utils/persist'
|
2024-09-21 02:25:23 +08:00
|
|
|
import { create } from 'zustand'
|
2024-09-27 10:38:40 +08:00
|
|
|
import { createJSONStorage, persist } from 'zustand/middleware'
|
2024-09-21 02:25:23 +08:00
|
|
|
|
2024-09-27 10:38:40 +08:00
|
|
|
interface ToolState {
|
2024-09-21 02:25:23 +08:00
|
|
|
launchOptions: string[]
|
|
|
|
|
launchIndex: number
|
|
|
|
|
powerPlan: number
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-27 10:38:40 +08:00
|
|
|
interface ToolAction {
|
|
|
|
|
setLaunchOption: (option: string, index: number) => void
|
|
|
|
|
setLaunchOptions: (options: string[]) => void
|
|
|
|
|
setLaunchIndex: (index: number) => void
|
|
|
|
|
setPowerPlan: (index: number) => void
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const STORE_NAME = "tool"
|
|
|
|
|
const { /* store, */ storage } = tauriStore(STORE_NAME)
|
|
|
|
|
|
|
|
|
|
const useToolStore = create<ToolState & ToolAction>()(
|
|
|
|
|
persist(
|
|
|
|
|
(set/* , get */) => ({
|
|
|
|
|
launchOptions: ["-high -refresh 120 -novid -nojoy -tickrate 128 +cl_cmdrate 128 +cl_updaterate 128 +exec auto.cfg +test", "", ""],
|
|
|
|
|
launchIndex: 0,
|
|
|
|
|
powerPlan: 0,
|
|
|
|
|
setLaunchOption: (option: string, index: number) => set((state) => ({ launchOptions: [...state.launchOptions.slice(0, index), option, ...state.launchOptions.slice(index + 1)] })),
|
|
|
|
|
setLaunchOptions: (options: string[]) => set(() => ({ launchOptions: options })),
|
|
|
|
|
setLaunchIndex: (index: number) => set(() => ({ launchIndex: index })),
|
|
|
|
|
setPowerPlan: (index: number) => set(() => ({ powerPlan: index }))
|
|
|
|
|
}),
|
|
|
|
|
{
|
|
|
|
|
name: STORE_NAME, // 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 useToolStore
|