[fix](trx-frontend-http): roll back optimistic freq update when set_freq fails

setRigFrequency applied applyLocalTunedFrequency before the network
round-trip, leaving the spectrum view shifted to the new frequency even
when the POST was rejected (e.g. 403 when the user loses control access).
Save the previous frequency and restore it in the catch block so the UI
stays aligned with the actual server-side state.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Stanislaw Grams <stanislawgrams@gmail.com>
This commit is contained in:
2026-03-16 23:46:04 +01:00
parent 9fba303bd8
commit 844b0e60df
@@ -1822,12 +1822,20 @@ async function setRigFrequency(freqHz) {
throw new Error(`Unsupported frequency: ${targetHz}`); throw new Error(`Unsupported frequency: ${targetHz}`);
} }
// Optimistic local update before any network round-trip. // Optimistic local update before any network round-trip.
const prevFreqHz = lastFreqHz;
applyLocalTunedFrequency(targetHz); applyLocalTunedFrequency(targetHz);
// set_freq and set_center_freq are independent server operations — run in parallel. try {
await Promise.all([ // set_freq and set_center_freq are independent server operations — run in parallel.
postPath(`/set_freq?hz=${targetHz}`), await Promise.all([
ensureTunedBandwidthCoverage(targetHz), postPath(`/set_freq?hz=${targetHz}`),
]); ensureTunedBandwidthCoverage(targetHz),
]);
} catch (err) {
// Roll back the optimistic update so the spectrum view stays on the
// actual server-side frequency (e.g. when the user loses control access).
if (prevFreqHz != null) applyLocalTunedFrequency(prevFreqHz, true);
throw err;
}
} }
function spectrumBinIndexForHz(data, hz) { function spectrumBinIndexForHz(data, hz) {