[feat] loading state using init watch
This commit is contained in:
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user