推进 OPFS G-code 程序路径 helper

This commit is contained in:
2026-06-14 15:57:35 +08:00
parent a158f66071
commit d40a6422e8
5 changed files with 115 additions and 13 deletions

View File

@@ -8,6 +8,7 @@ import {
saveTextFile,
} from "../../opfs/file-service.js";
import {
gcodeFilenameFromProgramPath,
loadGcodeProgram,
loadMachineTextFiles,
machineFilePaths,
@@ -311,23 +312,24 @@ function syncEditorToWasmFs() {
requireIniSdk().writeTextFile(WASM_FILE, editor.value);
}
function gcodeFilenameFromSnapshotPath(path) {
const prefix = "linuxcnc/gcode/";
if (typeof path !== "string" || !path.startsWith(prefix)) {
return GCODE_FILENAME;
}
const filename = path.slice(prefix.length);
return filename || GCODE_FILENAME;
}
async function loadSelectedGcodeProgram() {
const opfsPath = restoredSessionSnapshot?.payload?.files?.gcode;
const filename = gcodeFilenameFromSnapshotPath(opfsPath);
const hasSnapshotGcode = typeof opfsPath === "string" && opfsPath.startsWith("linuxcnc/gcode/");
let filename = GCODE_FILENAME;
let selectedOpfsPath = `linuxcnc/gcode/${GCODE_FILENAME}`;
let source = "default";
if (typeof opfsPath === "string") {
try {
filename = gcodeFilenameFromProgramPath(opfsPath);
selectedOpfsPath = opfsPath;
source = "snapshot";
} catch {
filename = GCODE_FILENAME;
}
}
return {
filename,
opfsPath: opfsPath ?? `linuxcnc/gcode/${filename}`,
source: hasSnapshotGcode ? "snapshot" : "default",
opfsPath: selectedOpfsPath,
source,
wasmPath: GCODE_WASM_FILE,
text: await loadGcodeProgram(filename),
};