refactor: replace feature globals with typed services
This commit is contained in:
@@ -384,7 +384,7 @@
|
||||
sdrSquelchSupported = false;
|
||||
}
|
||||
updateSdrSquelchControlVisibility();
|
||||
if (typeof vchanApplyCapabilities === "function") vchanApplyCapabilities(caps);
|
||||
window.trx?.modules?.vchan?.applyCapabilities(caps);
|
||||
}
|
||||
var freqEl = document.getElementById("freq");
|
||||
var centerFreqEl = document.getElementById("center-freq");
|
||||
@@ -1217,9 +1217,9 @@
|
||||
if (themeToggleBtn) {
|
||||
themeToggleBtn.addEventListener("click", () => {
|
||||
setTheme(currentTheme() === "dark" ? "light" : "dark");
|
||||
updateMapBaseLayerForTheme(currentTheme());
|
||||
syncLocatorMarkerStyles();
|
||||
refreshAisMarkerColors();
|
||||
window.trx.modules.map?.updateMapBaseLayerForTheme(currentTheme());
|
||||
window.trx.modules.map?.syncLocatorMarkerStyles();
|
||||
window.trx.modules.map?.refreshAisMarkerColors();
|
||||
scheduleOverviewDraw();
|
||||
if (typeof scheduleSpectrumDraw === "function" && lastSpectrumData) scheduleSpectrumDraw();
|
||||
});
|
||||
@@ -1227,9 +1227,9 @@
|
||||
if (headerStylePickSelect) {
|
||||
headerStylePickSelect.addEventListener("change", () => {
|
||||
setStyle(headerStylePickSelect.value);
|
||||
updateMapBaseLayerForTheme(currentTheme());
|
||||
syncLocatorMarkerStyles();
|
||||
refreshAisMarkerColors();
|
||||
window.trx.modules.map?.updateMapBaseLayerForTheme(currentTheme());
|
||||
window.trx.modules.map?.syncLocatorMarkerStyles();
|
||||
window.trx.modules.map?.refreshAisMarkerColors();
|
||||
});
|
||||
}
|
||||
function readyText() {
|
||||
@@ -1315,9 +1315,9 @@
|
||||
window.trxUi?.setActiveRig(lastActiveRigId);
|
||||
if (rigListChanged) {
|
||||
window.trx.modules.scheduler?.setRig(lastActiveRigId);
|
||||
if (typeof setBackgroundDecodeRig === "function") setBackgroundDecodeRig(lastActiveRigId);
|
||||
if (typeof bmPopulateScopePicker === "function") bmPopulateScopePicker();
|
||||
if (typeof bmFetch === "function") bmFetch(document.getElementById("bm-category-filter")?.value || "");
|
||||
window.trx.modules.backgroundDecode?.setRig(lastActiveRigId);
|
||||
window.trx.modules.bookmarks?.populateScopePicker();
|
||||
window.trx.modules.bookmarks?.fetch(document.getElementById("bm-category-filter")?.value || "");
|
||||
}
|
||||
window.trx.modules.map?.updateMapRigFilter();
|
||||
}
|
||||
@@ -1562,12 +1562,13 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
if (typeof vchanChannels !== "undefined" && Array.isArray(vchanChannels)) {
|
||||
vchanChannels.forEach((ch) => {
|
||||
const virtualChannels = window.trx.modules.vchan?.channels || [];
|
||||
if (virtualChannels.length > 0) {
|
||||
virtualChannels.forEach((ch) => {
|
||||
if (!Number.isFinite(ch.freq_hz) || ch.freq_hz <= 0) return;
|
||||
const xc = hzToX(ch.freq_hz);
|
||||
if (xc < 0 || xc > W) return;
|
||||
const isActive = ch.id === vchanActiveId;
|
||||
const isActive = ch.id === window.trx.modules.vchan?.activeId;
|
||||
const color = cssColorToRgba("#38bdf8");
|
||||
if (isActive) {
|
||||
signalOverlayGl.drawSegments([xc, 0, xc, H], color, Math.max(1.5, dpr * 1.5));
|
||||
@@ -1852,7 +1853,8 @@
|
||||
refreshWavelengthDisplay(lastFreqHz);
|
||||
}
|
||||
function activeRdsChannelId() {
|
||||
if (typeof vchanActiveId !== "undefined" && vchanActiveId) return vchanActiveId;
|
||||
const virtualChannelId = window.trx.modules.vchan?.activeId;
|
||||
if (virtualChannelId) return virtualChannelId;
|
||||
return null;
|
||||
}
|
||||
function activeChannelRds() {
|
||||
@@ -1861,23 +1863,25 @@
|
||||
if (activeId) {
|
||||
const rds = vchanRdsById.get(activeId);
|
||||
if (rds) return rds;
|
||||
if (typeof vchanChannels !== "undefined" && Array.isArray(vchanChannels) && vchanChannels.length > 0) {
|
||||
if (vchanChannels[0].id === activeId) return primaryRds;
|
||||
const virtualChannels = window.trx.modules.vchan?.channels || [];
|
||||
if (virtualChannels.length > 0) {
|
||||
if (virtualChannels[0].id === activeId) return primaryRds;
|
||||
}
|
||||
}
|
||||
return primaryRds;
|
||||
}
|
||||
function activeChannelIsWfm() {
|
||||
if (typeof vchanChannels !== "undefined" && Array.isArray(vchanChannels) && vchanChannels.length > 0) {
|
||||
const virtualChannels = window.trx.modules.vchan?.channels || [];
|
||||
if (virtualChannels.length > 0) {
|
||||
const activeId = activeRdsChannelId();
|
||||
const active = vchanChannels.find((ch) => ch.id === activeId) || vchanChannels[0];
|
||||
const active = virtualChannels.find((ch) => ch.id === activeId) || virtualChannels[0];
|
||||
return String(active?.mode || "").toUpperCase() === "WFM";
|
||||
}
|
||||
return lastModeName === "WFM";
|
||||
}
|
||||
function activeChannelFreqHz() {
|
||||
if (typeof vchanActiveChannel === "function") {
|
||||
const ch = vchanActiveChannel();
|
||||
if (window.trx.modules.vchan) {
|
||||
const ch = window.trx.modules.vchan.activeChannel();
|
||||
if (Number.isFinite(ch?.freq_hz)) return ch.freq_hz;
|
||||
}
|
||||
return lastFreqHz;
|
||||
@@ -1899,11 +1903,12 @@
|
||||
}
|
||||
function collectRdsOverlayEntries() {
|
||||
const entries = [];
|
||||
if (typeof vchanChannels !== "undefined" && Array.isArray(vchanChannels) && vchanChannels.length > 0) {
|
||||
for (const ch of vchanChannels) {
|
||||
const virtualChannels = window.trx.modules.vchan?.channels || [];
|
||||
if (virtualChannels.length > 0) {
|
||||
for (const ch of virtualChannels) {
|
||||
if (String(ch?.mode || "").toUpperCase() !== "WFM") continue;
|
||||
if (!Number.isFinite(ch?.freq_hz)) continue;
|
||||
const rds = vchanRdsById.get(ch.id) || (vchanChannels[0].id === ch.id ? primaryRds : null);
|
||||
const rds = vchanRdsById.get(ch.id) || (virtualChannels[0].id === ch.id ? primaryRds : null);
|
||||
if (!rds) continue;
|
||||
entries.push({ id: ch.id, freq_hz: ch.freq_hz, rds });
|
||||
}
|
||||
@@ -3145,7 +3150,7 @@ ${unsupportedBandSummary()}`;
|
||||
prevRenderData.mode = update.status.mode;
|
||||
const mode = normalizeMode(update.status.mode);
|
||||
const modeUpper2 = mode ? mode.toUpperCase() : "";
|
||||
const onVirtual = typeof vchanIsOnVirtual === "function" && vchanIsOnVirtual();
|
||||
const onVirtual = window.trx.modules.vchan?.isOnVirtual() === true;
|
||||
if (!onVirtual) {
|
||||
modeEl.value = modeUpper2;
|
||||
if (modeUpper2 === "WFM" && lastModeName !== "WFM") {
|
||||
@@ -3500,10 +3505,10 @@ ${unsupportedBandSummary()}`;
|
||||
sseSessionId = d.session_id || null;
|
||||
} catch (_) {
|
||||
}
|
||||
if (typeof vchanHandleSession === "function") vchanHandleSession(evt.data);
|
||||
window.trx.modules.vchan?.handleSession(evt.data);
|
||||
});
|
||||
es.addEventListener("channels", (evt) => {
|
||||
if (typeof vchanHandleChannels === "function") vchanHandleChannels(evt.data);
|
||||
window.trx.modules.vchan?.handleChannels(evt.data);
|
||||
});
|
||||
es.onerror = () => {
|
||||
if (es.readyState === EventSource.CLOSED) {
|
||||
@@ -3600,9 +3605,7 @@ ${unsupportedBandSummary()}`;
|
||||
async function takeSchedulerControlForDecoderDisable(buttonEl) {
|
||||
const enabled = buttonEl?.dataset?.enabled === "true" || /^\s*Disable\b/i.test(buttonEl?.textContent || "");
|
||||
if (!enabled) return;
|
||||
if (typeof window.vchanTakeSchedulerControl === "function") {
|
||||
await window.vchanTakeSchedulerControl();
|
||||
}
|
||||
await window.trx.modules.vchan?.takeSchedulerControl();
|
||||
}
|
||||
window.takeSchedulerControlForDecoderDisable = takeSchedulerControlForDecoderDisable;
|
||||
async function switchRigFromSelect(selectEl) {
|
||||
@@ -3635,8 +3638,8 @@ ${unsupportedBandSummary()}`;
|
||||
updateRigIdentitySummary(lastActiveRigId);
|
||||
window.trxUi?.setActiveRig(lastActiveRigId);
|
||||
window.trx.modules.scheduler?.setRig(lastActiveRigId);
|
||||
if (typeof setBackgroundDecodeRig === "function") setBackgroundDecodeRig(lastActiveRigId);
|
||||
if (typeof bmFetch === "function") bmFetch(document.getElementById("bm-category-filter")?.value || "");
|
||||
window.trx.modules.backgroundDecode?.setRig(lastActiveRigId);
|
||||
window.trx.modules.bookmarks?.fetch(document.getElementById("bm-category-filter")?.value || "");
|
||||
window.trx.modules.map?.syncAprsReceiverMarker();
|
||||
connect();
|
||||
stopSpectrumStreaming();
|
||||
@@ -3914,7 +3917,7 @@ ${unsupportedBandSummary()}`;
|
||||
setControlPending(modeEl, true);
|
||||
showHint("Setting mode…");
|
||||
try {
|
||||
if (typeof vchanInterceptMode === "function" && await vchanInterceptMode(mode)) {
|
||||
if (await window.trx.modules.vchan?.interceptMode(mode)) {
|
||||
showHint("Channel mode set", 1500);
|
||||
return;
|
||||
}
|
||||
@@ -4047,7 +4050,7 @@ ${unsupportedBandSummary()}`;
|
||||
scheduleSpectrumDraw();
|
||||
}
|
||||
try {
|
||||
if (typeof vchanInterceptBandwidth === "function" && await vchanInterceptBandwidth(clamped)) return;
|
||||
if (await window.trx.modules.vchan?.interceptBandwidth(clamped)) return;
|
||||
await postPath(`/set_bandwidth?hz=${clamped}`);
|
||||
if (Number.isFinite(lastFreqHz)) {
|
||||
await ensureTunedBandwidthCoverage(lastFreqHz);
|
||||
@@ -4131,7 +4134,7 @@ ${unsupportedBandSummary()}`;
|
||||
}
|
||||
async function applyAutoBandwidth() {
|
||||
if (!lastSpectrumData || lastFreqHz == null) return;
|
||||
const onVirtual = typeof vchanIsOnVirtual === "function" && vchanIsOnVirtual();
|
||||
const onVirtual = window.trx.modules.vchan?.isOnVirtual() === true;
|
||||
const interference = onVirtual ? {} : { cci: lastWfmCci, aci: lastWfmAci };
|
||||
const estimated = estimateOccupiedBandwidth(lastSpectrumData, lastFreqHz, interference);
|
||||
if (!Number.isFinite(estimated) || estimated <= 0) {
|
||||
@@ -4155,7 +4158,7 @@ ${unsupportedBandSummary()}`;
|
||||
}
|
||||
window.trxUi?.notify(`Auto BW: ${formatBwLabel(estimated)} — ${reason}`, { kind: "success", duration: 5e3 });
|
||||
try {
|
||||
if (typeof vchanInterceptBandwidth === "function" && await vchanInterceptBandwidth(estimated)) return;
|
||||
if (await window.trx.modules.vchan?.interceptBandwidth(estimated)) return;
|
||||
await postPath(`/set_bandwidth?hz=${estimated}`);
|
||||
if (Number.isFinite(lastFreqHz)) {
|
||||
await ensureTunedBandwidthCoverage(lastFreqHz);
|
||||
@@ -4373,9 +4376,9 @@ ${unsupportedBandSummary()}`;
|
||||
function initSettingsUI() {
|
||||
window.trx.modules.scheduler?.initialize(lastActiveRigId, authRole);
|
||||
window.trx.modules.scheduler?.wireEvents();
|
||||
if (typeof initBackgroundDecode === "function") {
|
||||
initBackgroundDecode(lastActiveRigId, authRole);
|
||||
wireBackgroundDecodeEvents();
|
||||
if (window.trx.modules.backgroundDecode) {
|
||||
window.trx.modules.backgroundDecode.initialize(lastActiveRigId, authRole);
|
||||
window.trx.modules.backgroundDecode.wireEvents();
|
||||
}
|
||||
}
|
||||
document.getElementById("auth-form").addEventListener("submit", async (e) => {
|
||||
@@ -4619,7 +4622,7 @@ ${unsupportedBandSummary()}`;
|
||||
if (!bm) return null;
|
||||
const parts = [];
|
||||
if (bm.name) parts.push(String(bm.name));
|
||||
if (typeof bmFmtFreq === "function") parts.push(bmFmtFreq(bm.freq_hz));
|
||||
if (window.trx.modules.bookmarks) parts.push(window.trx.modules.bookmarks.formatFrequency(bm.freq_hz));
|
||||
if (bm.mode) parts.push(String(bm.mode));
|
||||
if (bm.locator) parts.push(String(bm.locator));
|
||||
const distance = bookmarkDistanceText(bm);
|
||||
@@ -6517,8 +6520,9 @@ ${unsupportedBandSummary()}`;
|
||||
}
|
||||
vchanRdsById = next;
|
||||
vchanSignalDbById = nextSig;
|
||||
if (typeof vchanActiveId !== "undefined" && vchanActiveId && nextSig.has(vchanActiveId)) {
|
||||
sigLastDbm = nextSig.get(vchanActiveId);
|
||||
const virtualChannelId = window.trx.modules.vchan?.activeId;
|
||||
if (virtualChannelId && nextSig.has(virtualChannelId)) {
|
||||
sigLastDbm = nextSig.get(virtualChannelId);
|
||||
refreshSigStrengthDisplay();
|
||||
}
|
||||
updateRdsPsOverlay(primaryRds);
|
||||
@@ -7159,7 +7163,7 @@ ${unsupportedBandSummary()}`;
|
||||
}
|
||||
function createBookmarkChip(bm, colorMap, options = {}) {
|
||||
const span = document.createElement("span");
|
||||
const freqStr = typeof bmFmtFreq === "function" ? bmFmtFreq(bm.freq_hz) : bm.freq_hz + " Hz";
|
||||
const freqStr = window.trx.modules.bookmarks ? window.trx.modules.bookmarks.formatFrequency(bm.freq_hz) : bm.freq_hz + " Hz";
|
||||
const esc = (s) => String(s).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
||||
span.className = "spectrum-bookmark-chip";
|
||||
if (options.sideStack) {
|
||||
@@ -7745,7 +7749,7 @@ ${unsupportedBandSummary()}`;
|
||||
if (_bwDragEdge) {
|
||||
try {
|
||||
const bwHz = Math.round(currentBandwidthHz);
|
||||
if (!(typeof vchanInterceptBandwidth === "function" && await vchanInterceptBandwidth(bwHz))) {
|
||||
if (!await window.trx.modules.vchan?.interceptBandwidth(bwHz)) {
|
||||
await postPath(`/set_bandwidth?hz=${bwHz}`);
|
||||
if (Number.isFinite(lastFreqHz)) {
|
||||
await ensureTunedBandwidthCoverage(lastFreqHz, currentBandwidthHz);
|
||||
|
||||
Reference in New Issue
Block a user