import { useState, useEffect } from 'react' const isTauri = typeof window !== 'undefined' && ('__TAURI_INTERNALS__' in window || '__TAURI__' in window) const isWindows = typeof navigator !== 'undefined' && /Win/.test(navigator.platform) /** Whether to render custom window controls (Windows + Tauri only) */ export const showWindowControls = isTauri && isWindows export function WindowControls() { const [maximized, setMaximized] = useState(false) const [win, setWin] = useState<{ minimize: () => Promise toggleMaximize: () => Promise close: () => Promise isMaximized: () => Promise onResized: (handler: () => void) => Promise<() => void> } | null>(null) useEffect(() => { if (!showWindowControls) return let unlisten: (() => void) | undefined import('@tauri-apps/api/window') .then(async ({ getCurrentWindow }) => { const w = getCurrentWindow() setWin(w as any) setMaximized(await w.isMaximized()) unlisten = await w.onResized(async () => { setMaximized(await w.isMaximized()) }) }) .catch(() => {}) return () => { unlisten?.() } }, []) const runWindowAction = (action: () => Promise) => { void action().catch((error) => { console.error('Window control action failed', error) }) } if (!showWindowControls || !win) return null return (
{/* Minimize */} {/* Maximize / Restore */} {/* Close */}
) }