[fix] errors with default empty steam users + loading process

This commit is contained in:
Purp1e
2025-03-23 02:27:21 +08:00
parent 2247640dc1
commit 7e2e556485
8 changed files with 27 additions and 30 deletions

View File

@@ -32,6 +32,7 @@ export function Prepare() {
const app = useAppStore()
const router = useRouter()
const [loading, setLoading] = useState(true)
const [inited, setInited] = useState(false)
const [, setSteamDir] = useState(steam.state.steamDir)
const [, setCs2Dir] = useState(steam.state.cs2Dir)
@@ -41,31 +42,32 @@ export function Prepare() {
await steam.store.start()
await app.store.start()
if (!app.state.inited) await autoGetPaths()
setInited(true)
}
void init()
}, [])
// valid变动后调整State
const debounceValid = useDebounce(steam.state.steamDirValid && steam.state.cs2DirValid, {
wait: 500,
leading: true,
trailing: true,
maxWait: 2500,
})
const [checkCount, setCheckCount] = useState(0)
useEffect(() => {
setCheckCount((prev) => (prev >= 10 ? 10 : prev + 1))
// console.log(checkCount, "触发", debounceValid, steam.state.steamDir, steam.state.cs2Dir)
if (checkCount < 2 && debounceValid && app.state.inited) {
setTimeout(() => {
router.push("/home")
}, 800)
// console.log(checkCount, "触发", steam.state.steamDir, steam.state.cs2Dir, app.state.inited)
if (checkCount <= 2) {
if (steam.state.steamDir && steam.state.cs2Dir && app.state.inited) {
setTimeout(() => {
router.push("/home")
}, 300)
} else {
setTimeout(() => {
setLoading(false)
}, 1000)
}
} else {
setTimeout(() => {
setLoading(false)
}, 1000)
}, 1200)
}
}, [debounceValid])
}, [inited])
const handleSelectSteamDir = async () => {
const selected = await open({

View File

@@ -6,10 +6,10 @@ const Header = () => {
return (
<div className="pt-6 select-none pb-9" data-tauri-drag-region>
<h1 className="text-xl font-medium tracking-wide w-fit">
{steam.currentUser().personaName || 'CS工具箱'}
{steam.currentUser()?.personaName || 'CS工具箱'}
</h1>
<p className="text-sm font-light tracking-wide text-zinc-400 w-fit">
{steam.currentUser().accountName || '本周使用CS工具箱 114 小时'}
{steam.currentUser()?.accountName || '本周使用CS工具箱 114 小时'}
</p>
</div>
)