refactor: add typed decoder plugin runtime

This commit is contained in:
sjg
2026-08-01 13:02:54 +02:00
parent 6a83e2e90a
commit 508cf2ba87
23 changed files with 438 additions and 324 deletions
@@ -291,7 +291,7 @@
}
aprsWindow.updateAprsBar = updateAprsBar;
aprsWindow.clearAprsBar = function() {
aprsWindow.resetAprsHistoryView?.();
resetAprsHistoryView();
};
aprsWindow.closeAprsBar = function() {
aprsBarDismissedAtMs = Date.now();
@@ -300,18 +300,18 @@
aprsBarOverlay.innerHTML = "";
}
};
aprsWindow.resetAprsHistoryView = function() {
function resetAprsHistoryView() {
if (aprsPacketsEl) aprsPacketsEl.innerHTML = "";
aprsPacketHistory = [];
updateAprsBar();
renderAprsHistory();
aprsWindow.clearMapMarkersByType?.("aprs");
};
aprsWindow.pruneAprsHistoryView = function() {
}
function pruneAprsHistoryView() {
pruneAprsPacketHistory();
updateAprsBar();
renderAprsHistory();
};
}
function addAprsPacket(pkt) {
const tsMs = Number.isFinite(pkt.ts_ms) ? Number(pkt.ts_ms) : Date.now();
pkt._tsMs = tsMs;
@@ -327,7 +327,7 @@
function normalizeServerAprsPacket(pkt) {
return normalizeAprsPacket(pkt, aprsWindow.getDecodeRigMeta?.() ?? null);
}
aprsWindow.onServerAprsBatch = function(packets) {
function onServerAprsBatch(packets) {
if (!Array.isArray(packets) || packets.length === 0) return;
if (aprsStatus) aprsStatus.textContent = "Receiving";
const normalized = [];
@@ -348,16 +348,13 @@
pruneAprsPacketHistory();
if (hasCrcOk) scheduleAprsBarUpdate();
scheduleAprsHistoryRender();
};
aprsWindow.restoreAprsHistory = function(packets) {
aprsWindow.onServerAprsBatch?.(packets);
};
}
document.getElementById("settings-clear-aprs-history")?.addEventListener("click", () => {
void (async () => {
if (!await aprsWindow.trxUi.confirm({ title: "Clear APRS history?", message: "All stored APRS packets will be permanently removed.", confirmLabel: "Clear history" })) return;
try {
await aprsWindow.postPath?.("/clear_aprs_decode");
aprsWindow.resetAprsHistoryView?.();
resetAprsHistoryView();
} catch (e) {
console.error("APRS history clear failed", e);
}
@@ -395,10 +392,17 @@
renderAprsHistory();
});
}
aprsWindow.onServerAprs = function(pkt) {
function onServerAprs(pkt) {
if (aprsStatus) aprsStatus.textContent = "Receiving";
addAprsPacket(normalizeServerAprsPacket(pkt));
};
}
renderAprsHistory();
aprsWindow._trxDrainPendingDecode?.("aprs");
window.trxPluginRuntime.registerDecoder({
id: "aprs",
onMessage: onServerAprs,
onBatch: onServerAprsBatch,
restore: onServerAprsBatch,
reset: resetAprsHistoryView,
prune: pruneAprsHistoryView
});
})();