[feat] global watch dir and set better check logic
todo: first time check failed should let user manually click
This commit is contained in:
@@ -10,6 +10,5 @@ export async function init() {
|
||||
await toolStore.start()
|
||||
await steamStore.start()
|
||||
const appConfigDirPath = await appConfigDir()
|
||||
console.log(appConfigDirPath)
|
||||
await setStoreCollectionPath(path.resolve(appConfigDirPath, "cstb"))
|
||||
}
|
||||
|
||||
@@ -2,10 +2,14 @@ import type { SteamUser } from "@/types/steam"
|
||||
import { store } from "@tauri-store/valtio"
|
||||
import { DEFAULT_STORE_CONFIG } from "./config"
|
||||
import { useSnapshot } from "valtio"
|
||||
import { useEffect } from "react"
|
||||
import { addToast } from "@heroui/react"
|
||||
import { invoke } from "@tauri-apps/api/core"
|
||||
import { dir } from "console"
|
||||
|
||||
const defaultValue = {
|
||||
dir: "C:\\Program Files (x86)\\Steam",
|
||||
csDir: "",
|
||||
steamDir: "C:\\Program Files (x86)\\Steam",
|
||||
cs2Dir: "",
|
||||
users: [
|
||||
{
|
||||
steamID64: "76561198052315353",
|
||||
@@ -16,8 +20,8 @@ const defaultValue = {
|
||||
avatar: "",
|
||||
},
|
||||
] as SteamUser[],
|
||||
isDirValid: false,
|
||||
isCsDirValid: false,
|
||||
steamDirValid: false,
|
||||
cs2DirValid: false,
|
||||
}
|
||||
|
||||
export const steamStore = store(
|
||||
@@ -35,27 +39,41 @@ export const useSteamStore = () => {
|
||||
setDir,
|
||||
setCsDir,
|
||||
setUsers,
|
||||
setIsDirValid,
|
||||
setIsCsDirValid,
|
||||
setSteamDirValid,
|
||||
setCs2DirValid,
|
||||
checkSteamDirValid,
|
||||
checkCs2DirValid,
|
||||
currentUser,
|
||||
resetSteamStore,
|
||||
}
|
||||
}
|
||||
|
||||
const setDir = (dir: string) => {
|
||||
steamStore.state.dir = dir
|
||||
steamStore.state.steamDir = dir
|
||||
}
|
||||
const setCsDir = (dir: string) => {
|
||||
steamStore.state.csDir = dir
|
||||
steamStore.state.cs2Dir = dir
|
||||
}
|
||||
const setUsers = (users: SteamUser[]) => {
|
||||
steamStore.state.users = users
|
||||
}
|
||||
const setIsDirValid = (valid: boolean) => {
|
||||
steamStore.state.isDirValid = valid
|
||||
const setSteamDirValid = (valid: boolean) => {
|
||||
steamStore.state.steamDirValid = valid
|
||||
}
|
||||
const setIsCsDirValid = (valid: boolean) => {
|
||||
steamStore.state.isCsDirValid = valid
|
||||
const setCs2DirValid = (valid: boolean) => {
|
||||
steamStore.state.cs2DirValid = valid
|
||||
}
|
||||
|
||||
const checkSteamDirValid = async () => {
|
||||
const pathExist = await invoke<boolean>("check_path", { path: steamStore.state.steamDir })
|
||||
console.log("steamDir", steamStore.state.steamDir, "pathExist", pathExist)
|
||||
setSteamDirValid(pathExist)
|
||||
}
|
||||
|
||||
const checkCs2DirValid = async () => {
|
||||
const pathExist = await invoke<boolean>("check_path", { path: steamStore.state.cs2Dir })
|
||||
console.log("cs2Dir", steamStore.state.cs2Dir, "pathExist", pathExist)
|
||||
setCs2DirValid(pathExist)
|
||||
}
|
||||
|
||||
const currentUser = () => {
|
||||
@@ -63,9 +81,9 @@ const currentUser = () => {
|
||||
}
|
||||
|
||||
const resetSteamStore = () => {
|
||||
setDir(defaultValue.dir)
|
||||
setCsDir(defaultValue.csDir)
|
||||
setDir(defaultValue.steamDir)
|
||||
setCsDir(defaultValue.cs2Dir)
|
||||
setUsers(defaultValue.users)
|
||||
setIsDirValid(defaultValue.isDirValid)
|
||||
setIsCsDirValid(defaultValue.isCsDirValid)
|
||||
}
|
||||
setSteamDirValid(defaultValue.steamDirValid)
|
||||
setCs2DirValid(defaultValue.cs2DirValid)
|
||||
}
|
||||
Reference in New Issue
Block a user