diff --git a/public/index.html b/public/index.html index d2c6e95..48f04d5 100644 --- a/public/index.html +++ b/public/index.html @@ -527,7 +527,8 @@ this.stations = init.stations; this.stationRadio = init.stationRadio; - this.selectedStation = init.clientStation; + const stored = loadSelectedStation(); + this.selectedStation = (stored && this.stations[stored]) ? stored : init.clientStation; for (const [label, rotState] of Object.entries(init.rotators)) { const state = new RotatorState(); @@ -593,6 +594,7 @@ pill.addEventListener('click', () => { this.selectedStation = name; + saveSelectedStation(name); this.updateStationSelection(); this.applyAutoTab(); }); @@ -724,9 +726,14 @@ else this.handleMessage(msg); }); - setInterval(() => { - ws.send(JSON.stringify({ ping: 1 })); + const pingTimer = setInterval(() => { + if (ws.readyState === WebSocket.OPEN) ws.send(JSON.stringify({ ping: 1 })); }, 2000); + + ws.addEventListener("close", () => { + clearInterval(pingTimer); + reloadWhenServerIsBack(); + }); }); } } @@ -735,11 +742,38 @@ return location.origin.replace(/^http/, 'ws') + location.pathname.replace(/\/?$/, '/') + 'ws'; } + /** Polls until the server accepts a WebSocket again, then reloads to get a fresh state. */ + function reloadWhenServerIsBack() { + setTimeout(() => { + const probe = new WebSocket(wsUrl()); + probe.addEventListener("open", () => location.reload()); + probe.addEventListener("error", () => reloadWhenServerIsBack()); + }, 2000); + } + /** N1MM frequencies are in tens of Hz. */ function formatFreq(freq) { return (freq / 100000).toFixed(3) + ' MHz'; } + const STATION_STORAGE_KEY = 'rotrouter.selectedStation'; + + function loadSelectedStation() { + try { + return localStorage.getItem(STATION_STORAGE_KEY); + } catch { + return null; + } + } + + function saveSelectedStation(name) { + try { + localStorage.setItem(STATION_STORAGE_KEY, name); + } catch { + // storage unavailable (private mode etc.) — selection just won't persist + } + } + document.addEventListener("DOMContentLoaded", () => { new RotatorApp().initialize(); });