[fix] errors with default empty steam users + loading process
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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 = [] }
|
||||
|
||||
|
||||
@@ -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>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ export default function Page() {
|
||||
steam.setCsDir(e.target.value)
|
||||
}}
|
||||
/>
|
||||
<p>当前用户64位SteamID:{steam.currentUser().steamID64}</p>
|
||||
<p>当前用户64位SteamID:{steam.currentUser()?.steamID64}</p>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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>
|
||||
)
|
||||
|
||||
@@ -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 = () => {
|
||||
|
||||
Reference in New Issue
Block a user