|
1 | | -import { createFileRoute, Navigate, Outlet } from "@tanstack/react-router"; |
2 | | -import { isTauri } from "@tauri-apps/api/core"; |
3 | | -import { getCurrentWindow } from "@tauri-apps/api/window"; |
4 | | -import { useEffect, useState } from "react"; |
| 1 | +import { createFileRoute, Navigate, Outlet } from "@tanstack/react-router" |
| 2 | +import { isTauri } from "@tauri-apps/api/core" |
| 3 | +import { getCurrentWindow } from "@tauri-apps/api/window" |
| 4 | +import { useEffect, useState } from "react" |
5 | 5 |
|
6 | 6 | export const Route = createFileRoute("/window")({ |
7 | 7 | component: Component, |
8 | 8 | pendingComponent: PendingComponent, |
9 | | -}); |
| 9 | +}) |
10 | 10 |
|
11 | 11 | function Component() { |
12 | | - const [is_maximized, set_is_maximized] = useState(false); |
| 12 | + const [is_maximized, set_is_maximized] = useState(false) |
13 | 13 | useEffect(() => { |
14 | 14 | if (isTauri()) { |
15 | 15 | //设置窗口标题 |
16 | | - getCurrentWindow().setTitle(document.title).catch(console.error); |
| 16 | + getCurrentWindow().setTitle(document.title).catch(console.error) |
17 | 17 | //监控网页标题变化 |
18 | 18 | const mutation_observer = new MutationObserver(async (mutations) => { |
19 | 19 | for (const mutation of mutations) { |
20 | 20 | if (mutation.type === "childList") { |
21 | | - await getCurrentWindow().setTitle(document.title); |
| 21 | + await getCurrentWindow().setTitle(document.title) |
22 | 22 | } |
23 | 23 | } |
24 | | - }); |
25 | | - mutation_observer.observe(document.querySelector("title")!, { childList: true }); |
| 24 | + }) |
| 25 | + mutation_observer.observe(document.querySelector("title")!, { childList: true }) |
26 | 26 | //监控窗口缩放 |
27 | | - const un_on_resized = getCurrentWindow().onResized(async () => set_is_maximized(await getCurrentWindow().isMaximized())); |
| 27 | + const un_on_resized = getCurrentWindow().onResized(async () => set_is_maximized(await getCurrentWindow().isMaximized())) |
28 | 28 | return () => { |
29 | 29 | mutation_observer.disconnect(); |
30 | | - (async () => (await un_on_resized)())(); |
31 | | - }; |
| 30 | + (async () => (await un_on_resized)())() |
| 31 | + } |
32 | 32 | } |
33 | | - }, []); |
34 | | - return <> |
35 | | - <div className="w-screen h-screen flex flex-col"> |
36 | | - <div data-tauri-drag-region className="h-8 flex justify-end"> |
37 | | - {isTauri() && <> |
38 | | - <div className="w-8 flex items-center justify-center hover:bg-neutral-200 active:bg-neutral-300 cursor-pointer" |
39 | | - onClick={async () => await getCurrentWindow().minimize()} |
40 | | - > |
41 | | - <div className="icon-[mdi--window-minimize]" /> |
42 | | - </div> |
43 | | - <div className="w-8 flex items-center justify-center hover:bg-neutral-200 active:bg-neutral-300 cursor-pointer" |
44 | | - onClick={async () => await getCurrentWindow().toggleMaximize()} |
45 | | - > |
46 | | - {!is_maximized ? <div className="icon-[mdi--window-maximize]" /> : <div className="icon-[mdi--window-restore]" />} |
47 | | - </div> |
48 | | - <div className="w-8 flex items-center justify-center hover:bg-red-600 active:bg-red-500 cursor-pointer" |
49 | | - onClick={async () => await getCurrentWindow().close()} |
50 | | - > |
51 | | - <div className="icon-[mdi--window-close]" /> |
52 | | - </div> |
53 | | - </>} |
54 | | - </div> |
55 | | - <Outlet /> |
56 | | - <Navigate to="/window/login" /> |
| 33 | + }, []) |
| 34 | + return <div className="w-screen h-screen flex flex-col"> |
| 35 | + <div data-tauri-drag-region className="h-8 flex justify-end"> |
| 36 | + {isTauri() && <> |
| 37 | + <div className="w-8 flex items-center justify-center hover:bg-neutral-200 active:bg-neutral-300 cursor-pointer" |
| 38 | + onClick={async () => await getCurrentWindow().minimize()} |
| 39 | + > |
| 40 | + <div className="icon-[mdi--window-minimize]" /> |
| 41 | + </div> |
| 42 | + <div className="w-8 flex items-center justify-center hover:bg-neutral-200 active:bg-neutral-300 cursor-pointer" |
| 43 | + onClick={async () => await getCurrentWindow().toggleMaximize()} |
| 44 | + > |
| 45 | + {!is_maximized ? <div className="icon-[mdi--window-maximize]" /> : <div className="icon-[mdi--window-restore]" />} |
| 46 | + </div> |
| 47 | + <div className="w-8 flex items-center justify-center hover:bg-red-600 active:bg-red-500 cursor-pointer" |
| 48 | + onClick={async () => await getCurrentWindow().close()} |
| 49 | + > |
| 50 | + <div className="icon-[mdi--window-close]" /> |
| 51 | + </div> |
| 52 | + </>} |
57 | 53 | </div> |
58 | | - </>; |
| 54 | + <Outlet /> |
| 55 | + <Navigate to="/window/login" /> |
| 56 | + </div> |
59 | 57 | } |
60 | 58 |
|
61 | 59 | function PendingComponent() { |
62 | | - return <> |
63 | | - <div className="w-screen h-screen flex items-center justify-center gap-1"> |
64 | | - <div className="select-none font-bold">正在加载窗口</div> |
65 | | - <div className="icon-[line-md--loading-loop] w-6 h-6" /> |
66 | | - </div> |
67 | | - </>; |
| 60 | + return <div className="w-screen h-screen flex items-center justify-center gap-1"> |
| 61 | + <div className="select-none font-bold">正在加载窗口</div> |
| 62 | + <div className="icon-[line-md--loading-loop] w-6 h-6" /> |
| 63 | + </div> |
68 | 64 | } |
0 commit comments