import React, { MouseEvent, ReactNode } from 'react'; import { useAtomValue } from 'jotai'; import { Text } from 'folds'; import { customWindowChromeAtom } from '../../state/customWindowChrome'; import { invokeTauri, isTauri } from '../../hooks/useTauri'; import * as css from './TitleBar.css'; /** * Detect macOS from the web side (no `tauri-plugin-os` dependency). We only need * a coarse "is this a Mac" signal to decide which side the window controls sit * on, so the UA/platform sniff is sufficient and stays cross-platform. */ const isMacOS = (): boolean => { const platform = ( navigator as unknown as { userAgentData?: { platform?: string }; } ).userAgentData?.platform ?? navigator.platform ?? navigator.userAgent; return /mac/i.test(platform); }; const MIN_GLYPH = ( ); const MAX_GLYPH = ( ); const CLOSE_GLYPH = ( ); type ControlButtonProps = { label: string; glyph: ReactNode; onClick: () => void; close?: boolean; }; function ControlButton({ label, glyph, onClick, close }: ControlButtonProps) { return ( ); } /** * P5-47 — TDS Custom Window Chrome titlebar. * * Renders `null` unless we're inside Tauri **and** the user opted into custom * window chrome. Otherwise it draws a thin (~32px) folds/TDS-styled titlebar: a * draggable region (explicit `window_start_drag` on mousedown, double-press to * maximize) with the app brand, plus minimize / maximize / close controls that * call the native window commands. * * OS-aware: Windows/Linux put the controls on the right; macOS mirrors them to * the left (the native traffic-light position) since decorations — and thus the * real traffic lights — are stripped while custom chrome is on. */ export function TitleBar() { const enabled = useAtomValue(customWindowChromeAtom); if (!isTauri() || !enabled) return null; const mac = isMacOS(); // Official Tauri custom-titlebar recipe: primary-button mousedown starts an // OS window drag; a double press (detail === 2) toggles maximize instead. An // explicit `window_start_drag` invoke is used rather than // `data-tauri-drag-region` because the attribute only fires when the exact // element is the event target (children like the brand text wouldn't drag). const handleDragMouseDown = (evt: MouseEvent): void => { if (evt.button !== 0) return; if (evt.detail === 2) { invokeTauri('window_toggle_maximize'); } else { invokeTauri('window_start_drag'); } }; const controls = (
invokeTauri('window_minimize')} /> invokeTauri('window_toggle_maximize')} /> invokeTauri('window_close')} close />
); const dragRegion = (
Lotus Chat
); return (
{mac ? ( <> {controls} {dragRegion} ) : ( <> {dragRegion} {controls} )}
); }