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

72 lines
1.5 KiB
TypeScript
Raw Normal View History

2024-11-11 10:04:00 +08:00
import type { SteamUser } from "@/types/steam"
2025-03-12 22:20:06 +08:00
import { store } from "tauri-plugin-valtio"
import { DEFAULT_STORE_CONFIG } from "."
2025-03-17 11:48:30 +08:00
import { useSnapshot } from "valtio"
const defaultValue = {
dir: "C:\\Program Files (x86)\\Steam",
csDir: "",
2025-03-12 22:20:06 +08:00
users: [
{
steamID64: "76561198052315353",
steamID32: "STEAM_0:0:46157676",
accountName: "wrr",
personaName: "wrr",
recent: 0,
avatar: "",
},
] as SteamUser[],
isDirValid: false,
2025-03-12 22:20:06 +08:00
isCsDirValid: false,
}
2025-03-17 11:48:30 +08:00
2025-03-12 22:20:06 +08:00
export const steamStore = store(
"steam",
{ ...defaultValue },
DEFAULT_STORE_CONFIG,
)
2025-03-17 11:48:30 +08:00
export const useSteamStore = () => {
void steamStore.start
const state = useSnapshot(steamStore.state)
return {
state,
setDir,
setCsDir,
setUsers,
setIsDirValid,
setIsCsDirValid,
currentUser,
resetSteamStore,
}
}
const setDir = (dir: string) => {
2025-03-12 22:20:06 +08:00
steamStore.state.dir = dir
}
2025-03-17 11:48:30 +08:00
const setCsDir = (dir: string) => {
2025-03-12 22:20:06 +08:00
steamStore.state.csDir = dir
}
2025-03-17 11:48:30 +08:00
const setUsers = (users: SteamUser[]) => {
2025-03-12 22:20:06 +08:00
steamStore.state.users = users
}
2025-03-17 11:48:30 +08:00
const setIsDirValid = (valid: boolean) => {
2025-03-12 22:20:06 +08:00
steamStore.state.isDirValid = valid
}
2025-03-17 11:48:30 +08:00
const setIsCsDirValid = (valid: boolean) => {
2025-03-12 22:20:06 +08:00
steamStore.state.isCsDirValid = valid
}
2025-03-17 11:48:30 +08:00
const currentUser = () => {
return steamStore.state.users[0] || defaultValue.users[0]
}
2025-03-17 11:48:30 +08:00
const resetSteamStore = () => {
setDir(defaultValue.dir)
setCsDir(defaultValue.csDir)
setUsers(defaultValue.users)
setIsDirValid(defaultValue.isDirValid)
setIsCsDirValid(defaultValue.isCsDirValid)
2025-03-12 22:20:06 +08:00
}