[feat] loading state using init watch

This commit is contained in:
Purp1e
2025-03-21 02:52:09 +08:00
parent c2c1a4c368
commit 90c6492b9c
2 changed files with 32 additions and 6 deletions

View File

@@ -10,6 +10,10 @@ import { dir } from "console"
const defaultValue = {
steamDir: "C:\\Program Files (x86)\\Steam",
cs2Dir: "",
steamDirValid: false,
cs2DirValid: false,
steamDirChecking: false,
cs2DirChecking: false,
users: [
{
steamID64: "76561198052315353",
@@ -20,8 +24,6 @@ const defaultValue = {
avatar: "",
},
] as SteamUser[],
steamDirValid: false,
cs2DirValid: false,
}
export const steamStore = store(
@@ -64,16 +66,32 @@ const setCs2DirValid = (valid: boolean) => {
steamStore.state.cs2DirValid = valid
}
const SetSteamDirChecking = (checking: boolean) => {
steamStore.state.steamDirChecking = checking
}
const SetCs2DirChecking = (checking: boolean) => {
steamStore.state.cs2DirChecking = checking
}
const checkSteamDirValid = async () => {
SetSteamDirChecking(true)
const pathExist = await invoke<boolean>("check_path", { path: steamStore.state.steamDir })
console.log("steamDir", steamStore.state.steamDir, "pathExist", pathExist)
setSteamDirValid(pathExist)
setTimeout(() => {
SetSteamDirChecking(false)
}, 500)
}
const checkCs2DirValid = async () => {
SetCs2DirChecking(true)
const pathExist = await invoke<boolean>("check_path", { path: steamStore.state.cs2Dir })
console.log("cs2Dir", steamStore.state.cs2Dir, "pathExist", pathExist)
setCs2DirValid(pathExist)
setTimeout(() => {
SetCs2DirChecking(false)
}, 500)
}
const currentUser = () => {
@@ -86,4 +104,6 @@ const resetSteamStore = () => {
setUsers(defaultValue.users)
setSteamDirValid(defaultValue.steamDirValid)
setCs2DirValid(defaultValue.cs2DirValid)
SetSteamDirChecking(defaultValue.steamDirChecking)
SetCs2DirChecking(defaultValue.cs2DirChecking)
}