dev-prepare #2

Merged
purp1e merged 42 commits from dev-prepare into master 2025-03-24 02:16:40 +08:00
4 changed files with 52 additions and 28 deletions
Showing only changes of commit 0f3dca7428 - Show all commits

View File

@@ -1,2 +0,0 @@
**添加规则文件可帮助模型精准理解你的编码偏好,如框架、代码风格等**
**规则文件只对当前工程生效单文件限制10000字符。如果无需将该文件提交到远程 Git 仓库,请将其添加到 .gitignore**

BIN
bun.lockb

Binary file not shown.

View File

@@ -13,8 +13,7 @@
"build": "tauri build", "build": "tauri build",
"dev": "tauri dev", "dev": "tauri dev",
"lint": "next lint", "lint": "next lint",
"fix": "next lint --fix", "fix": "next lint --fix"
"prepare": "husky"
}, },
"dependencies": { "dependencies": {
"@heroui/react": "^2.7.5", "@heroui/react": "^2.7.5",
@@ -40,13 +39,12 @@
"react": "^19.0.0", "react": "^19.0.0",
"react-dom": "^19.0.0", "react-dom": "^19.0.0",
"swr": "^2.3.3", "swr": "^2.3.3",
"tauri-plugin-system-info-api": "^2.0.9", "tauri-plugin-system-info-api": "^2.0.10",
"tauri-plugin-valtio": "1.1.1", "tauri-plugin-valtio": "1.1.2",
"throttle-debounce": "^5.0.2", "throttle-debounce": "^5.0.2",
"zustand": "5.0.1" "zustand": "5.0.1"
}, },
"devDependencies": { "devDependencies": {
"@biomejs/biome": "^1.9.4",
"@tauri-apps/cli": "^2.3.1", "@tauri-apps/cli": "^2.3.1",
"@testing-library/dom": "^10.4.0", "@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.6.3", "@testing-library/jest-dom": "^6.6.3",
@@ -64,7 +62,6 @@
"cssnano": "^7.0.6", "cssnano": "^7.0.6",
"eslint": "9.14.0", "eslint": "9.14.0",
"eslint-config-next": "15.0.3", "eslint-config-next": "15.0.3",
"husky": "^9.1.7",
"lint-staged": "^15.5.0", "lint-staged": "^15.5.0",
"postcss": "^8.5.3", "postcss": "^8.5.3",
"postcss-import": "^16.1.0", "postcss-import": "^16.1.0",

View File

@@ -1,9 +1,10 @@
import { addToast, Button, Spinner } from "@heroui/react" import { addToast, Button, Spinner } from "@heroui/react"
import { useRouter } from "next/navigation" import { useRouter } from "next/navigation"
import { useEffect, useState } from "react" import { useEffect, useState } from "react"
import { useSteamStore } from "@/store/steam" import { steamStore, useSteamStore } from "@/store/steam"
import { open } from "@tauri-apps/plugin-dialog" import { open } from "@tauri-apps/plugin-dialog"
import { invoke } from "@tauri-apps/api/core" 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) { async function check_path(path: string, suffix?: string) {
if (suffix && !path.toLowerCase().startsWith(suffix)) return false if (suffix && !path.toLowerCase().startsWith(suffix)) return false
return await invoke<boolean>("check_path", { path: path }) const exist = await invoke<boolean>("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() { export function Prepare() {
const steam = useSteamStore() const steam = useSteamStore()
const router = useRouter() const router = useRouter()
const [loading, setLoading] = useState(true) const [loading, setLoading] = useState(true)
const [steamDir, setSteamDir] = useState(steam.state.dir) const [checking, setChecking] = useState(false)
const [cs2Dir, setCs2Dir] = useState(steam.state.csDir) const [, setSteamDir] = useState(steam.state.dir)
const [, setCs2Dir] = useState(steam.state.csDir)
const [inited, setInited] = useState(false) const [inited, setInited] = useState(false)
useEffect(() => { useEffect(() => {
const checkPaths = async () => { const initValues = async () => {
const exist: boolean = await steamStore.start()
(await check_path(steam.state.dir, "steam.exe")) && const initialSteamDir = steam.state.dir
(await check_path(steam.state.csDir, "cs2.exe")) const initialCs2Dir = steam.state.csDir
setInited(exist) setSteamDir(initialSteamDir)
setLoading(false) 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]) }, [steam.state.dir, steam.state.csDir, router])
const handleSelectSteamDir = async () => { const handleSelectSteamDir = async () => {
@@ -65,15 +91,15 @@ export function Prepare() {
addToast({ title: "路径不存在", color: "warning" }) addToast({ title: "路径不存在", color: "warning" })
return return
} }
setCs2Dir(selected) setCs2Dir(dir)
steam.setCsDir(selected) steam.setCsDir(dir)
} }
} }
if (loading) { if (loading) {
return ( return (
<div className="flex flex-col items-center justify-center gap-6"> <div className="flex items-center justify-center gap-4">
<Spinner size="lg" variant="simple" /> <Spinner size="md" variant="simple" />
<p>...</p> <p>...</p>
</div> </div>
) )
@@ -87,9 +113,10 @@ export function Prepare() {
<div className="flex gap-2"> <div className="flex gap-2">
<input <input
className="flex-grow px-2 py-1 mb-2 rounded-lg" className="flex-grow px-2 py-1 mb-2 rounded-lg"
value={steamDir} value={steam.state.dir}
onChange={(e) => { onChange={(e) => {
setSteamDir(e.target.value), steam.setDir(e.target.value) setSteamDir(e.target.value)
steam.setDir(e.target.value)
}} }}
/> />
<Button onPress={handleSelectSteamDir} variant="solid" color="primary" size="sm"> <Button onPress={handleSelectSteamDir} variant="solid" color="primary" size="sm">
@@ -100,9 +127,10 @@ export function Prepare() {
<div className="flex gap-2"> <div className="flex gap-2">
<input <input
className="flex-grow px-2 py-1 mb-2 rounded-lg" className="flex-grow px-2 py-1 mb-2 rounded-lg"
value={cs2Dir} value={steam.state.csDir}
onChange={(e) => { onChange={(e) => {
setCs2Dir(e.target.value), steam.setCsDir(e.target.value) setCs2Dir(e.target.value)
steam.setCsDir(e.target.value)
}} }}
/> />
<Button onPress={handleSelectCs2Dir} variant="solid" color="primary" size="sm"> <Button onPress={handleSelectCs2Dir} variant="solid" color="primary" size="sm">
@@ -119,6 +147,7 @@ export function Prepare() {
variant="solid" variant="solid"
color="primary" color="primary"
size="sm" size="sm"
isLoading={checking}
isDisabled={!inited} isDisabled={!inited}
> >