Files
cstb-next/src/components/window/Nav.tsx

115 lines
3.6 KiB
TypeScript
Raw Normal View History

2024-09-20 23:15:42 +08:00
"use client"
2025-03-14 19:13:32 +08:00
import { setTheme as setTauriTheme } from "@/hooks/tauri/theme"
2025-03-17 11:48:30 +08:00
import { useAppStore } from "@/store/app"
import { useToolStore } from "@/store/tool"
import { addToast } from "@heroui/react"
import { Close, Minus, Moon, Refresh, RocketOne, Square, SunOne } from "@icon-park/react"
2025-03-14 19:13:32 +08:00
import { type Theme, getCurrentWindow } from "@tauri-apps/api/window"
2025-03-12 22:20:06 +08:00
import { /* relaunch, */ exit } from "@tauri-apps/plugin-process"
import { useTheme } from "next-themes"
2024-11-11 10:04:00 +08:00
import { usePathname, useRouter } from "next/navigation"
import { saveAllNow } from "@tauri-store/valtio"
2025-03-20 01:57:51 +08:00
import { useSteamStore } from "@/store/steam"
2024-09-20 23:15:42 +08:00
const Nav = () => {
2025-03-17 11:48:30 +08:00
const app = useAppStore()
const tool = useToolStore()
2025-03-20 01:57:51 +08:00
const steam = useSteamStore()
const { theme, setTheme } = useTheme()
2025-03-14 19:13:32 +08:00
const setAppTheme = async (theme: Theme) => {
setTheme(theme)
await setTauriTheme(theme)
}
2024-09-20 23:15:42 +08:00
const close = async () => {
// (await window.hideOnClose) ? getCurrent().hide() : exit();
await saveAllNow()
2024-09-21 01:05:40 +08:00
await exit()
}
2024-09-20 23:15:42 +08:00
const minimize = async () => {
await saveAllNow()
await getCurrentWindow().minimize()
2024-09-21 01:05:40 +08:00
}
2024-09-20 23:15:42 +08:00
const toggleMaximize = async () => {
const current = getCurrentWindow()
const maximized = await current.isMaximized()
2024-09-21 01:05:40 +08:00
await (maximized ? current.unmaximize() : current.maximize())
2024-09-20 23:15:42 +08:00
}
2024-09-21 01:05:40 +08:00
// const reset = async () => {
// await relaunch()
// }
const router = useRouter()
2024-10-28 10:42:42 +08:00
const pathname = usePathname()
2024-09-20 23:15:42 +08:00
return (
<nav className="absolute top-0 right-0 flex flex-row h-16 gap-0.5 p-4" data-tauri-drag-region>
2024-09-20 23:15:42 +08:00
<button
2024-11-11 10:04:00 +08:00
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={() => {
2025-03-17 11:48:30 +08:00
app.resetAppStore()
tool.resetToolStore()
2025-03-20 01:57:51 +08:00
steam.resetSteamStore()
addToast({
title: "重置成功",
2025-03-12 22:20:06 +08:00
color: "success",
// description: "已重置所有设置",
})
2025-03-20 01:57:51 +08:00
router.push("/")
}}
>
<Refresh size={16} />
</button>
{pathname !== "/" && (
<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={() => (pathname !== "/" ? router.push("/") : router.back())}
>
<RocketOne size={16} />
</button>
)}
<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={() => (theme === "light" ? setAppTheme("dark") : setAppTheme("light"))}
>
{theme === "light" ? <SunOne size={16} /> : <Moon size={16} />}
</button>
{/* { platform() === "windows" && ( */}
2024-11-11 10:04:00 +08:00
<>
<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"
2024-11-11 10:04:00 +08:00
onClick={minimize}
>
<Minus size={16} />
</button>
<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"
2024-11-11 10:04:00 +08:00
onClick={toggleMaximize}
>
<Square size={16} />
</button>
<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"
2024-11-11 10:04:00 +08:00
onClick={close}
>
<Close size={16} />
</button>
</>
{/* )} */}
2024-09-20 23:15:42 +08:00
</nav>
2024-09-21 01:05:40 +08:00
)
}
2024-09-20 23:15:42 +08:00
2024-09-21 01:05:40 +08:00
export default Nav