diff --git a/.lingma/rules/project_rule.md b/.lingma/rules/project_rule.md deleted file mode 100644 index 4ce458c..0000000 --- a/.lingma/rules/project_rule.md +++ /dev/null @@ -1,2 +0,0 @@ -**添加规则文件可帮助模型精准理解你的编码偏好,如框架、代码风格等** -**规则文件只对当前工程生效,单文件限制10000字符。如果无需将该文件提交到远程 Git 仓库,请将其添加到 .gitignore** diff --git a/bun.lockb b/bun.lockb index 9eefc28..dc9198f 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 829ac03..27b6920 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,7 @@ "build": "tauri build", "dev": "tauri dev", "lint": "next lint", - "fix": "next lint --fix", - "prepare": "husky" + "fix": "next lint --fix" }, "dependencies": { "@heroui/react": "^2.7.5", @@ -40,13 +39,12 @@ "react": "^19.0.0", "react-dom": "^19.0.0", "swr": "^2.3.3", - "tauri-plugin-system-info-api": "^2.0.9", - "tauri-plugin-valtio": "1.1.1", + "tauri-plugin-system-info-api": "^2.0.10", + "tauri-plugin-valtio": "1.1.2", "throttle-debounce": "^5.0.2", "zustand": "5.0.1" }, "devDependencies": { - "@biomejs/biome": "^1.9.4", "@tauri-apps/cli": "^2.3.1", "@testing-library/dom": "^10.4.0", "@testing-library/jest-dom": "^6.6.3", @@ -64,7 +62,6 @@ "cssnano": "^7.0.6", "eslint": "9.14.0", "eslint-config-next": "15.0.3", - "husky": "^9.1.7", "lint-staged": "^15.5.0", "postcss": "^8.5.3", "postcss-import": "^16.1.0", @@ -85,4 +82,4 @@ "last 1 safari version" ] } -} +} \ No newline at end of file diff --git a/src/components/cstb/Prepare.tsx b/src/components/cstb/Prepare.tsx index 5bcf0be..246d572 100644 --- a/src/components/cstb/Prepare.tsx +++ b/src/components/cstb/Prepare.tsx @@ -1,9 +1,10 @@ import { addToast, Button, Spinner } from "@heroui/react" import { useRouter } from "next/navigation" import { useEffect, useState } from "react" -import { useSteamStore } from "@/store/steam" +import { steamStore, useSteamStore } from "@/store/steam" import { open } from "@tauri-apps/plugin-dialog" import { invoke } from "@tauri-apps/api/core" +import path from "path" /** * 检查指定路径的有效性 @@ -13,27 +14,52 @@ import { invoke } from "@tauri-apps/api/core" */ async function check_path(path: string, suffix?: string) { if (suffix && !path.toLowerCase().startsWith(suffix)) return false - return await invoke("check_path", { path: path }) + const exist = await invoke("check_path", { path: path }) + return exist +} + +function trim_end_string(str: string, suffix: string): string { + if (str.endsWith(suffix)) { + return str.slice(0, -suffix.length) + } + return str } export function Prepare() { const steam = useSteamStore() const router = useRouter() const [loading, setLoading] = useState(true) - const [steamDir, setSteamDir] = useState(steam.state.dir) - const [cs2Dir, setCs2Dir] = useState(steam.state.csDir) + const [checking, setChecking] = useState(false) + const [, setSteamDir] = useState(steam.state.dir) + const [, setCs2Dir] = useState(steam.state.csDir) const [inited, setInited] = useState(false) useEffect(() => { - const checkPaths = async () => { - const exist: boolean = - (await check_path(steam.state.dir, "steam.exe")) && - (await check_path(steam.state.csDir, "cs2.exe")) + const initValues = async () => { + await steamStore.start() + const initialSteamDir = steam.state.dir + const initialCs2Dir = steam.state.csDir - setInited(exist) - setLoading(false) + setSteamDir(initialSteamDir) + setCs2Dir(initialCs2Dir) } - checkPaths() + void initValues() + }) + + useEffect(() => { + const checkPaths = async () => { + setChecking(true) + const exist: boolean = + (await check_path(path.resolve(steam.state.dir, "steam.exe"))) && + (await check_path(path.resolve(steam.state.csDir, "cs2.exe"))) + + setTimeout(() => { + setInited(exist) + setLoading(false) + setChecking(false) + }, 500) + } + void checkPaths() }, [steam.state.dir, steam.state.csDir, router]) const handleSelectSteamDir = async () => { @@ -65,15 +91,15 @@ export function Prepare() { addToast({ title: "路径不存在", color: "warning" }) return } - setCs2Dir(selected) - steam.setCsDir(selected) + setCs2Dir(dir) + steam.setCsDir(dir) } } if (loading) { return ( -
- +
+

正在检查路径...

) @@ -87,9 +113,10 @@ export function Prepare() {
{ - setSteamDir(e.target.value), steam.setDir(e.target.value) + setSteamDir(e.target.value) + steam.setDir(e.target.value) }} />