Dispatch manifest workbench commands through desktop router
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -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<Record<string, DesignResult>>({});
|
||||
const [workbenches, setWorkbenches] = useState<Record<string, "Part" | "Sketcher" | "PartDesign" | "Spreadsheet" | "Surface" | "Assembly" | "Draft" | "Architecture" | "TechDraw" | "CAM">>(() => initialWorkbench ? { [initialDocumentId]: initialWorkbench } : {});
|
||||
const workbench = workbenches[active] ?? "Part";
|
||||
const desktopDispatcher = useRef<DesktopCommandDispatcher | null>(null);
|
||||
const desktopCommandRecords = useRef<Promise<Array<Record<string, unknown>>> | null>(null);
|
||||
const [selectedSheets, setSelectedSheets] = useState<Record<string, string>>({});
|
||||
const [csvPanel, setCsvPanel] = useState<{ id: string; mode: "import" | "export"; selected?: string; done(result: Record<string, unknown>): void } | null>(null);
|
||||
const [sheetRanges, setSheetRanges] = useState<Record<string, string>>({});
|
||||
@@ -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<never>((_, 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() {
|
||||
</div></details>
|
||||
{workbench === "Part" && <PartWorkbenchMenu disabled={partActionDisabled} activate={activatePartAction} currentTask={workspaceTask} />}
|
||||
{workbench !== "Part" && <ParityWorkbenchMenu workbench={workbench}
|
||||
onCommand={command => setStatus(`${command}: selected (desktop menu; execution wiring pending)`)} />}
|
||||
onCommand={command => void executeManifestCommand(command)} />}
|
||||
{workbench !== "Part" && <WorkbenchParityMenu workbench={workbench} />}
|
||||
</nav>
|
||||
<PersistentToolbarWorkspace router={router} documentId={nativeName(active || initialDocumentId)} workbench={workbench}>
|
||||
|
||||
Reference in New Issue
Block a user