[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

BIN
bun.lockb

Binary file not shown.

View File

@@ -11,6 +11,7 @@
"next-build": "next build",
"tauri": "tauri",
"build": "tauri build",
"build-fast": "tauri build -b nsis -- --profile dev",
"dev": "tauri dev",
"lint": "next lint",
"fix": "next lint --fix"
@@ -36,7 +37,6 @@
"@types/throttle-debounce": "^5.0.2",
"ahooks": "^3.8.4",
"framer-motion": "^12.5.0",
"jotai": "^2.12.2",
"next": "15.2.2",
"next-themes": "^0.4.6",
"react": "^19.0.0",

View File

@@ -17,6 +17,10 @@ opt-level = "s" # Optimize for binary size
strip = true # Remove debug symbols
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[profile.dev]
opt-level = 0 # 关闭优化
debug = true # 保留调试信息
[build-dependencies]
tauri-build = { version = "2.1.0", features = [] }

View File

@@ -10,7 +10,7 @@ export default function Page() {
<p>{steam.state.cs2Dir}</p>
<p>Steam路径有效{steam.state.steamDirValid ? "是" : "否"}</p>
<p>{steam.state.cs2DirValid ? "是" : "否"}</p>
<p>Steam账号{steam.currentUser().accountName}</p>
<p>Steam账号{steam.currentUser()?.accountName || " "}</p>
</div>
)
}

View File

@@ -39,7 +39,7 @@ export default function Page() {
steam.setCsDir(e.target.value)
}}
/>
<p>64SteamID{steam.currentUser().steamID64}</p>
<p>64SteamID{steam.currentUser()?.steamID64}</p>
</div>
</div>
)

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>
)

View File

@@ -12,16 +12,7 @@ const defaultValue = {
cs2DirValid: false,
steamDirChecking: false,
cs2DirChecking: false,
users: [
{
steamID64: "76561198052315353",
steamID32: "46157676",
accountName: "wrr_account",
personaName: "wrr",
recent: 0,
avatar: "",
},
] as SteamUser[],
users: [] as SteamUser[],
}
export const steamStore = store(
@@ -51,7 +42,7 @@ export const useSteamStore = () => {
}
const cs2BaseDir = () => {
return path.normalize(`${steamStore.state.cs2Dir.replaceAll("\\", "/") }/../../..`)
return path.normalize(`${steamStore.state.cs2Dir.replaceAll("\\", "/")}/../../..`)
}
const setDir = (dir: string) => {
@@ -97,7 +88,7 @@ const checkCs2DirValid = async () => {
}
const currentUser = () => {
return steamStore.state.users[0] || defaultValue.users[0]
return steamStore.state.users.at(0) || undefined
}
const resetSteamStore = () => {