推进 INI 面板会话恢复加载流程

This commit is contained in:
2026-06-14 15:24:26 +08:00
parent 558960b2f2
commit 633b8fd0ed
4 changed files with 127 additions and 28 deletions

View File

@@ -310,6 +310,37 @@ function syncEditorToWasmFs() {
requireIniSdk().writeTextFile(WASM_FILE, editor.value);
}
async function restoreSessionSnapshotToEditor() {
const snapshot = await loadMachineSessionSnapshot(
SESSION_SNAPSHOT_ID,
MACHINE_ID,
{ filename: SESSION_SNAPSHOT_FILENAME },
);
const files = await loadMachineTextFiles(MACHINE_ID);
editor.value = files.ini;
setField("sessionIni", snapshot.payload.files.ini);
setField("sessionParameters", snapshot.payload.files.parameters);
setField("sessionToolTable", snapshot.payload.files.toolTable);
setField("sessionGcode", snapshot.payload.files.gcode);
setField("sessionSnapshot", `${snapshot.sessionId}/${SESSION_SNAPSHOT_FILENAME}`);
return snapshot;
}
async function loadMachineSessionIntoWasm() {
loadedSession = await loadMachineSessionFromOpfs(
requireInterpSdk(),
MACHINE_ID,
{
...SESSION_WASM_FILES,
iniSdk: requireIniSdk(),
},
);
setField("sessionIni", loadedSession.ini.wasmPath);
setField("sessionParameters", loadedSession.parameters.wasmPath);
setField("sessionToolTable", loadedSession.toolTable.wasmPath);
return loadedSession;
}
async function loadSample() {
setLog(`Fetching ${SAMPLE_PATH}`);
const response = await fetch(SAMPLE_PATH);
@@ -463,18 +494,7 @@ document.getElementById("save-session-snapshot").addEventListener("click", async
document.getElementById("restore-session-snapshot").addEventListener("click", async () => {
try {
const snapshot = await loadMachineSessionSnapshot(
SESSION_SNAPSHOT_ID,
MACHINE_ID,
{ filename: SESSION_SNAPSHOT_FILENAME },
);
const files = await loadMachineTextFiles(MACHINE_ID);
editor.value = files.ini;
setField("sessionIni", snapshot.payload.files.ini);
setField("sessionParameters", snapshot.payload.files.parameters);
setField("sessionToolTable", snapshot.payload.files.toolTable);
setField("sessionGcode", snapshot.payload.files.gcode);
setField("sessionSnapshot", `${snapshot.sessionId}/${SESSION_SNAPSHOT_FILENAME}`);
const snapshot = await restoreSessionSnapshotToEditor();
setLog(
[
"Restored machine session snapshot from OPFS.",
@@ -492,17 +512,7 @@ document.getElementById("restore-session-snapshot").addEventListener("click", as
document.getElementById("load-session").addEventListener("click", async () => {
try {
loadedSession = await loadMachineSessionFromOpfs(
requireInterpSdk(),
MACHINE_ID,
{
...SESSION_WASM_FILES,
iniSdk: requireIniSdk(),
},
);
setField("sessionIni", loadedSession.ini.wasmPath);
setField("sessionParameters", loadedSession.parameters.wasmPath);
setField("sessionToolTable", loadedSession.toolTable.wasmPath);
await loadMachineSessionIntoWasm();
setLog(
[
"Loaded machine session into the interpreter WASM filesystem.",
@@ -518,6 +528,28 @@ document.getElementById("load-session").addEventListener("click", async () => {
}
});
document.getElementById("restore-load-session").addEventListener("click", async () => {
try {
const snapshot = await restoreSessionSnapshotToEditor();
await loadMachineSessionIntoWasm();
setField("sessionGcode", snapshot.payload.files.gcode);
setLog(
[
"Restored and loaded machine session snapshot.",
`Snapshot: ${snapshot.sessionId}/${SESSION_SNAPSHOT_FILENAME}`,
`INI: ${loadedSession.ini.opfsPath} -> ${loadedSession.ini.wasmPath}`,
`Parameter file: ${loadedSession.parameters.opfsPath} -> ${loadedSession.parameters.wasmPath}`,
`Parameters: ${loadedSession.parameters.result.trim()}`,
`Tool table file: ${loadedSession.toolTable.opfsPath} -> ${loadedSession.toolTable.wasmPath}`,
`Tool table: ${loadedSession.toolTable.result.trim()}`,
`G-code: ${snapshot.payload.files.gcode ?? "-"}`,
].join("\n"),
);
} catch (error) {
setLog(`Machine session snapshot restore/load failed: ${error.message}`, true);
}
});
document.getElementById("run-gcode").addEventListener("click", async () => {
try {
if (!loadedSession) {

View File

@@ -230,6 +230,7 @@
<button id="load-machine-files">Load Machine Files</button>
<button id="save-session-snapshot">Save Session Snapshot</button>
<button id="restore-session-snapshot">Restore Session Snapshot</button>
<button id="restore-load-session" class="secondary">Restore And Load Session</button>
<button id="sync-wasm">Sync To WASM FS</button>
<button id="query" class="secondary">Query LinuxCNC Fields</button>
<button id="load-session" class="secondary">Load Machine Session</button>

View File

@@ -413,10 +413,10 @@ TOOL_TABLE = browser-tool.tbl
if (!uiDocument.getElementById("ini-editor").value.includes("MACHINE = browser-smoke")) {
throw new Error("UI restored session snapshot did not reload INI text");
}
uiDocument.getElementById("load-session").click();
uiDocument.getElementById("restore-load-session").click();
await waitFor(
() => uiDocument.getElementById("log")?.textContent.includes("Loaded machine session"),
"machine session load",
() => uiDocument.getElementById("log")?.textContent.includes("Restored and loaded machine session"),
"restore and load machine session",
);
assertEqual(
uiDocument.getElementById("field-session-ini").textContent,
@@ -435,9 +435,10 @@ TOOL_TABLE = browser-tool.tbl
);
const uiLog = uiDocument.getElementById("log").textContent;
if (!uiLog.includes("restore_parameters=0") || !uiLog.includes("tooldata_load=0")) {
throw new Error(`UI session log missing LinuxCNC load result: ${uiLog}`);
throw new Error(`UI restore/load session log missing LinuxCNC load result: ${uiLog}`);
}
if (
!uiLog.includes("Snapshot: ui-machine-session/ui-machine-session.json") ||
!uiLog.includes(
"Parameter file: linuxcnc/machines/xyzab-tdr/linuxcnc.var -> /work/session-linuxcnc.var",
) ||
@@ -445,7 +446,7 @@ TOOL_TABLE = browser-tool.tbl
"Tool table file: linuxcnc/machines/xyzab-tdr/tool.tbl -> /work/session-tool.tbl",
)
) {
throw new Error(`UI session log missing OPFS default file mapping: ${uiLog}`);
throw new Error(`UI restore/load session log missing OPFS default file mapping: ${uiLog}`);
}
uiDocument.getElementById("run-gcode").click();
await waitFor(