[fix] input init value not synced problem
This commit is contained in:
@@ -1,2 +0,0 @@
|
||||
**添加规则文件可帮助模型精准理解你的编码偏好,如框架、代码风格等**
|
||||
**规则文件只对当前工程生效,单文件限制10000字符。如果无需将该文件提交到远程 Git 仓库,请将其添加到 .gitignore**
|
||||
11
package.json
11
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"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<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() {
|
||||
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 (
|
||||
<div className="flex flex-col items-center justify-center gap-6">
|
||||
<Spinner size="lg" variant="simple" />
|
||||
<div className="flex items-center justify-center gap-4">
|
||||
<Spinner size="md" variant="simple" />
|
||||
<p>正在检查路径...</p>
|
||||
</div>
|
||||
)
|
||||
@@ -87,9 +113,10 @@ export function Prepare() {
|
||||
<div className="flex gap-2">
|
||||
<input
|
||||
className="flex-grow px-2 py-1 mb-2 rounded-lg"
|
||||
value={steamDir}
|
||||
value={steam.state.dir}
|
||||
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">
|
||||
@@ -100,9 +127,10 @@ export function Prepare() {
|
||||
<div className="flex gap-2">
|
||||
<input
|
||||
className="flex-grow px-2 py-1 mb-2 rounded-lg"
|
||||
value={cs2Dir}
|
||||
value={steam.state.csDir}
|
||||
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">
|
||||
@@ -119,6 +147,7 @@ export function Prepare() {
|
||||
variant="solid"
|
||||
color="primary"
|
||||
size="sm"
|
||||
isLoading={checking}
|
||||
isDisabled={!inited}
|
||||
>
|
||||
进入
|
||||
|
||||
Reference in New Issue
Block a user