import AppBar from '@mui/material/AppBar'; import Toolbar from '@mui/material/Toolbar'; import Typography from '@mui/material/Typography'; import { throttle } from 'lodash-es'; import React, { useEffect, useMemo, useState } from 'react'; import ToggleDarkModeButton from './ToggleDarkModeButton'; function useWindowControlsOverlayVisible(): boolean { const [windowControlsOverlayVisible, setWindowControlsOverlayVisible] = useState(false); const updateWindowControlsOverlayVisible = useMemo( () => throttle( ({ visible }: WindowControlsOverlayGeometryChangeEvent) => setWindowControlsOverlayVisible(visible), 250, ), [], ); useEffect(() => { if ('windowControlsOverlay' in navigator) { const { windowControlsOverlay } = navigator; setWindowControlsOverlayVisible(windowControlsOverlay.visible); windowControlsOverlay.addEventListener( 'geometrychange', updateWindowControlsOverlayVisible, ); return () => { windowControlsOverlay.removeEventListener( 'geometrychange', updateWindowControlsOverlayVisible, ); }; } // Nothing to clean up if `windowControlsOverlay` is unsupported. return () => {}; }, [updateWindowControlsOverlayVisible]); return windowControlsOverlayVisible; } export default function TopBar(): JSX.Element { const overlayVisible = useWindowControlsOverlayVisible(); return ( ({ background: theme.palette.outer.background, borderBottom: `1px solid ${theme.palette.outer.border}`, appRegion: 'drag', '.MuiButtonBase-root': { appRegion: 'no-drag', }, })} > Refinery ); }