Add manifest-driven desktop shell preview

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
2026-11-13 14:28:46 +08:00
parent e493eafa04
commit 330221bd5d
9 changed files with 317 additions and 3 deletions

View File

@@ -0,0 +1,68 @@
export type DesktopCommandMetadata = {
menuText: string;
toolTip: string;
icon: string;
accel: string;
};
export type DesktopMenuItem = {
type: "command" | "submenu" | "separator";
id?: string;
label?: string;
ref?: string;
items?: DesktopMenuItem[];
};
export type DesktopMenu = { label: string; items: DesktopMenuItem[] };
export type DesktopToolbar = { name: string; items: string[] };
export type DesktopWorkbench = {
id: string;
source: string;
menus: DesktopMenu[];
toolbars: DesktopToolbar[];
docks: string[];
};
export type DesktopManifest = {
schema: string;
generatedAt: string;
workbenchCount: number;
workbenches: DesktopWorkbench[];
commandMetadata: Record<string, DesktopCommandMetadata>;
commandCount: number;
menuCommandCount: number;
toolbarCommandCount: number;
};
let cache: DesktopManifest | null = null;
export async function loadDesktopManifest(url = "/api/desktop-gui-manifest.json"): Promise<DesktopManifest> {
if (cache) return cache;
const response = await fetch(url);
if (!response.ok) throw new Error(`desktop manifest HTTP ${response.status}`);
cache = (await response.json()) as DesktopManifest;
return cache;
}
export function workbenchById(manifest: DesktopManifest, id: string): DesktopWorkbench | undefined {
return manifest.workbenches.find(item => item.id === id);
}
export function commandLabel(manifest: DesktopManifest, command: string): string {
return manifest.commandMetadata[command]?.menuText?.trim() || command;
}
export function commandTooltip(manifest: DesktopManifest, command: string): string {
return manifest.commandMetadata[command]?.toolTip?.trim() || command;
}
export function menuCommandIds(menu: DesktopMenu): string[] {
const out: string[] = [];
const walk = (items: DesktopMenuItem[] = []) => {
for (const item of items) {
if (item.type === "command" && item.id) out.push(item.id);
if (item.items) walk(item.items);
}
};
walk(menu.items);
return out;
}