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

73 lines
2.0 KiB
TypeScript
Raw Normal View History

2024-09-20 23:15:42 +08:00
"use client"
2024-09-21 01:05:40 +08:00
import { RocketOne, Minus, Close, Square } from "@icon-park/react"
import { /* relaunch, */ exit } from "@tauri-apps/plugin-process"
import { getCurrentWindow } from "@tauri-apps/api/window"
2024-09-27 16:13:05 +08:00
// import { platform } from "@tauri-apps/plugin-os"
2024-10-28 10:42:42 +08:00
import { useRouter, usePathname } from "next/navigation"
2024-09-20 23:15:42 +08:00
const Nav = () => {
const close = async () => {
// (await window.hideOnClose) ? getCurrent().hide() : exit();
2024-09-21 01:05:40 +08:00
await exit()
}
2024-09-20 23:15:42 +08:00
const minimize = () => {
getCurrentWindow()
.minimize()
.then(() => {
2024-09-21 01:05:40 +08:00
console.log("minimized")
2024-09-20 23:15:42 +08:00
})
.catch((err: unknown) => {
2024-09-21 01:05:40 +08:00
console.error(err)
})
}
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 (
2024-09-21 01:05:40 +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
className="px-2 py-0 transition rounded hover:bg-zinc-200/80 active:scale-95"
2024-10-28 10:42:42 +08:00
onClick={() => pathname !== "/prepare" ? router.push("/prepare") : router.back()}
2024-09-20 23:15:42 +08:00
>
<RocketOne size={16} />
</button>
{/* { platform() === "windows" && ( */}
<>
<button
className="px-2 py-0 transition rounded hover:bg-zinc-200/80 active:scale-95"
onClick={minimize}
>
<Minus size={16} />
</button>
<button
className="px-2 py-0 transition rounded hover:bg-zinc-200/80 active:scale-95"
onClick={toggleMaximize}
>
<Square size={16} />
</button>
<button
className="px-2 py-0 transition rounded hover:bg-zinc-200/80 active:scale-95"
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