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-12 11:22:32 +08:00
|
|
|
import { resetAppStore } from "@/store/app"
|
|
|
|
|
import { resetToolStore } from "@/store/tool"
|
|
|
|
|
import { addToast } from "@heroui/react"
|
2025-03-17 01:17:35 +08:00
|
|
|
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"
|
2025-03-13 22:04:27 +08:00
|
|
|
import { saveAllNow } from "tauri-plugin-valtio"
|
2024-09-20 23:15:42 +08:00
|
|
|
|
|
|
|
|
const Nav = () => {
|
2025-03-12 13:07:16 +08:00
|
|
|
const { theme, setTheme } = useTheme()
|
2025-03-14 19:13:32 +08:00
|
|
|
const setAppTheme = async (theme: Theme) => {
|
|
|
|
|
setTheme(theme)
|
|
|
|
|
await setTauriTheme(theme)
|
|
|
|
|
}
|
2025-03-12 13:07:16 +08:00
|
|
|
|
2024-09-20 23:15:42 +08:00
|
|
|
const close = async () => {
|
|
|
|
|
// (await window.hideOnClose) ? getCurrent().hide() : exit();
|
2025-03-13 22:04:27 +08:00
|
|
|
await saveAllNow()
|
2024-09-21 01:05:40 +08:00
|
|
|
await exit()
|
|
|
|
|
}
|
2024-09-20 23:15:42 +08:00
|
|
|
|
2025-03-13 02:34:59 +08:00
|
|
|
const minimize = async () => {
|
2025-03-13 22:04:27 +08:00
|
|
|
await saveAllNow()
|
2025-03-13 02:34:59 +08:00
|
|
|
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-17 01:17:35 +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-17 01:17:35 +08:00
|
|
|
className="px-2 py-0 transition duration-150 rounded hover:bg-zinc-200/80 dark:hover:bg-zinc-100/10 active:scale-95"
|
2025-03-12 11:22:32 +08:00
|
|
|
onClick={() => {
|
|
|
|
|
resetAppStore()
|
|
|
|
|
resetToolStore()
|
|
|
|
|
addToast({
|
|
|
|
|
title: "重置成功",
|
2025-03-12 22:20:06 +08:00
|
|
|
color: "success",
|
2025-03-12 13:16:25 +08:00
|
|
|
// description: "已重置所有设置",
|
2025-03-12 11:22:32 +08:00
|
|
|
})
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Refresh size={16} />
|
|
|
|
|
</button>
|
|
|
|
|
|
2025-03-17 01:17:35 +08:00
|
|
|
{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>
|
|
|
|
|
)}
|
2024-09-27 11:20:48 +08:00
|
|
|
|
2025-03-12 13:07:16 +08:00
|
|
|
<button
|
|
|
|
|
type="button"
|
2025-03-17 01:17:35 +08:00
|
|
|
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"))}
|
2025-03-12 13:07:16 +08:00
|
|
|
>
|
|
|
|
|
{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-17 01:17:35 +08:00
|
|
|
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"
|
2025-03-17 01:17:35 +08:00
|
|
|
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"
|
2025-03-17 01:17:35 +08:00
|
|
|
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-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
|