推进 INI 面板 restore/load session workflow helper

This commit is contained in:
2026-06-14 21:30:19 +08:00
parent ddc9a4e0f3
commit 8e8a319d78
5 changed files with 364 additions and 22 deletions

View File

@@ -1,3 +1,7 @@
import {
createMachineSessionLoadSummary,
machineSessionLoadLogLines,
} from "./session-load-summary.js";
import {
createSessionSnapshotSummary,
sessionSnapshotSummaryLogLines,
@@ -23,6 +27,16 @@ export function sessionSnapshotSaveLogLines(summary) {
];
}
export function sessionSnapshotRestoreLogLines(summary) {
return [
...sessionSnapshotSummaryLogLines(summary),
`INI: ${summary.iniOpfsPath}`,
`Parameter file: ${summary.parameterOpfsPath}`,
`Tool table file: ${summary.toolTableOpfsPath}`,
`G-code: ${summary.gcodeOpfsPath ?? "-"}`,
];
}
export async function saveMachineSessionSnapshotWorkflow({
machineId,
snapshotId,
@@ -63,3 +77,54 @@ export async function saveMachineSessionSnapshotWorkflow({
logLines: sessionSnapshotSaveLogLines(summary),
};
}
export async function restoreMachineSessionSnapshotWorkflow({
machineId,
snapshotId,
snapshotFilename,
snapshotLabel,
loadMachineSessionSnapshot,
loadMachineTextFiles,
loadSession = null,
}) {
const snapshot = await loadMachineSessionSnapshot(
snapshotId,
machineId,
{ filename: snapshotFilename },
);
const files = await loadMachineTextFiles(machineId);
const summary = createSessionSnapshotSummary(snapshot, snapshotLabel ?? snapshotLabelFromSession(snapshot));
const fields = createSessionSnapshotFieldState(summary);
const result = {
snapshot,
editorIniText: files.ini,
summary,
fields,
loadSummary: null,
loadedSession: null,
logLines: sessionSnapshotRestoreLogLines(summary),
};
if (loadSession) {
const loadedSession = await loadSession();
const loadSummary = createMachineSessionLoadSummary(loadedSession);
result.loadedSession = loadedSession;
result.loadSummary = loadSummary;
result.fields = {
...fields,
sessionIni: loadSummary.iniWasmPath,
sessionParameters: loadSummary.parameterWasmPath,
sessionToolTable: loadSummary.toolTableWasmPath,
sessionGcode: summary.gcodeOpfsPath,
};
result.logLines = [
...sessionSnapshotSummaryLogLines(summary),
...machineSessionLoadLogLines(loadSummary),
`G-code: ${summary.gcodeOpfsPath ?? "-"}`,
];
}
return result;
}
function snapshotLabelFromSession(snapshot) {
return snapshot?.metadata?.snapshotLabel ?? snapshot?.sessionId ?? null;
}