Files
cstb-next/src/components/window/Nav.tsx
2024-11-11 10:04:00 +08:00

82 lines
2.1 KiB
TypeScript

"use client"
import { Close, Minus, RocketOne, Square } from "@icon-park/react"
import { getCurrentWindow } from "@tauri-apps/api/window"
import { /* relaunch, */ exit } from "@tauri-apps/plugin-process"
// import { platform } from "@tauri-apps/plugin-os"
import { usePathname, useRouter } from "next/navigation"
const Nav = () => {
const close = async () => {
// (await window.hideOnClose) ? getCurrent().hide() : exit();
await exit()
}
const minimize = () => {
getCurrentWindow()
.minimize()
.then(() => {
console.log("minimized")
})
.catch((err: unknown) => {
console.error(err)
})
}
const toggleMaximize = async () => {
const current = getCurrentWindow()
const maximized = await current.isMaximized()
await (maximized ? current.unmaximize() : current.maximize())
}
// const reset = async () => {
// await relaunch()
// }
const router = useRouter()
const pathname = usePathname()
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 rounded hover:bg-zinc-200/80 active:scale-95"
onClick={() =>
pathname !== "/prepare" ? router.push("/prepare") : router.back()
}
>
<RocketOne size={16} />
</button>
{/* { platform() === "windows" && ( */}
<>
<button
type="button"
className="px-2 py-0 transition rounded hover:bg-zinc-200/80 active:scale-95"
onClick={minimize}
>
<Minus size={16} />
</button>
<button
type="button"
className="px-2 py-0 transition rounded hover:bg-zinc-200/80 active:scale-95"
onClick={toggleMaximize}
>
<Square size={16} />
</button>
<button
type="button"
className="px-2 py-0 transition rounded hover:bg-zinc-200/80 active:scale-95"
onClick={close}
>
<Close size={16} />
</button>
</>
{/* )} */}
</nav>
)
}
export default Nav