Dispatch standard view commands through desktop router
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -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