推进 INI 面板 run readiness workflow helper
This commit is contained in:
@@ -34,6 +34,55 @@ export function selectSessionGcodeProgram({
|
||||
};
|
||||
}
|
||||
|
||||
export function createRunSessionReadinessState({
|
||||
loadedSession = null,
|
||||
snapshot = null,
|
||||
defaultFilename,
|
||||
defaultOpfsPath,
|
||||
wasmPath,
|
||||
gcodeFilenameFromProgramPath,
|
||||
}) {
|
||||
const program = selectSessionGcodeProgram({
|
||||
snapshot,
|
||||
defaultFilename,
|
||||
defaultOpfsPath,
|
||||
wasmPath,
|
||||
gcodeFilenameFromProgramPath,
|
||||
});
|
||||
const missing = [];
|
||||
if (!loadedSession?.ini?.wasmPath) {
|
||||
missing.push("loaded-session");
|
||||
}
|
||||
if (!program.filename || !program.opfsPath || !program.wasmPath) {
|
||||
missing.push("gcode-program");
|
||||
}
|
||||
const canRun = missing.length === 0;
|
||||
return {
|
||||
phase: canRun ? "ready" : "blocked",
|
||||
canRun,
|
||||
missing,
|
||||
loadedSession: {
|
||||
iniWasmPath: loadedSession?.ini?.wasmPath ?? null,
|
||||
},
|
||||
snapshot: {
|
||||
present: Boolean(snapshot),
|
||||
label: snapshot?.metadata?.snapshotLabel ?? snapshot?.sessionId ?? null,
|
||||
workflow: snapshot?.metadata?.workflow ?? null,
|
||||
gcodeOpfsPath: snapshot?.payload?.files?.gcode ?? null,
|
||||
},
|
||||
defaultProgram: {
|
||||
filename: defaultFilename ?? null,
|
||||
opfsPath: defaultOpfsPath ?? null,
|
||||
wasmPath: wasmPath ?? null,
|
||||
},
|
||||
program,
|
||||
runButton: {
|
||||
enabled: canRun,
|
||||
reason: canRun ? null : `Missing ${missing.join(", ")}.`,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function runSessionContextLogLines(program, snapshot = null, snapshotLabel = null) {
|
||||
const summary = createSessionSnapshotSummary({
|
||||
metadata: snapshot?.metadata ?? {},
|
||||
@@ -58,16 +107,18 @@ export async function runGcodeSessionWorkflow({
|
||||
summarizeRun = () => ({}),
|
||||
snapshotLabel = null,
|
||||
}) {
|
||||
if (!loadedSession) {
|
||||
throw new Error("Load a machine session before running G-code.");
|
||||
}
|
||||
const program = selectSessionGcodeProgram({
|
||||
const readiness = createRunSessionReadinessState({
|
||||
loadedSession,
|
||||
snapshot,
|
||||
defaultFilename,
|
||||
defaultOpfsPath,
|
||||
wasmPath,
|
||||
gcodeFilenameFromProgramPath,
|
||||
});
|
||||
if (!readiness.canRun) {
|
||||
throw new Error("Load a machine session before running G-code.");
|
||||
}
|
||||
const program = readiness.program;
|
||||
const programText = await loadGcodeProgram(program.filename);
|
||||
interp.writeTextFile(program.wasmPath, programText);
|
||||
const resultText = interp.runFileWithIni(program.wasmPath, loadedSession.ini.wasmPath).trim();
|
||||
@@ -91,6 +142,7 @@ export async function runGcodeSessionWorkflow({
|
||||
resultText,
|
||||
motionSnapshots,
|
||||
summary,
|
||||
readiness,
|
||||
fields: {
|
||||
sessionGcode: program.opfsPath,
|
||||
runStatus: summary.runStatus,
|
||||
|
||||
Reference in New Issue
Block a user