diff --git a/web/docs/current/desktop-parity-continuation.md b/web/docs/current/desktop-parity-continuation.md index 660edc8c..9287081c 100644 --- a/web/docs/current/desktop-parity-continuation.md +++ b/web/docs/current/desktop-parity-continuation.md @@ -69,6 +69,10 @@ - **快捷键已写入 OPFS**:`freecad-parameters/web-shortcuts.json`; 实测录制 `Ctrl+Shift+K` 后文件内容 `{"Std_About":"Ctrl+Shift+K"}`,0 pageError。 运行时仍优先 localStorage 缓存,OPFS 作为持久层。 +- **标准视图/开关命令直连 dispatcher**:`Std_View*`、`Std_Toggle*`、`Std_DrawStyle`、 + BoxSelection 等不再打开 TaskFrame,而是走 `DesktopCommandDispatcher` + 的 scene/dock 命令(20 秒超时)。快捷键实测 `Std_ViewFitAll` 已进入内核, + 返回 “The current document has no mounted 3D view”(空文档前置未满足,符合预期)。 - 说明:Python 控制台尚未接入;原生 Shortcut 参数同步待 P3。 - 非 Part 菜单命令改为打开 **React TaskFrame 模态**(`web/src/shell/task-frame.tsx`), iframe 复用 `/workbench.html?module=&command=` 的现有任务面板; diff --git a/web/src/project-shell.tsx b/web/src/project-shell.tsx index f98a27f8..e9739ed3 100644 --- a/web/src/project-shell.tsx +++ b/web/src/project-shell.tsx @@ -90,6 +90,8 @@ import { PreferencesDialog, loadWebPreferences } from "./shell/preferences-dialo import { formatLength, formatVolume, unitInfo } from "./shell/units.js"; import { ShortcutEditor, ShortcutManager } from "./shell/shortcut-manager.js"; import { BottomDock } from "./shell/bottom-dock.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"; @@ -216,6 +218,8 @@ function App() { const [status, setStatus] = useState("Project session ready"); const [reportLog, setReportLog] = useState([]); const [bottomDockOpen, setBottomDockOpen] = useState(false); + const desktopDispatcher = useRef(null); + const desktopCommandRecords = useRef | null>(null); const [response, setResponse] = useState(null); const [importedMesh, setImportedMesh] = useState(null); const [importing, setImporting] = useState(false); @@ -1720,11 +1724,37 @@ 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 = (command: string) => { + const executeManifestCommand = async (command: string) => { if (!active) return; - setParityTask({ module: workbench, command }); - setStatus(`${command}: opened React task frame`); + const sceneCommand = /^(Std_View|Std_Toggle|Std_DrawStyle|Std_AlignToSelection|Std_BoxSelection|Part_BoxSelection)/.test(command); + if (!sceneCommand) { + setParityTask({ module: workbench, command }); + setStatus(`${command}: opened React task frame`); + 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; + const record = records.find(item => item.command === command && ["Web", "Std", "Show", "Part"].includes(item.module)) + ?? records.find(item => item.command === command); + if (!record) throw new Error("no command matrix record"); + const response = await desktopPromise(desktopDispatcher.current.execute(record, {}, nativeName(active))); + if (response.kind === "error") setStatus(`${command}: ${response.error.message}`); + else setStatus(`${command}: executed`); + } catch (error) { + setStatus(`${command}: ${String((error as Error)?.message ?? error)}`); + } }; + const desktopPromise = (promise: Promise) => Promise.race([promise, + new Promise((_, reject) => setTimeout(() => reject(new Error("command timed out")), 20000))]); const activatePartAction = (item: PartUiAction) => { if (partActionDisabled(item)) return;