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

118 lines
3.1 KiB
TypeScript
Raw Normal View History

2024-09-20 23:15:42 +08:00
"use client"
import { resetAppStore } from "@/store/app"
import { resetToolStore } from "@/store/tool"
import { addToast } from "@heroui/react"
2025-03-12 22:20:06 +08:00
import {
Close,
Minus,
Moon,
Refresh,
RocketOne,
Square,
SunOne,
} from "@icon-park/react"
2024-09-21 01:05:40 +08:00
import { 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-09-27 16:13:05 +08:00
// import { platform } from "@tauri-apps/plugin-os"
2024-11-11 10:04:00 +08:00
import { usePathname, useRouter } from "next/navigation"
import { saveAllNow } from "tauri-plugin-valtio"
2024-09-20 23:15:42 +08:00
const Nav = () => {
const { theme, setTheme } = useTheme()
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 (
2025-03-12 22:20:06 +08:00
<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 active:scale-95"
onClick={() => {
resetAppStore()
resetToolStore()
addToast({
title: "重置成功",
2025-03-12 22:20:06 +08:00
color: "success",
// description: "已重置所有设置",
})
}}
>
<Refresh size={16} />
</button>
<button
type="button"
className="px-2 py-0 transition duration-150 rounded hover:bg-zinc-200/80 active:scale-95"
2025-03-12 22:20:06 +08:00
onClick={() =>
pathname !== "/prepare" ? router.push("/prepare") : router.back()
}
2024-09-20 23:15:42 +08:00
>
<RocketOne size={16} />
</button>
<button
type="button"
className="px-2 py-0 transition duration-150 rounded hover:bg-zinc-200/80 active:scale-95"
2025-03-12 22:20:06 +08:00
onClick={() =>
theme === "light" ? setTheme("dark") : setTheme("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 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 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 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