diff --git a/bun.lockb b/bun.lockb index 61fa940..f151ae5 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 6d6ad7f..dc4cae0 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "@tauri-apps/plugin-store": "^2.2.0", "@tauri-store/valtio": "^2.0.0", "@types/throttle-debounce": "^5.0.2", - "@uidotdev/usehooks": "^2.4.1", + "ahooks": "^3.8.4", "framer-motion": "^12.5.0", "jotai": "^2.12.2", "next": "15.2.2", diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 80dda2e..59188e1 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -4,7 +4,7 @@ import { useEffect } from "react" import "./globals.css" import Providers from "./providers" import { init } from "@/store" -import { useDebounce } from "@uidotdev/usehooks" +import { useDebounce } from "ahooks" export default function RootLayout({ children }: { children: React.ReactNode }) { useEffect(() => { @@ -13,8 +13,8 @@ export default function RootLayout({ children }: { children: React.ReactNode }) // 检测steam路径和游戏路径是否有效 const steam = useSteamStore() - const debounceSteamDir = useDebounce(steam.state.steamDir, 500) - const debounceCs2Dir = useDebounce(steam.state.cs2Dir, 500) + const debounceSteamDir = useDebounce(steam.state.steamDir, {wait: 500, leading: true, trailing: true, maxWait: 2500}) + const debounceCs2Dir = useDebounce(steam.state.cs2Dir, {wait: 500, leading: true, trailing: true, maxWait: 2500}) useEffect(() => { void steam.checkSteamDirValid() }, [debounceSteamDir]) diff --git a/src/components/cstb/Prepare.tsx b/src/components/cstb/Prepare.tsx index dbea3a2..fe95df8 100644 --- a/src/components/cstb/Prepare.tsx +++ b/src/components/cstb/Prepare.tsx @@ -1,10 +1,11 @@ -import { addToast, Button, Chip, Spinner } from "@heroui/react" +import { addToast, Button, Chip, Input, Spinner } from "@heroui/react" import { useRouter } from "next/navigation" import { useEffect, useState } from "react" import { useSteamStore } from "@/store/steam" import { open } from "@tauri-apps/plugin-dialog" import { invoke } from "@tauri-apps/api/core" import { onOpenUrl } from "@tauri-apps/plugin-deep-link" +import { useDebounce } from "ahooks" /** * 检查指定路径的有效性 @@ -29,33 +30,43 @@ export function Prepare() { const steam = useSteamStore() 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) + // Init useEffect(() => { - const initValues = () => { - const initialSteamDir = steam.state.steamDir - const initialCs2Dir = steam.state.cs2Dir + void steam.store.start() + }, []) - setSteamDir(initialSteamDir) - setCs2Dir(initialCs2Dir) + // 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) - const allCheckPassed = steam.state.steamDirValid && steam.state.cs2DirValid - setInited(steam.state.steamDirValid && steam.state.cs2DirValid) - // 逻辑有点问题,第一次启动时检查成功直接跳转,第一次检查失败不跳转,用户手动点击 - if (allCheckPassed) { + if (checkCount < 1) { + if (debounceValid) { + console.log("跳转") setTimeout(() => { router.push("/home") }, 500) } else { setTimeout(() => { setLoading(false) - }, 800) + }, 1200) } + } else { + setTimeout(() => { + setLoading(false) + }, 800) } - initValues() - }) + }, [debounceValid]) const handleSelectSteamDir = async () => { const selected = await open({ @@ -102,7 +113,7 @@ export function Prepare() { addToast({ title: "路径不存在", color: "warning" }) return } - setCs2Dir(dir) + // setCs2Dir(dir) steam.setCsDir(dir) } } @@ -120,42 +131,45 @@ export function Prepare() {
当前路径等设置有待确认
Steam所在文件夹
+CS2所在文件夹
+