fix rendering och refresh så det inte uppdatera sidan vid inställningar

This commit is contained in:
larssand
2026-08-27 14:47:24 +02:00
parent 808d5b2657
commit 32acc0e9c7
4 changed files with 59 additions and 7 deletions

View File

@@ -2540,6 +2540,7 @@ let lastOverlayBestLapByKey = {};
let activeModalEscapeHandler = null;
let settingsStorageNotice = "";
let settingsStorageNoticeIsError = false;
let settingsDraftActive = false;
const backend = {
available: false,
lastSyncAt: null,
@@ -2568,9 +2569,12 @@ init();
async function init() {
document.body.classList.toggle("overlay-mode", overlayMode);
["focusin", "input", "change"].forEach((eventName) => {
dom.view.addEventListener(eventName, markSettingsDraftActive);
});
if ("speechSynthesis" in window) {
window.speechSynthesis.addEventListener("voiceschanged", () => {
if (currentView === "settings") renderView();
if (currentView === "settings") renderViewFromBackground();
});
}
seedDefaultData();
@@ -2587,7 +2591,7 @@ async function init() {
Promise.allSettled([hydrateFromBackend(), loadAmmcConfigFromBackend()]).finally(() => {
applyTheme();
renderNav();
renderView();
renderViewFromBackground();
setupLanguageControl();
updateHeaderState();
updateConnectionBadge();
@@ -2605,6 +2609,14 @@ async function init() {
}
}
function markSettingsDraftActive(event) {
if (currentView !== "settings") return;
const target = event.target;
if (target instanceof HTMLInputElement || target instanceof HTMLSelectElement || target instanceof HTMLTextAreaElement) {
settingsDraftActive = true;
}
}
function seedDefaultData() {
if (!state.classes.length) {
state.classes.push(
@@ -3212,6 +3224,7 @@ function updateViewUrl(view, driverId = "", classId = "") {
}
function renderView() {
if (currentView === "settings") settingsDraftActive = false;
clearModalEscapeHandler();
const navMeta = NAV_ITEMS.find((x) => x.id === currentView);
dom.pageTitle.textContent = navMeta ? t(navMeta.titleKey) : "";
@@ -3322,6 +3335,11 @@ function renderView() {
updateHeaderState();
}
function renderViewFromBackground() {
if (currentView === "settings" && settingsDraftActive) return;
renderView();
}
function clearModalEscapeHandler() {
if (activeModalEscapeHandler) {
document.removeEventListener("keydown", activeModalEscapeHandler);

View File

@@ -162,7 +162,7 @@ function connectDecoderRole(role, deps) {
state.decoder[lastErrorKey] = "";
saveState();
updateConnectionBadge();
if (["timing", "settings", "overlay"].includes(getCurrentView())) {
if (["timing", "overlay"].includes(getCurrentView())) {
renderView();
}
};
@@ -207,7 +207,7 @@ function connectDecoderRole(role, deps) {
}, 2000));
}
if (["timing", "settings", "overlay"].includes(getCurrentView())) {
if (["timing", "overlay"].includes(getCurrentView())) {
renderView();
}
};
@@ -216,7 +216,7 @@ function connectDecoderRole(role, deps) {
state.decoder[lastErrorKey] = t("error.decoder_connection");
saveState();
updateConnectionBadge();
if (["timing", "settings", "overlay"].includes(getCurrentView())) {
if (["timing", "overlay"].includes(getCurrentView())) {
renderView();
}
};