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所在文件夹

+

Steam所在文件夹

- { - setSteamDir(e.target.value) - steam.setDir(e.target.value) + onValueChange={(value) => { + setSteamDir(value) + steam.setDir(value) }} + description="steam.exe所在文件夹" + errorMessage={"路径无效"} + isInvalid={!steam.state.steamDirValid} /> -
-

CS2所在文件夹

+

CS2所在文件夹

- { - setCs2Dir(e.target.value) - steam.setCsDir(e.target.value) + onValueChange={(value) => { + setCs2Dir(value) + steam.setCsDir(value) }} + description="cs2.exe所在文件夹" + errorMessage={"路径无效"} + isInvalid={!steam.state.cs2DirValid} /> -
-
- {steam.state.steamDirValid ? "Steam √" : "Steam ×"} - {steam.state.cs2DirValid ? "CS2 √" : "CS2 ×"} -
-
diff --git a/src/store/app.ts b/src/store/app.ts index 058b9eb..b4b48ca 100644 --- a/src/store/app.ts +++ b/src/store/app.ts @@ -18,6 +18,7 @@ export const useAppStore = () => { return { state, + store: appStore, setVersion, setHasUpdate, setInited, diff --git a/src/store/steam.ts b/src/store/steam.ts index 2dc9812..3eb92f3 100644 --- a/src/store/steam.ts +++ b/src/store/steam.ts @@ -35,6 +35,7 @@ export const useSteamStore = () => { return { state, + store: steamStore, setDir, setCsDir, setUsers, @@ -74,7 +75,6 @@ const SetCs2DirChecking = (checking: boolean) => { const checkSteamDirValid = async () => { SetSteamDirChecking(true) const pathExist = await invoke("check_path", { path: steamStore.state.steamDir }) - console.log("steamDir", steamStore.state.steamDir, "pathExist", pathExist) setSteamDirValid(pathExist) setTimeout(() => { SetSteamDirChecking(false) @@ -84,7 +84,6 @@ const checkSteamDirValid = async () => { const checkCs2DirValid = async () => { SetCs2DirChecking(true) const pathExist = await invoke("check_path", { path: steamStore.state.cs2Dir }) - console.log("cs2Dir", steamStore.state.cs2Dir, "pathExist", pathExist) setCs2DirValid(pathExist) setTimeout(() => { SetCs2DirChecking(false) diff --git a/src/store/tool.ts b/src/store/tool.ts index 232a762..3148eac 100644 --- a/src/store/tool.ts +++ b/src/store/tool.ts @@ -25,6 +25,7 @@ export const useToolStore = () => { return { state, + store: toolStore, setLaunchOption, setLaunchOptions, setLaunchIndex,