From 452f0b976fe04e464c07baae15f2900d7c40135f Mon Sep 17 00:00:00 2001 From: wangdequan Date: Fri, 13 Nov 2026 16:39:39 +0800 Subject: [PATCH] Dispatch manifest workbench commands through desktop router Co-Authored-By: Claude Code --- .../current/desktop-parity-continuation.md | 5 ++- web/src/project-shell.tsx | 34 ++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/web/docs/current/desktop-parity-continuation.md b/web/docs/current/desktop-parity-continuation.md index 9821c5e8..2de25dec 100644 --- a/web/docs/current/desktop-parity-continuation.md +++ b/web/docs/current/desktop-parity-continuation.md @@ -44,7 +44,10 @@ - Workbench 选择器扩展到 29 个模块(Part 保持原有 `PartWorkbenchMenu`); - 选中 BIM 后菜单显示 2D Drafting / 3D/BIM / Annotation / Manage / Flamingo / Fasteners / Utils;截图 `BIM-web-menu.png`; - - Part 回归审计仍 0 错误/0 溢出;命令点击当前只写状态(execution wiring pending)。 + - Part 回归审计仍 0 错误/0 溢出。 + - 非 Part 菜单命令已接 `DesktopCommandDispatcher`:按 `command-matrix` 找记录、 + 用空参数执行,状态栏显示 running/executed/error;20 秒超时提示改用工作台任务。 + BIM_TogglePanels 实测进入 running(该命令需要面板任务,尚需专用 React 桥)。 - Python InitGui 解析改为位置感知变量解析(`self.*`、重赋值、`+` 拼接), 菜单命令 513、工具栏命令 362,gui-missing 降至 623。 - 说明:preview 页仅渲染清单与命令回调;统一执行路由尚待 P2/P3。 diff --git a/web/src/project-shell.tsx b/web/src/project-shell.tsx index 9f80a8c6..21432b2b 100644 --- a/web/src/project-shell.tsx +++ b/web/src/project-shell.tsx @@ -83,6 +83,8 @@ import { RecoveryController } from "./recovery-controller.js"; import { mountQueueRecoveryPanel } from "./queue-recovery-panel.js"; import { PartDesignWorkspace } from "./partdesign-workspace-component.js"; import { ParityWorkbenchMenu } from "./shell/workbench-menu.js"; +import { DesktopCommandDispatcher } from "./desktop-command-dispatcher.js"; +import type { WorkbenchCommandRecord } from "./workbench-command-facade.js"; import { DocumentTree, type DocumentTreeNode } from "./document-tree.js"; import { PARTDESIGN_DOCUMENT_COMMAND, PARTDESIGN_DOCUMENT_SCHEMA, type DesignAction, type DesignPayload, type DesignResult } from "./partdesign-document-facade.js"; @@ -311,6 +313,8 @@ function App() { const [designSnapshots, setDesignSnapshots] = useState>({}); const [workbenches, setWorkbenches] = useState>(() => initialWorkbench ? { [initialDocumentId]: initialWorkbench } : {}); const workbench = workbenches[active] ?? "Part"; + const desktopDispatcher = useRef(null); + const desktopCommandRecords = useRef>> | null>(null); const [selectedSheets, setSelectedSheets] = useState>({}); const [csvPanel, setCsvPanel] = useState<{ id: string; mode: "import" | "export"; selected?: string; done(result: Record): void } | null>(null); const [sheetRanges, setSheetRanges] = useState>({}); @@ -1700,6 +1704,34 @@ function App() { || !!workspaceTask || !!viewCommand || !!csvPanel || item.command === "Part_ColorPerFace" && (compoundSelection.length !== 1 || !partSnapshots[active]?.objects?.some(object => object.name === compoundSelection[0] && object.topology?.Face && object.type !== "App::Link")); + const executeManifestCommand = async (command: string) => { + if (!active) return; + setStatus(`${command}: running`); + try { + desktopDispatcher.current ??= new DesktopCommandDispatcher(router); + if (!desktopCommandRecords.current) { + desktopCommandRecords.current = fetch("/api/workbench-command-matrix.json").then(async response => { + if (!response.ok) throw new Error(`command matrix HTTP ${response.status}`); + const payload = await response.json() as { records?: WorkbenchCommandRecord[] }; + return payload.records ?? []; + }); + } + const records = await desktopCommandRecords.current as WorkbenchCommandRecord[]; + const record = records.find(item => item.command === command + && [workbench, "Web", "Std"].includes(item.module)) + ?? records.find(item => item.command === command); + if (!record) throw new Error("no command matrix record"); + const response = await Promise.race([ + desktopDispatcher.current.execute(record, {}, nativeName(active)), + new Promise((_, reject) => setTimeout(() => reject(new Error("command timed out; open its workbench task")), 20000)), + ]); + if (response.kind === "error") setStatus(`${command}: ${response.error.message}`); + else setStatus(`${command}: executed`); + } catch (error) { + setStatus(`${command}: ${String((error as Error)?.message ?? error)}`); + } + }; + const activatePartAction = (item: PartUiAction) => { if (partActionDisabled(item)) return; resetTaskDrafts(); setViewCommand(""); setPartTaskMode(item); setRetainedPartResponse(null); @@ -1895,7 +1927,7 @@ function App() { {workbench === "Part" && } {workbench !== "Part" && setStatus(`${command}: selected (desktop menu; execution wiring pending)`)} />} + onCommand={command => void executeManifestCommand(command)} />} {workbench !== "Part" && }