2024-09-20 23:15:42 +08:00
|
|
|
"use client"
|
2025-03-12 11:22:32 +08:00
|
|
|
import { resetAppStore } from "@/store/app"
|
|
|
|
|
import { resetToolStore } from "@/store/tool"
|
|
|
|
|
import { addToast } from "@heroui/react"
|
2025-03-12 13:07:16 +08:00
|
|
|
import { Close, Minus, Moon, Refresh, RefreshOne, RocketOne, Square, Sun, SunOne } from "@icon-park/react"
|
|
|
|
|
import { useTheme } from "next-themes"
|
2024-09-21 01:05:40 +08:00
|
|
|
import { getCurrentWindow } from "@tauri-apps/api/window"
|
2025-03-12 13:07:16 +08:00
|
|
|
import { /* relaunch, */ exit, relaunch } from "@tauri-apps/plugin-process"
|
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"
|
2024-09-20 23:15:42 +08:00
|
|
|
|
|
|
|
|
const Nav = () => {
|
2025-03-12 13:07:16 +08:00
|
|
|
const { theme, setTheme } = useTheme()
|
|
|
|
|
|
2024-09-20 23:15:42 +08:00
|
|
|
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 (
|
2025-03-12 11:22:32 +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"
|
2025-03-12 11:22:32 +08:00
|
|
|
className="px-2 py-0 transition duration-150 rounded hover:bg-zinc-200/80 active:scale-95"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
resetAppStore()
|
|
|
|
|
resetToolStore()
|
|
|
|
|
addToast({
|
|
|
|
|
title: "重置成功",
|
|
|
|
|
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"
|
|
|
|
|
onClick={() => (pathname !== "/prepare" ? router.push("/prepare") : router.back())}
|
2024-09-20 23:15:42 +08:00
|
|
|
>
|
|
|
|
|
<RocketOne size={16} />
|
|
|
|
|
</button>
|
2024-09-27 11:20:48 +08:00
|
|
|
|
2025-03-12 13:07:16 +08:00
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
className="px-2 py-0 transition duration-150 rounded hover:bg-zinc-200/80 active:scale-95"
|
|
|
|
|
onClick={() => (theme === "light" ? setTheme("dark") : setTheme("light"))}
|
|
|
|
|
>
|
|
|
|
|
{theme === "light" ? <SunOne size={16} /> : <Moon size={16} />}
|
|
|
|
|
</button>
|
|
|
|
|
|
2024-09-27 11:20:48 +08:00
|
|
|
{/* { platform() === "windows" && ( */}
|
2024-11-11 10:04:00 +08:00
|
|
|
<>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
2025-03-12 11:22:32 +08:00
|
|
|
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"
|
2025-03-12 11:22:32 +08:00
|
|
|
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"
|
2025-03-12 11:22:32 +08:00
|
|
|
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-27 11:20:48 +08:00
|
|
|
{/* )} */}
|
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
|