MCPcopy
hub / github.com/xintaofei/codeg / WindowControls

Function WindowControls

src/components/layout/window-controls.tsx:18–124  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16export const WINDOW_CONTROLS_WIDTH = 138
17
18export function WindowControls() {
19 const t = useTranslations("Folder.windowControls")
20 const { isWindows, isLinux } = usePlatform()
21 const showControls = isWindows || isLinux
22 const [isMaximized, setIsMaximized] = useState(false)
23 const appWindowRef = useRef<Awaited<
24 ReturnType<typeof getTauriWindow>
25 > | null>(null)
26
27 useEffect(() => {
28 if (!showControls || !isDesktop()) return
29
30 let disposed = false
31 let unlistenResize: (() => void) | null = null
32 let resizeFrame: number | null = null
33
34 getTauriWindow().then((appWindow) => {
35 if (disposed) return
36 appWindowRef.current = appWindow
37
38 const syncMaximized = async () => {
39 try {
40 const maximized = await appWindow.isMaximized()
41 if (!disposed) setIsMaximized(maximized)
42 } catch {
43 if (!disposed) setIsMaximized(false)
44 }
45 }
46
47 const scheduleSync = () => {
48 if (resizeFrame !== null) return
49 resizeFrame = window.requestAnimationFrame(() => {
50 resizeFrame = null
51 void syncMaximized()
52 })
53 }
54
55 void syncMaximized()
56
57 appWindow
58 .onResized(() => scheduleSync())
59 .then((unlisten) => {
60 unlistenResize = unlisten
61 })
62 .catch(() => {
63 unlistenResize = null
64 })
65 })
66
67 return () => {
68 disposed = true
69 if (resizeFrame !== null) {
70 window.cancelAnimationFrame(resizeFrame)
71 }
72 unlistenResize?.()
73 }
74 }, [showControls])
75

Callers

nothing calls this directly

Calls 8

usePlatformFunction · 0.90
cnFunction · 0.90
isDesktopFunction · 0.85
getTauriWindowFunction · 0.85
syncMaximizedFunction · 0.85
scheduleSyncFunction · 0.85
closeMethod · 0.80
tFunction · 0.50

Tested by

no test coverage detected