Update URL on mode switch

This commit is contained in:
Smittix
2026-02-04 09:26:29 +00:00
parent fa1c1e1eb6
commit 60f08d3672
+28 -5
View File
@@ -2019,7 +2019,7 @@
// After fade out, hide welcome and switch to mode // After fade out, hide welcome and switch to mode
setTimeout(() => { setTimeout(() => {
welcome.style.display = 'none'; welcome.style.display = 'none';
switchMode(mode); switchMode(mode, { updateUrl: true });
}, 400); }, 400);
} }
@@ -2050,7 +2050,8 @@
if (accepted) { if (accepted) {
const welcome = document.getElementById('welcomePage'); const welcome = document.getElementById('welcomePage');
if (welcome) welcome.style.display = 'none'; if (welcome) welcome.style.display = 'none';
switchMode(mode); switchMode(mode, { updateUrl: false });
updateModeUrl(mode, true);
} else { } else {
pendingStartMode = mode; pendingStartMode = mode;
} }
@@ -2072,8 +2073,8 @@
if (pendingStartMode) { if (pendingStartMode) {
// Bypass welcome and jump to requested mode // Bypass welcome and jump to requested mode
welcome.style.display = 'none'; welcome.style.display = 'none';
switchMode(pendingStartMode); switchMode(pendingStartMode, { updateUrl: true });
pendingStartMode = null; pendingStartMode = null;
} }
}, 300); }, 300);
} }
@@ -2451,8 +2452,20 @@
} }
}); });
function updateModeUrl(mode, replace = false) {
if (!validModes.has(mode)) return;
const url = new URL(window.location.href);
url.searchParams.set('mode', mode);
if (replace) {
window.history.replaceState({ mode }, '', url);
} else {
window.history.pushState({ mode }, '', url);
}
}
// Mode switching // Mode switching
function switchMode(mode) { function switchMode(mode, options = {}) {
const { updateUrl = true } = options;
// Only stop local scans if in local mode (not agent mode) // Only stop local scans if in local mode (not agent mode)
const isAgentMode = typeof currentAgent !== 'undefined' && currentAgent !== 'local'; const isAgentMode = typeof currentAgent !== 'undefined' && currentAgent !== 'local';
if (!isAgentMode) { if (!isAgentMode) {
@@ -2465,6 +2478,9 @@
} }
currentMode = mode; currentMode = mode;
if (updateUrl) {
updateModeUrl(mode);
}
// Sync mode state with current agent/local after switching // Sync mode state with current agent/local after switching
if (isAgentMode && typeof syncAgentModeStates === 'function') { if (isAgentMode && typeof syncAgentModeStates === 'function') {
@@ -2697,6 +2713,13 @@
if (typeof Meshtastic !== 'undefined') Meshtastic.invalidateMap(); if (typeof Meshtastic !== 'undefined') Meshtastic.invalidateMap();
}); });
window.addEventListener('popstate', function () {
const mode = getModeFromQuery();
if (mode && mode !== currentMode) {
switchMode(mode, { updateUrl: false });
}
});
// Also handle orientation changes explicitly for mobile // Also handle orientation changes explicitly for mobile
window.addEventListener('orientationchange', function () { window.addEventListener('orientationchange', function () {
setTimeout(() => { setTimeout(() => {