Dispatch standard view commands through desktop router
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -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=<id>&command=<id>` 的现有任务面板;
|
||||
|
||||
@@ -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<string[]>([]);
|
||||
const [bottomDockOpen, setBottomDockOpen] = useState(false);
|
||||
const desktopDispatcher = useRef<DesktopCommandDispatcher | null>(null);
|
||||
const desktopCommandRecords = useRef<Promise<WorkbenchCommandRecord[]> | null>(null);
|
||||
const [response, setResponse] = useState<FacadeResponse | null>(null);
|
||||
const [importedMesh, setImportedMesh] = useState<MeshPayload | null>(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 = <T,>(promise: Promise<T>) => Promise.race([promise,
|
||||
new Promise<never>((_, reject) => setTimeout(() => reject(new Error("command timed out")), 20000))]);
|
||||
|
||||
const activatePartAction = (item: PartUiAction) => {
|
||||
if (partActionDisabled(item)) return;
|
||||
|
||||
Reference in New Issue
Block a user