import rndDefaults from "components/system/Window/RndWindow/rndDefaults"; import StyledTitlebar from "components/system/Window/Titlebar/StyledTitlebar"; import useTitlebarContextMenu from "components/system/Window/Titlebar/useTitlebarContextMenu"; import useWindowActions from "components/system/Window/Titlebar/useWindowActions"; import { CloseIcon, MaximizedIcon, MaximizeIcon, MinimizeIcon, } from "components/system/Window/Titlebar/WindowActionIcons"; import { useProcesses } from "contexts/process"; import { useSession } from "contexts/session"; import useDoubleClick from "hooks/useDoubleClick"; import { useCallback, useRef } from "react"; import Button from "styles/common/Button"; import Icon from "styles/common/Icon"; import { LONG_PRESS_DELAY_MS, PREVENT_SCROLL } from "utils/constants"; import { haltEvent, label } from "utils/functions"; type TitlebarProps = { id: string; }; const Titlebar: FC = ({ id }) => { const { processes: { [id]: process }, } = useProcesses(); const { allowResizing = true, closing, componentWindow, hideMaximizeButton, hideMinimizeButton, hideTitlebarIcon, icon, title, maximized, } = process || {}; const { foregroundId } = useSession(); const isForeground = id === foregroundId; const { onClose, onMaximize, onMinimize } = useWindowActions(id); const onClickClose = useDoubleClick(onClose); const onClickMaximize = useDoubleClick(onMaximize); const titlebarContextMenu = useTitlebarContextMenu(id); const touchStartTimeRef = useRef(0); const touchStartPositionRef = useRef(); const touchesRef = useRef(); const onTouchEnd = useCallback( (event: React.TouchEvent) => { const { x, y } = componentWindow?.getBoundingClientRect() || {}; if ( Date.now() - touchStartTimeRef.current >= LONG_PRESS_DELAY_MS && touchStartPositionRef.current && touchStartPositionRef.current.x === x && touchStartPositionRef.current.y === y ) { titlebarContextMenu.onContextMenuCapture( Object.assign(event, { touches: touchesRef.current, }) ); } }, [componentWindow, titlebarContextMenu] ); const onTouchStart = useCallback( ({ touches }: React.TouchEvent) => { if (componentWindow) { componentWindow.blur(); componentWindow.focus(PREVENT_SCROLL); touchStartTimeRef.current = Date.now(); touchStartPositionRef.current = componentWindow.getBoundingClientRect(); touchesRef.current = touches as unknown as TouchList; } }, [componentWindow] ); return ( ); }; export default Titlebar;