()
| 16 | export const WINDOW_CONTROLS_WIDTH = 138 |
| 17 | |
| 18 | export 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 |
nothing calls this directly
no test coverage detected