[fix](trx-frontend-http): restore bookmark host contract
The TypeScript migration turned app.js from a classic script into an ES module, so its top-level declarations stopped being shared globals. bookmarks.ts was converted verbatim and kept reading them as window properties, which app.ts no longer publishes. Every bookmark interaction read undefined: the Add Bookmark and Select All buttons stayed hidden because the auth check saw no authEnabled or authRole, per-rig scopes were missing from the scope picker and the move target, decoder checkboxes were never built, and Tune threw on bridge.postPath before issuing a single request. Extend the typed window.trx host contract instead of restoring globals, as docs/frontend-architecture.md closes the standalone window property list. trx.state publishes authEnabled; trx.core publishes setRigFrequency, applyLocalTunedFrequency, armOptimisticFrequency, syncBandwidthInput, scheduleSpectrumDraw, and onDecoderRegistryReady. Replace the vchan setRigFrequency wrapper with an interceptFrequency service method, matching interceptMode and interceptBandwidth. The wrapper captured an undefined original and silently dropped every tune; routing interception through setRigFrequency also restores virtual channel redirection for the application's own tuning. Read registry-built elements through bmOptionalEl, since bmEl throws and the decoder checkboxes and decode toggle buttons are legitimately absent until the registry arrives. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GdyUjuXejCEfiub675z6cz Signed-off-by: Stan Grams <sjg@haxx.space>
This commit is contained in:
@@ -31,8 +31,6 @@ interface VirtualChannelBridge {
|
||||
jogUnit?: number;
|
||||
rxActive?: boolean;
|
||||
_audioChannelOverride?: string | null;
|
||||
_freqOptimisticSeq?: number;
|
||||
_freqOptimisticHz?: number;
|
||||
renderRdsOverlays?: () => void;
|
||||
updateDocumentTitle?: (rds: unknown) => void;
|
||||
activeChannelRds?: () => unknown;
|
||||
@@ -47,10 +45,16 @@ interface VirtualChannelBridge {
|
||||
positionRdsPsOverlay?: () => void;
|
||||
mwDefaultsForMode?: (mode: string) => [number, ...unknown[]];
|
||||
showHint?: (message: string, durationMs: number) => void;
|
||||
applyLocalTunedFrequency?: (frequencyHz: number) => void;
|
||||
setRigFrequency?: (frequencyHz: number) => void;
|
||||
refreshFreqDisplay?: () => void;
|
||||
trx?: { modules?: { vchan?: VirtualChannelService } };
|
||||
trx?: {
|
||||
core?: VirtualChannelCoreServices;
|
||||
modules?: { vchan?: VirtualChannelService };
|
||||
};
|
||||
}
|
||||
|
||||
interface VirtualChannelCoreServices {
|
||||
applyLocalTunedFrequency(frequencyHz: number, forceDisplay?: boolean): void;
|
||||
armOptimisticFrequency(frequencyHz: number): void;
|
||||
}
|
||||
|
||||
interface VirtualChannelService {
|
||||
@@ -63,6 +67,7 @@ interface VirtualChannelService {
|
||||
isOnVirtual(): boolean;
|
||||
interceptMode(mode: string): Promise<boolean>;
|
||||
interceptBandwidth(bandwidthHz: number): Promise<boolean>;
|
||||
interceptFrequency(frequencyHz: number): boolean;
|
||||
takeSchedulerControl(): Promise<void>;
|
||||
releaseToScheduler(): Promise<void>;
|
||||
}
|
||||
@@ -571,6 +576,19 @@ async function vchanInterceptBandwidth(bwHz: number): Promise<boolean> {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Called by setRigFrequency before it posts /set_freq. When a non-primary
|
||||
// channel is active the change belongs to the channel API instead of the rig,
|
||||
// so this applies the optimistic local update and reports the tune as handled.
|
||||
function vchanInterceptFrequency(freqHz: number): boolean {
|
||||
if (!vchanIsOnVirtual()) return false;
|
||||
const core = vchanWindow.trx?.core;
|
||||
const targetHz = Math.round(freqHz);
|
||||
core?.armOptimisticFrequency(targetHz);
|
||||
core?.applyLocalTunedFrequency(targetHz);
|
||||
vchanSetChannelFreq(freqHz);
|
||||
return true;
|
||||
}
|
||||
|
||||
vchanWindow.trx ??= {};
|
||||
vchanWindow.trx.modules ??= {};
|
||||
vchanWindow.trx.modules.vchan = {
|
||||
@@ -583,34 +601,11 @@ vchanWindow.trx.modules.vchan = {
|
||||
isOnVirtual: vchanIsOnVirtual,
|
||||
interceptMode: vchanInterceptMode,
|
||||
interceptBandwidth: vchanInterceptBandwidth,
|
||||
interceptFrequency: vchanInterceptFrequency,
|
||||
takeSchedulerControl: vchanTakeSchedulerControl,
|
||||
releaseToScheduler: vchanToggleSchedulerRelease,
|
||||
};
|
||||
|
||||
// Wrap setRigFrequency (defined in app.js, loaded before this file) so that
|
||||
// frequency changes are redirected to the active virtual channel instead of
|
||||
// the server when on a non-primary channel.
|
||||
(function() {
|
||||
const original = vchanWindow.setRigFrequency;
|
||||
vchanWindow.setRigFrequency = function(freqHz: number) {
|
||||
if (vchanIsOnVirtual()) {
|
||||
// Optimistic local update first, then fire-and-forget channel API.
|
||||
if (vchanWindow.applyLocalTunedFrequency) {
|
||||
if (typeof vchanWindow._freqOptimisticSeq === "number") {
|
||||
vchanWindow._freqOptimisticSeq += 1;
|
||||
vchanWindow._freqOptimisticHz = Math.round(freqHz);
|
||||
}
|
||||
vchanWindow.applyLocalTunedFrequency(Math.round(freqHz));
|
||||
}
|
||||
vchanSetChannelFreq(freqHz);
|
||||
return;
|
||||
}
|
||||
// Scheduler control is fire-and-forget — don't block the freq change.
|
||||
void vchanTakeSchedulerControl();
|
||||
original?.(freqHz);
|
||||
};
|
||||
})();
|
||||
|
||||
(function initSchedulerReleaseControl() {
|
||||
const btn = document.getElementById("scheduler-release-btn");
|
||||
if (btn) {
|
||||
|
||||
Reference in New Issue
Block a user