The top-right ⋮ and the logo opened the same menu: one of them was redundant. The logo stays as the only titlebar trigger (the app's own mark, where an app menu lives); the right side is back to workspaces, accounts and the window buttons. Alt+F, F10, the palette and the account menu's last row open the menu under the logo. Apps that want a separate button keep <AppMenu/>'s default trigger. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
100 lines
5.4 KiB
TypeScript
100 lines
5.4 KiB
TypeScript
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 <header className="bt-titlebar" onContextMenu={titlebarContextMenu}>
|
|
<div className="bt-titlebar-drag" data-tauri-drag-region/>
|
|
<AppMenuLogo/>
|
|
<div className="bt-titlebar-spacer" data-tauri-drag-region/>
|
|
<TitlebarExtras/>
|
|
<AccountSwitcher/>
|
|
<UpdateChip/>
|
|
{/* One home for the app menu: the logo. Alt+F, F10, the palette and the account menu's last row open it there. */}
|
|
<AppMenu trigger={false}/>
|
|
{os !== 'macos' && <WindowControls maximized={maximized}/>}
|
|
</header>;
|
|
}
|
|
|
|
/** "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 <button className="bt-update-chip bt-update-chip--problem" title={chip.title}
|
|
onClick={() => invoke('open_external_url', { url: chip.href }).catch(() => {})}>{chip.label}</button>;
|
|
}
|
|
return <button className={`bt-update-chip bt-update-chip--${chip.kind}`} title={chip.title} disabled={chip.kind === 'installing'} onClick={apply}>
|
|
<span className="bt-update-chip-dot" aria-hidden="true"/>{chip.label}
|
|
</button>;
|
|
}
|
|
|
|
function WindowControls({ maximized }: { maximized: boolean }) {
|
|
const t = useT();
|
|
return <div className="bt-captions">
|
|
<button className="bt-caption" aria-label={t('wb.shell.window.minimize')} title={t('wb.shell.window.minimize')} onClick={minimize}>
|
|
<svg viewBox="0 0 10 10" aria-hidden="true"><path d="M0 5.5h10"/></svg>
|
|
</button>
|
|
<button className="bt-caption" aria-label={maximized ? t('wb.shell.window.restore') : t('wb.shell.window.maximize')} title={maximized ? t('wb.shell.window.restore') : t('wb.shell.window.maximize')} onClick={toggleMaximize}>
|
|
{maximized
|
|
? <svg viewBox="0 0 10 10" aria-hidden="true"><path d="M.5 2.5h7v7h-7z"/><path d="M2.5 2.5v-2h7v7h-2"/></svg>
|
|
: <svg viewBox="0 0 10 10" aria-hidden="true"><path d="M.5.5h9v9h-9z"/></svg>}
|
|
</button>
|
|
<button className="bt-caption bt-caption--close" aria-label={t('wb.common.close')} title={t('wb.common.close')} onClick={close}>
|
|
<svg viewBox="0 0 10 10" aria-hidden="true"><path d="M0 0l10 10M10 0L0 10"/></svg>
|
|
</button>
|
|
</div>;
|
|
}
|
|
|
|
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]) =>
|
|
<div key={direction} className="bt-grip" style={style} aria-hidden="true"
|
|
onPointerDown={event => { if (event.button === 0) { event.preventDefault(); startResize(direction); } }}/>)}</>;
|
|
}
|