[feat] use heroui + setup persistore + setup toast

todo: fix launchoption problem
This commit is contained in:
Purp1e
2025-03-12 11:22:32 +08:00
parent 2ef6d2c298
commit 9103150562
27 changed files with 745 additions and 264 deletions

View File

@@ -1,51 +1,36 @@
import { tauriStore } from "@/utils/old"
import { create } from "zustand"
import { createJSONStorage, persist } from "zustand/middleware"
import { store } from 'tauri-plugin-valtio';
import { DEFAULT_STORE_CONFIG } from '.';
interface ToolState {
launchOptions: string[]
launchIndex: number
powerPlan: number
const defaultValue = {
launchOptions: [] as string[],
launchIndex: 0,
powerPlan: 0
}
interface ToolAction {
setLaunchOption: (option: string, index: number) => void
setLaunchOptions: (options: string[]) => void
setLaunchIndex: (index: number) => void
setPowerPlan: (index: number) => void
export const toolStore = store('tool', { ...defaultValue }, DEFAULT_STORE_CONFIG);
export const setLaunchOption = (option: string, index: number) => {
toolStore.state.launchOptions = [
...toolStore.state.launchOptions.slice(0, index),
option,
...toolStore.state.launchOptions.slice(index + 1)
]
}
const STORE_NAME = "tool"
const { /* store, */ storage } = await tauriStore(STORE_NAME)
export const setLaunchOptions = (options: string[]) => {
toolStore.state.launchOptions = options
}
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
},
),
)
export const setLaunchIndex = (index: number) => {
toolStore.state.launchIndex = index
}
export default useToolStore
export const setPowerPlan = (plan: number) => {
toolStore.state.powerPlan = plan
}
export const resetToolStore = () => {
toolStore.state.launchOptions = defaultValue.launchOptions
toolStore.state.launchIndex = defaultValue.launchIndex
toolStore.state.powerPlan = defaultValue.powerPlan
}