import { store } from "@tauri-store/valtio" import { useSnapshot } from "valtio" import { DEFAULT_STORE_CONFIG } from "./config" const defaultValue = { launchOptions: [ "-novid -high -freq 144 -fullscreen", "-novid -high -w 1920 -h 1080 -freq 144 -sw -noborder", "-novid -high -freq 144 -fullscreen -allow_third_party_software", ] as string[], launchIndex: 0, powerPlan: 0, } export const toolStore = store( "tool", { ...defaultValue }, DEFAULT_STORE_CONFIG, ) export const useToolStore = () => { void toolStore.start const state = useSnapshot(toolStore.state) return { state, store: toolStore, setLaunchOption, setLaunchOptions, setLaunchIndex, setPowerPlan, addLaunchOption, resetToolStore, } } const setLaunchOption = (option: string, index: number) => { toolStore.state.launchOptions = [ ...toolStore.state.launchOptions.slice(0, index), option, ...toolStore.state.launchOptions.slice(index + 1), ] } const setLaunchOptions = (options: string[]) => { toolStore.state.launchOptions = options } const setLaunchIndex = (index: number) => { toolStore.state.launchIndex = index } const setPowerPlan = (plan: number) => { toolStore.state.powerPlan = plan } const addLaunchOption = (option: string) => { // 限制最高10个 if (toolStore.state.launchOptions.length >= 10) { return } toolStore.state.launchOptions = [...toolStore.state.launchOptions, option] } const resetToolStore = () => { setLaunchOptions(defaultValue.launchOptions) setLaunchIndex(defaultValue.launchIndex) setPowerPlan(defaultValue.powerPlan) }