[feat] global watch dir and set better check logic
todo: first time check failed should let user manually click
This commit is contained in:
@@ -22,7 +22,7 @@ const FastLaunch = () => {
|
||||
type="button"
|
||||
onClick={() =>
|
||||
invoke("launch_game", {
|
||||
steamPath: `${steam.state.dir}/steam.exe`,
|
||||
steamPath: `${steam.state.steamDir}/steam.exe`,
|
||||
launchOption: tool.state.launchOptions[tool.state.launchIndex] || "",
|
||||
server: "perfectworld",
|
||||
})
|
||||
@@ -35,7 +35,7 @@ const FastLaunch = () => {
|
||||
type="button"
|
||||
onClick={() =>
|
||||
invoke("launch_game", {
|
||||
steamPath: `${steam.state.dir}/steam.exe`,
|
||||
steamPath: `${steam.state.steamDir}/steam.exe`,
|
||||
launchOption: tool.state.launchOptions[tool.state.launchIndex] || "",
|
||||
server: "worldwide",
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { addToast, Button, Spinner } from "@heroui/react"
|
||||
import { addToast, Button, Chip, Spinner } from "@heroui/react"
|
||||
import { useRouter } from "next/navigation"
|
||||
import { useEffect, useState } from "react"
|
||||
import { steamStore, useSteamStore } from "@/store/steam"
|
||||
@@ -31,43 +31,33 @@ export function Prepare() {
|
||||
const router = useRouter()
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [checking, setChecking] = useState(false)
|
||||
const [, setSteamDir] = useState(steam.state.dir)
|
||||
const [, setCs2Dir] = useState(steam.state.csDir)
|
||||
const [, setSteamDir] = useState(steam.state.steamDir)
|
||||
const [, setCs2Dir] = useState(steam.state.cs2Dir)
|
||||
const [inited, setInited] = useState(false)
|
||||
const [links, setLinks] = useState<string[]>([])
|
||||
|
||||
useEffect(() => {
|
||||
const initValues = async () => {
|
||||
await steamStore.start()
|
||||
const initialSteamDir = steam.state.dir
|
||||
const initialCs2Dir = steam.state.csDir
|
||||
const initialSteamDir = steam.state.steamDir
|
||||
const initialCs2Dir = steam.state.cs2Dir
|
||||
|
||||
setSteamDir(initialSteamDir)
|
||||
setCs2Dir(initialCs2Dir)
|
||||
|
||||
const allCheckPassed = steam.state.steamDirValid && steam.state.cs2DirValid
|
||||
setInited(steam.state.steamDirValid && steam.state.cs2DirValid)
|
||||
// 逻辑有点问题,第一次启动时检查成功直接跳转,第一次检查失败不跳转,用户手动点击
|
||||
if (allCheckPassed) {
|
||||
router.push("/home")
|
||||
return
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
setLoading(false)
|
||||
}, 300)
|
||||
}
|
||||
void initValues()
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
void onOpenUrl((urls) => {
|
||||
console.log("deep link:", urls)
|
||||
setLinks(urls)
|
||||
})
|
||||
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 () => {
|
||||
const selected = await open({
|
||||
title: "选择 Steam.exe 文件",
|
||||
@@ -135,7 +125,7 @@ export function Prepare() {
|
||||
<div className="flex gap-2">
|
||||
<input
|
||||
className="flex-grow px-2 py-1 mb-2 rounded-lg"
|
||||
value={steam.state.dir}
|
||||
value={steam.state.steamDir}
|
||||
onChange={(e) => {
|
||||
setSteamDir(e.target.value)
|
||||
steam.setDir(e.target.value)
|
||||
@@ -149,7 +139,7 @@ export function Prepare() {
|
||||
<div className="flex gap-2">
|
||||
<input
|
||||
className="flex-grow px-2 py-1 mb-2 rounded-lg"
|
||||
value={steam.state.csDir}
|
||||
value={steam.state.cs2Dir}
|
||||
onChange={(e) => {
|
||||
setCs2Dir(e.target.value)
|
||||
steam.setCsDir(e.target.value)
|
||||
@@ -160,7 +150,12 @@ export function Prepare() {
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{links.length > 0 && <p className="text-white">{links}</p>}
|
||||
<TestDeepLink />
|
||||
|
||||
<section className="flex justify-center gap-3">
|
||||
<Chip>{steam.state.steamDirValid ? "Steam √" : "Steam ×"}</Chip>
|
||||
<Chip>{steam.state.cs2DirValid ? "CS2 √" : "CS2 ×"}</Chip>
|
||||
</section>
|
||||
|
||||
<section className="flex justify-center w-full gap-3 mt-6">
|
||||
<Button onPress={() => void autoGetPaths()} variant="ghost" color="default" size="sm">
|
||||
@@ -180,3 +175,16 @@ export function Prepare() {
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function TestDeepLink() {
|
||||
const [links, setLinks] = useState<string[]>([])
|
||||
const router = useRouter()
|
||||
|
||||
useEffect(() => {
|
||||
void onOpenUrl((urls) => {
|
||||
console.log("deep link:", urls)
|
||||
setLinks(urls)
|
||||
})
|
||||
}, [router])
|
||||
return <>{links.length > 0 && <p className="text-white">{links}</p>}</>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user