import { useEffect, type CSSProperties, type MouseEvent as ReactMouseEvent } from 'react'; import { RESIZE_BORDER } from '../chrome.ts'; import { chipFor } from '../updateModel.ts'; import { AccountSwitcher } from './AccountSwitcher.tsx'; import { AppMenu, AppMenuLogo } from './AppMenu.tsx'; import { invoke } from './bridge.ts'; import { useT, useUpdateStatus } from './hooks.ts'; import { tx } from './i18n.ts'; import { site } from './site.ts'; import { TitlebarExtras } from './TitlebarExtras.tsx'; import { close, minimize, os, startResize, systemMenu, toggleMaximize, type ResizeDirection } from './windowBinding.ts'; const isInteractive = (target: EventTarget | null) => target instanceof Element && !!target.closest('button, input, textarea, a, .dv-tab, [role="button"]'); /** Right-click on empty titlebar space: the native system menu (Restore, Move, Size, ...). */ export function titlebarContextMenu(event: ReactMouseEvent | MouseEvent) { if (isInteractive(event.target)) return; event.preventDefault(); const scale = window.devicePixelRatio || 1; systemMenu(Math.round(event.screenX * scale), Math.round(event.screenY * scale)); } /** * The 44px titlebar row. It sits under the dockview root: the top groups' tab headers are * transparent and let clicks through to the drag layer, the logo and the caption buttons. The logo * is the app menu's second trigger (AppMenu.tsx); everything else that is empty drags the window. */ export function Titlebar({ maximized }: { maximized: boolean }) { return
{/* One home for the app menu: the logo. Alt+F, F10, the palette and the account menu's last row open it there. */} {os !== 'macos' && }
; } /** "Update ready ยท restart": appears only when a verified update is downloaded (or failed to start). */ function UpdateChip() { const [status, apply] = useUpdateStatus(); const chip = chipFor(status, site().product, key => tx(key, undefined, '') || undefined); // Widen the tab strip's right reserve while the chip is shown so tabs never sit under it. useEffect(() => { const root = document.documentElement; if (chip) root.dataset.update = chip.kind; else delete root.dataset.update; return () => { delete root.dataset.update; }; }, [chip?.kind]); if (!chip) return null; if (chip.kind === 'problem') { return ; } return ; } function WindowControls({ maximized }: { maximized: boolean }) { const t = useT(); return
; } const CORNER = RESIZE_BORDER * 2; const GRIPS: Array<[ResizeDirection, CSSProperties]> = [ ['North', { top: 0, left: CORNER, right: CORNER, height: RESIZE_BORDER, cursor: 'ns-resize' }], ['South', { bottom: 0, left: CORNER, right: CORNER, height: RESIZE_BORDER, cursor: 'ns-resize' }], ['West', { left: 0, top: CORNER, bottom: CORNER, width: RESIZE_BORDER, cursor: 'ew-resize' }], ['East', { right: 0, top: CORNER, bottom: CORNER, width: RESIZE_BORDER, cursor: 'ew-resize' }], ['NorthWest', { top: 0, left: 0, width: CORNER, height: CORNER, cursor: 'nwse-resize' }], ['SouthEast', { bottom: 0, right: 0, width: CORNER, height: CORNER, cursor: 'nwse-resize' }], ['NorthEast', { top: 0, right: 0, width: CORNER, height: CORNER, cursor: 'nesw-resize' }], ['SouthWest', { bottom: 0, left: 0, width: CORNER, height: CORNER, cursor: 'nesw-resize' }], ]; /** * The shell webview covers the whole frameless window, so the OS never sees its edges: * these grips start native resize drags. Tab webviews are inset by the same band (Rust clamps too). */ export function ResizeGrips() { return <>{GRIPS.map(([direction, style]) =>