refactor: route all decoders through plugin runtime

This commit is contained in:
sjg
2026-08-01 13:06:38 +02:00
parent 508cf2ba87
commit 9fef0ebc7b
19 changed files with 255 additions and 319 deletions
@@ -2,6 +2,8 @@
//
// SPDX-License-Identifier: GPL-2.0-or-later
import type { PluginRuntimeWindow } from "./runtime-contract.js";
export {};
interface WsprMessage {
@@ -25,14 +27,9 @@ interface WsprBridge {
takeSchedulerControlForDecoderDisable?: (button: HTMLElement) => Promise<void>;
postPath?: (path: string) => Promise<unknown>;
trxUi: { confirm(options: { title: string; message: string; confirmLabel: string }): Promise<boolean> };
onServerWsprBatch?: (messages: WsprMessage[]) => void;
restoreWsprHistory?: (messages: WsprMessage[]) => void;
pruneWsprHistoryView?: () => void;
resetWsprHistoryView?: () => void;
onServerWspr?: (message: WsprMessage) => void;
[key: string]: unknown;
}
const wsprWindow = window as unknown as WsprBridge;
const wsprWindow = window as unknown as WsprBridge & PluginRuntimeWindow;
// --- WSPR Decoder Plugin (server-side decode) ---
const wsprStatus = document.getElementById("wspr-status");
@@ -142,7 +139,7 @@ function normalizeServerWsprMessage(msg: WsprMessage): { raw: string; grids: str
};
}
wsprWindow.onServerWsprBatch = function(messages: WsprMessage[]) {
function onServerWsprBatch(messages: WsprMessage[]): void {
if (!Array.isArray(messages) || messages.length === 0) return;
if (wsprStatus) wsprStatus.textContent = "Receiving";
const normalized: WsprMessage[] = [];
@@ -161,17 +158,12 @@ wsprWindow.onServerWsprBatch = function(messages: WsprMessage[]) {
wsprMessageHistory = normalized.concat(wsprMessageHistory);
pruneWsprMessageHistory();
scheduleWsprHistoryRender();
};
}
wsprWindow.restoreWsprHistory = function(messages: WsprMessage[]) {
const callback = wsprWindow.onServerWsprBatch;
if (typeof callback === "function") callback(messages);
};
wsprWindow.pruneWsprHistoryView = function() {
function pruneWsprHistoryView(): void {
pruneWsprMessageHistory();
renderWsprHistory();
};
}
function escapeWsprHtml(input: string): string {
return input
@@ -266,12 +258,12 @@ function applyWsprFilterToRow(row: HTMLElement): void {
row.style.display = message.includes(wsprFilterText) ? "" : "none";
}
wsprWindow.resetWsprHistoryView = function() {
function resetWsprHistoryView(): void {
if (wsprMessagesEl) wsprMessagesEl.innerHTML = "";
wsprMessageHistory = [];
renderWsprHistory();
if (wsprWindow.clearMapMarkersByType) wsprWindow.clearMapMarkersByType("wspr");
};
}
if (wsprFilterInput) {
wsprFilterInput.addEventListener("input", () => {
@@ -311,14 +303,14 @@ document.getElementById("settings-clear-wspr-history")?.addEventListener("click"
if (!await wsprWindow.trxUi.confirm({ title: "Clear WSPR history?", message: "All stored WSPR decodes will be permanently removed.", confirmLabel: "Clear history" })) return;
try {
await wsprWindow.postPath?.("/clear_wspr_decode");
wsprWindow.resetWsprHistoryView?.();
resetWsprHistoryView();
} catch (error: unknown) {
console.error("WSPR history clear failed", error);
}
})();
});
wsprWindow.onServerWspr = function(msg: WsprMessage) {
function onServerWspr(msg: WsprMessage): void {
if (wsprStatus) wsprStatus.textContent = "Receiving";
const next = normalizeServerWsprMessage(msg);
if (next.grids.length > 0 && wsprWindow.mapAddLocator) {
@@ -328,4 +320,13 @@ wsprWindow.onServerWspr = function(msg: WsprMessage) {
});
}
addWsprMessage(next.history);
};
}
wsprWindow.trxPluginRuntime.registerDecoder({
id: "wspr",
onMessage: onServerWspr,
onBatch: onServerWsprBatch,
restore: onServerWsprBatch,
prune: pruneWsprHistoryView,
reset: resetWsprHistoryView,
});