feat(sim): start and stop the decoder simulator from Settings (1.65.0)

This commit is contained in:
larssand committed 2026-11-05 18:48:37 +01:00
1 parent 0ce7280cbf
commit e4874fd558
14 files changed
+309 -110

No files matched your search

+27
View File
@@ -11,6 +11,7 @@ const { createBackupService } = require("./server/backup_service");
const { createAuth, COOKIE_NAME: AUTH_COOKIE_NAME, TOKEN_MAX_AGE_MS } = require("./server/auth");
const { createTts, resolvePiperBinary } = require("./server/tts");
const { installAll: installPiperAll, VOICES: PIPER_VOICES } = require("./server/tts_install");
const { createDecoderSimulator } = require("./server/decoder_sim");
const PORT = Number(process.env.PORT || 8081);
const HOST = process.env.HOST || "0.0.0.0";
@@ -368,6 +369,32 @@ app.post("/api/ammc/stop", async (_req, res) => {
}
});
// Decoder simulator (Settings → Decoder simulator): passings without a decoder, for testing.
const decoderSim = createDecoderSimulator({
getState: () => {
const row = db.prepare("SELECT state_json FROM app_state WHERE id = 1").get();
return row ? JSON.parse(row.state_json) : null;
},
log: (line) => console.log(line),
});
app.get("/api/sim/status", (_req, res) => {
res.json(decoderSim.status());
});
app.post("/api/sim/start", async (req, res) => {
try {
const status = await decoderSim.start({ port: req.body?.port || 9099, host: HOST, lapSec: req.body?.lapSec, spreadSec: req.body?.spreadSec });
res.json({ ok: true, status });
} catch (error) {
res.status(400).json({ error: error instanceof Error ? error.message : String(error), status: decoderSim.status() });
}
});
app.post("/api/sim/stop", async (_req, res) => {
res.json({ ok: true, status: await decoderSim.stop() });
});
// Two admin browsers can be open at once, and each pushes its own full in-memory copy of
// state on every save - whichever save lands last silently overwrites everything else,
// including any other browser's edits since its own last page load. That risk is most