refactor: add typed decoder plugin runtime
This commit is contained in:
@@ -228,15 +228,15 @@
|
||||
}
|
||||
aisWindow.updateAisBar = updateAisBar;
|
||||
aisWindow.clearAisBar = function() {
|
||||
aisWindow.resetAisHistoryView?.();
|
||||
resetAisHistoryView();
|
||||
};
|
||||
aisWindow.resetAisHistoryView = function() {
|
||||
function resetAisHistoryView() {
|
||||
if (aisMessagesEl) aisMessagesEl.innerHTML = "";
|
||||
aisMessageHistory = [];
|
||||
updateAisBar();
|
||||
renderAisHistory();
|
||||
aisWindow.clearMapMarkersByType?.("ais");
|
||||
};
|
||||
}
|
||||
function renderAisHistory() {
|
||||
pruneAisMessageHistory();
|
||||
if (!aisMessagesEl) {
|
||||
@@ -272,7 +272,7 @@
|
||||
rig_id: msg.rig_id || null
|
||||
};
|
||||
}
|
||||
aisWindow.onServerAisBatch = function(messages) {
|
||||
function onServerAisBatch(messages) {
|
||||
if (!Array.isArray(messages) || messages.length === 0) return;
|
||||
if (aisStatus) aisStatus.textContent = "Receiving";
|
||||
const normalized = [];
|
||||
@@ -295,21 +295,18 @@
|
||||
pruneAisMessageHistory();
|
||||
scheduleAisBarUpdate();
|
||||
scheduleAisHistoryRender();
|
||||
};
|
||||
aisWindow.restoreAisHistory = function(messages) {
|
||||
aisWindow.onServerAisBatch?.(messages);
|
||||
};
|
||||
aisWindow.pruneAisHistoryView = function() {
|
||||
}
|
||||
function pruneAisHistoryView() {
|
||||
pruneAisMessageHistory();
|
||||
updateAisBar();
|
||||
renderAisHistory();
|
||||
};
|
||||
}
|
||||
document.getElementById("settings-clear-ais-history")?.addEventListener("click", () => {
|
||||
void (async () => {
|
||||
if (!await aisWindow.trxUi.confirm({ title: "Clear AIS history?", message: "All stored AIS messages will be permanently removed.", confirmLabel: "Clear history" })) return;
|
||||
try {
|
||||
await aisWindow.postPath?.("/clear_ais_decode");
|
||||
aisWindow.resetAisHistoryView?.();
|
||||
resetAisHistoryView();
|
||||
} catch (e) {
|
||||
console.error("AIS history clear failed", e);
|
||||
}
|
||||
@@ -321,10 +318,17 @@
|
||||
renderAisHistory();
|
||||
});
|
||||
}
|
||||
aisWindow.onServerAis = function(msg) {
|
||||
function onServerAis(msg) {
|
||||
if (aisStatus) aisStatus.textContent = "Receiving";
|
||||
addAisMessage(normalizeServerAisMessage(msg));
|
||||
};
|
||||
}
|
||||
updateAisSummary();
|
||||
aisWindow._trxDrainPendingDecode?.("ais");
|
||||
window.trxPluginRuntime.registerDecoder({
|
||||
id: "ais",
|
||||
onMessage: onServerAis,
|
||||
onBatch: onServerAisBatch,
|
||||
restore: onServerAisBatch,
|
||||
reset: resetAisHistoryView,
|
||||
prune: pruneAisHistoryView
|
||||
});
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user