Fix mode switch re-entry regressions

This commit is contained in:
James Smith
2026-03-18 21:26:01 +00:00
parent c75cd820e9
commit 963fdaf013
4 changed files with 42 additions and 23 deletions
+11 -7
View File
@@ -16,8 +16,9 @@ const Meshtastic = (function() {
// Map state // Map state
let meshMap = null; let meshMap = null;
let meshMarkers = {}; // nodeId -> marker let meshMarkers = {}; // nodeId -> marker
let localNodeId = null; let localNodeId = null;
let clickDelegationAttached = false;
/** /**
* Initialize the Meshtastic mode * Initialize the Meshtastic mode
@@ -32,11 +33,14 @@ const Meshtastic = (function() {
/** /**
* Setup event delegation for dynamically created elements * Setup event delegation for dynamically created elements
*/ */
function setupEventDelegation() { function setupEventDelegation() {
// Handle button clicks in Leaflet popups and elsewhere if (clickDelegationAttached) return;
document.addEventListener('click', function(e) { clickDelegationAttached = true;
const tracerouteBtn = e.target.closest('.mesh-traceroute-btn');
if (tracerouteBtn) { // Handle button clicks in Leaflet popups and elsewhere
document.addEventListener('click', function(e) {
const tracerouteBtn = e.target.closest('.mesh-traceroute-btn');
if (tracerouteBtn) {
const nodeId = tracerouteBtn.dataset.nodeId; const nodeId = tracerouteBtn.dataset.nodeId;
if (nodeId) { if (nodeId) {
sendTraceroute(nodeId); sendTraceroute(nodeId);
+11 -8
View File
@@ -14,10 +14,11 @@ const SSTV = (function() {
let issMarker = null; let issMarker = null;
let issTrackLine = null; let issTrackLine = null;
let issPosition = null; let issPosition = null;
let issUpdateInterval = null; let issUpdateInterval = null;
let countdownInterval = null; let countdownInterval = null;
let nextPassData = null; let nextPassData = null;
let pendingMapInvalidate = false; let pendingMapInvalidate = false;
let locationListenersAttached = false;
// ISS frequency // ISS frequency
const ISS_FREQ = 145.800; const ISS_FREQ = 145.800;
@@ -92,10 +93,12 @@ const SSTV = (function() {
if (latInput && storedLat) latInput.value = storedLat; if (latInput && storedLat) latInput.value = storedLat;
if (lonInput && storedLon) lonInput.value = storedLon; if (lonInput && storedLon) lonInput.value = storedLon;
// Add change handlers to save and refresh if (!locationListenersAttached) {
if (latInput) latInput.addEventListener('change', saveLocationFromInputs); if (latInput) latInput.addEventListener('change', saveLocationFromInputs);
if (lonInput) lonInput.addEventListener('change', saveLocationFromInputs); if (lonInput) lonInput.addEventListener('change', saveLocationFromInputs);
} locationListenersAttached = true;
}
}
/** /**
* Save location from input fields * Save location from input fields
+13 -8
View File
@@ -27,11 +27,24 @@ const WeatherSat = (function() {
let consoleAutoHideTimer = null; let consoleAutoHideTimer = null;
let currentModalFilename = null; let currentModalFilename = null;
let locationListenersAttached = false; let locationListenersAttached = false;
let initialized = false;
/** /**
* Initialize the Weather Satellite mode * Initialize the Weather Satellite mode
*/ */
function init() { function init() {
if (initialized) {
checkStatus();
loadImages();
loadLocationInputs();
loadPasses();
startCountdownTimer();
checkSchedulerStatus();
initGroundMap();
return;
}
initialized = true;
checkStatus(); checkStatus();
loadImages(); loadImages();
loadLocationInputs(); loadLocationInputs();
@@ -39,14 +52,6 @@ const WeatherSat = (function() {
startCountdownTimer(); startCountdownTimer();
checkSchedulerStatus(); checkSchedulerStatus();
initGroundMap(); initGroundMap();
// Re-filter passes when satellite selection changes
const satSelect = document.getElementById('weatherSatSelect');
if (satSelect) {
satSelect.addEventListener('change', () => {
applyPassFilter();
});
}
} }
/** /**
+7
View File
@@ -4386,8 +4386,11 @@
} }
} }
let modeSwitchRequestId = 0;
// Mode switching // Mode switching
async function switchMode(mode, options = {}) { async function switchMode(mode, options = {}) {
const requestId = ++modeSwitchRequestId;
const { updateUrl = true } = options; const { updateUrl = true } = options;
const switchStartMs = performance.now(); const switchStartMs = performance.now();
const previousMode = currentMode; const previousMode = currentMode;
@@ -4457,6 +4460,7 @@
const stopPhaseMs = Math.round(performance.now() - stopPhaseStartMs); const stopPhaseMs = Math.round(performance.now() - stopPhaseStartMs);
await styleReadyPromise; await styleReadyPromise;
await scriptReadyPromise; await scriptReadyPromise;
if (requestId !== modeSwitchRequestId) return;
// Generic module cleanup — destroy previous mode's timers, SSE, etc. // Generic module cleanup — destroy previous mode's timers, SSE, etc.
if (previousMode && previousMode !== mode) { if (previousMode && previousMode !== mode) {
@@ -4465,6 +4469,7 @@
try { destroyFn(); } catch(e) { console.warn(`[switchMode] destroy ${previousMode} failed:`, e); } try { destroyFn(); } catch(e) { console.warn(`[switchMode] destroy ${previousMode} failed:`, e); }
} }
} }
if (requestId !== modeSwitchRequestId) return;
currentMode = mode; currentMode = mode;
document.body.setAttribute('data-mode', mode); document.body.setAttribute('data-mode', mode);
@@ -4480,6 +4485,7 @@
// Sync with local status // Sync with local status
syncLocalModeStates(); syncLocalModeStates();
} }
if (requestId !== modeSwitchRequestId) return;
// Close dropdowns and update active state // Close dropdowns and update active state
closeAllDropdowns(); closeAllDropdowns();
@@ -4799,6 +4805,7 @@
} else if (mode === 'ook') { } else if (mode === 'ook') {
OokMode.init(); OokMode.init();
} }
if (requestId !== modeSwitchRequestId) return;
// Waterfall destroy is now handled by moduleDestroyMap above. // Waterfall destroy is now handled by moduleDestroyMap above.