storebound/apps/desktop/src/traymenu/demo.tsx
CRT 5236f002f1 desktop: tray menu panels and pinnable context menus
The tray's right-click menu is drawn by the app: one tree from tray.rs
(stable submenu keys), one frameless always-on-top menu-N window per
panel rendered by tray-menu.html with the design system, placed inside
the monitor's work area. A pure panel book keeps transient and pinned
panels apart; pinned panels (pin button, Ctrl+click, middle click) are
draggable, step aside from each other and are saved in state.json
(menuPins) and restored at start. tray_update pushes the tree to the
open panels, which update in place; closed panels are destroyed. The
native menu, rendered from the same tree, stays as the fallback and on
Linux. Only menu-* windows get the menu_* commands (menu.json).

In-app context menus get the same behaviour through a pure menu stack
(ui/menu-stack.ts): pin a menu, tear off a submenu, pinned panels
survive the next menu, are draggable and re-read their entries from
live sources so data changes update them in place.

Also drops a stray diff3 marker line from CHANGELOG.md.
2026-10-24 13:44:08 +08:00

55 lines
3.2 KiB
TypeScript

// Dev only (a plain browser, never in the release bundle): the tray menu panels on fixture data, as the tray would show
// them: the root menu with Apps open beside it and a pinned Apps panel, whose values change every few seconds the way a
// store read changes them (the panels update in place).
import { useEffect, useMemo, useState } from 'react';
import type { MenuNode } from './model';
import { type MenuBridge, type MenuLang, TrayMenu } from './TrayMenu';
const STATES = [
['App Store: In review · Play: Live', 'App Store: Ready for sale · Play: Live'],
['Play: Rolling out 20%', 'Play: Rolling out 50%', 'Play: Rolling out 100%'],
['App Store: Rejected', 'App Store: Rejected'],
['App Store: Waiting for review', 'App Store: In review'],
];
const NAMES = ['Star Dash', 'Puzzle Garden', 'Pocket Chef', 'Night Runner'];
/** The tree tray.rs builds (menu_model), with fixture apps. */
export function demoNodes(tick: number, lang: MenuLang): MenuNode[] {
const tr = lang === 'tr';
const item = (id: string, label: string, enabled = true): MenuNode => ({ kind: 'item', id, label, enabled });
return [
item('tray-open', tr ? 'storebound\'u aç' : 'Open storebound'),
item('tray-read', tr ? 'Mağazaları şimdi oku' : 'Read the stores now'),
{ kind: 'sep' },
{ kind: 'sub', key: 'apps', label: tr ? 'Uygulamalar' : 'Apps', items: NAMES.map((n, i) => item(`tray-app:k${i}`, `${n} · ${STATES[i]![tick % STATES[i]!.length]}`)) },
{ kind: 'sep' },
item('tray-mute', tr ? 'Bildirimleri 1 saat sustur' : 'Mute notifications for 1 hour'),
item('tray-update', tr ? 'Güncellemeleri denetle' : 'Check for updates'),
item('tray-settings', tr ? 'Ayarlar' : 'Settings'),
{ kind: 'sep' },
item('tray-quit', tr ? 'storebound\'dan çık' : 'Quit storebound'),
];
}
const log = (what: string) => (...a: unknown[]) => console.info('tray menu', what, ...a);
const demoBridge: MenuBridge = { ready: () => {}, openSub: log('openSub'), pinSub: log('pinSub'), closeSubs: () => {}, close: log('close'), dismiss: log('dismiss'), pin: log('pin'), select: log('select') };
export function Demo({ lang }: { lang: MenuLang }) {
const [tick, setTick] = useState(0);
const q = new URLSearchParams(location.search);
const still = q.has('still');
useEffect(() => {
if (still) return;
const t = window.setInterval(() => setTick(n => n + 1), 3000);
return () => window.clearInterval(t);
}, [still]);
const nodes = useMemo(() => demoNodes(tick, lang), [tick, lang]);
return (
<>
<div className="tm-demo-at" style={{ left: 24, top: 160 }}><TrayMenu nodes={nodes} path={[]} pinned={false} hasParent={false} bridge={demoBridge} lang={lang} openKey="apps" /></div>
<div className="tm-demo-at" style={{ left: 262, top: 262 }}><TrayMenu nodes={nodes} path={['apps']} pinned={false} hasParent focusFirst bridge={demoBridge} lang={lang} /></div>
<div className="tm-demo-at" style={{ left: 690, top: 24 }}><TrayMenu nodes={nodes} path={['apps']} pinned hasParent={false} bridge={demoBridge} lang={lang} /></div>
<div className="tm-demo-at" style={{ left: 690, top: 260 }}><TrayMenu nodes={nodes} path={['gone']} pinned hasParent={false} bridge={demoBridge} lang={lang} /></div>
</>
);
}