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

71 lines
1.6 KiB
TypeScript
Raw Normal View History

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