推进 INI 面板会话恢复加载流程
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user