[feat] reset modal + basic auto get path + basic wrap err try
This commit is contained in:
@@ -85,6 +85,22 @@ export function Prepare() {
|
||||
}
|
||||
}
|
||||
|
||||
const autoGetPaths = async () => {
|
||||
try {
|
||||
const steam_path = await invoke<string>("get_steam_path")
|
||||
if (steam_path) steam.setDir(steam_path)
|
||||
} catch (e) {
|
||||
addToast({ title: "自动获取Steam路径失败", color: "danger" })
|
||||
}
|
||||
|
||||
try {
|
||||
const cs2_path = await invoke<string>("get_cs_path", { name: "cs2" })
|
||||
if (cs2_path) steam.setCsDir(cs2_path.replace(/\\[^\\]+$/, ""))
|
||||
} catch (e) {
|
||||
addToast({ title: "自动获取CS2路径失败", color: "danger" })
|
||||
}
|
||||
}
|
||||
|
||||
const handleSelectCs2Dir = async () => {
|
||||
const selected = await open({
|
||||
title: "选择 CS2.exe 文件",
|
||||
@@ -147,7 +163,7 @@ export function Prepare() {
|
||||
{links.length > 0 && <p className="text-white">{links}</p>}
|
||||
|
||||
<section className="flex justify-center w-full gap-3 mt-6">
|
||||
<Button onPress={() => alert("获取")} variant="ghost" color="default" size="sm">
|
||||
<Button onPress={() => void autoGetPaths()} variant="ghost" color="default" size="sm">
|
||||
自动获取
|
||||
</Button>
|
||||
<Button
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { setTheme as setTauriTheme } from "@/hooks/tauri/theme"
|
||||
import { useAppStore } from "@/store/app"
|
||||
import { useToolStore } from "@/store/tool"
|
||||
import { addToast } from "@heroui/react"
|
||||
import { addToast, Button, useDisclosure } from "@heroui/react"
|
||||
import { Close, Minus, Moon, Refresh, RocketOne, Square, SunOne } from "@icon-park/react"
|
||||
import { type Theme, getCurrentWindow } from "@tauri-apps/api/window"
|
||||
import { /* relaunch, */ exit } from "@tauri-apps/plugin-process"
|
||||
@@ -10,11 +10,9 @@ import { useTheme } from "next-themes"
|
||||
import { usePathname, useRouter } from "next/navigation"
|
||||
import { saveAllNow } from "@tauri-store/valtio"
|
||||
import { useSteamStore } from "@/store/steam"
|
||||
import { Modal, ModalContent, ModalHeader, ModalBody, ModalFooter } from "@heroui/react"
|
||||
|
||||
const Nav = () => {
|
||||
const app = useAppStore()
|
||||
const tool = useToolStore()
|
||||
const steam = useSteamStore()
|
||||
const { theme, setTheme } = useTheme()
|
||||
const setAppTheme = async (theme: Theme) => {
|
||||
setTheme(theme)
|
||||
@@ -46,23 +44,7 @@ const Nav = () => {
|
||||
|
||||
return (
|
||||
<nav className="absolute top-0 right-0 flex flex-row h-16 gap-0.5 p-4" data-tauri-drag-region>
|
||||
<button
|
||||
type="button"
|
||||
className="px-2 py-0 transition duration-150 rounded hover:bg-zinc-200/80 dark:hover:bg-zinc-100/10 active:scale-95"
|
||||
onClick={() => {
|
||||
app.resetAppStore()
|
||||
tool.resetToolStore()
|
||||
steam.resetSteamStore()
|
||||
addToast({
|
||||
title: "重置成功",
|
||||
color: "success",
|
||||
// description: "已重置所有设置",
|
||||
})
|
||||
router.push("/")
|
||||
}}
|
||||
>
|
||||
<Refresh size={16} />
|
||||
</button>
|
||||
<ResetModal />
|
||||
|
||||
{pathname !== "/" && (
|
||||
<button
|
||||
@@ -111,4 +93,64 @@ const Nav = () => {
|
||||
)
|
||||
}
|
||||
|
||||
function ResetModal() {
|
||||
const app = useAppStore()
|
||||
const tool = useToolStore()
|
||||
const steam = useSteamStore()
|
||||
const router = useRouter()
|
||||
const { isOpen, onOpen, onOpenChange } = useDisclosure()
|
||||
|
||||
function reset() {
|
||||
app.resetAppStore()
|
||||
tool.resetToolStore()
|
||||
steam.resetSteamStore()
|
||||
addToast({
|
||||
title: "重置成功",
|
||||
color: "success",
|
||||
// description: "已重置所有设置",
|
||||
})
|
||||
router.push("/")
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
className="px-2 py-0 transition duration-150 rounded hover:bg-zinc-200/80 dark:hover:bg-zinc-100/10 active:scale-95"
|
||||
onClick={onOpen}
|
||||
>
|
||||
<Refresh size={16} />
|
||||
</button>
|
||||
<Modal isOpen={isOpen} onOpenChange={onOpenChange}>
|
||||
<ModalContent>
|
||||
{(onClose) => (
|
||||
<>
|
||||
<ModalHeader className="flex flex-col gap-1">重置设置</ModalHeader>
|
||||
<ModalBody>
|
||||
<p>
|
||||
确认后会恢复CS工具箱的偏好设置为默认设置
|
||||
</p>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button color="danger" variant="light" onPress={onClose}>
|
||||
取消
|
||||
</Button>
|
||||
<Button
|
||||
color="primary"
|
||||
onPress={() => {
|
||||
reset()
|
||||
onClose()
|
||||
}}
|
||||
>
|
||||
确认
|
||||
</Button>
|
||||
</ModalFooter>
|
||||
</>
|
||||
)}
|
||||
</ModalContent>
|
||||
</Modal>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default Nav
|
||||
|
||||
Reference in New Issue
Block a user