fix: screensaver watcher not activated when enabled from settings UI

initInactivityWatcher() was called once at startup and returned early if
screensaver was disabled at that moment. Enabling it later from the
settings panel had no effect until page reload.

- Make initInactivityWatcher() idempotent: attach DOM listeners only once
  (flag _inactivityListenersAttached), check screensaver_enabled dynamically
  inside each handler so disabling/enabling is reflected immediately
- Call initInactivityWatcher() at end of saveSettings() so the inactivity
  timer starts immediately when user enables screensaver
This commit is contained in:
dadaloop82
2026-05-06 05:35:37 +00:00
parent ed89e74b94
commit 6f19d1bcd5
+21 -13
View File
@@ -2239,6 +2239,8 @@ async function saveSettings() {
statusEl.style.display = 'block'; statusEl.style.display = 'block';
setTimeout(() => statusEl.style.display = 'none', 4000); setTimeout(() => statusEl.style.display = 'none', 4000);
} }
// Re-init screensaver watcher in case it was just enabled
initInactivityWatcher();
} }
function switchSettingsTab(btn, tabId) { function switchSettingsTab(btn, tabId) {
@@ -11890,20 +11892,26 @@ function initScreensaverShortcuts() {
_initScreensaverShortcutBtn('screensaver-recipe-btn', 'recipe', null); _initScreensaverShortcutBtn('screensaver-recipe-btn', 'recipe', null);
} }
let _inactivityListenersAttached = false;
function initInactivityWatcher() { function initInactivityWatcher() {
const s = getSettings(); if (!_inactivityListenersAttached) {
if (!s.screensaver_enabled) return; // disabled by default const events = ['pointerdown', 'pointermove', 'keydown', 'scroll', 'touchstart'];
const events = ['pointerdown', 'pointermove', 'keydown', 'scroll', 'touchstart']; events.forEach(evt => {
events.forEach(evt => { document.addEventListener(evt, () => {
document.addEventListener(evt, () => { if (!getSettings().screensaver_enabled) return;
if (_screensaverActive) { if (_screensaverActive) {
dismissScreensaver(); dismissScreensaver();
} else { } else {
resetInactivityTimer(); resetInactivityTimer();
} }
}, { passive: true }); }, { passive: true });
}); });
resetInactivityTimer(); _inactivityListenersAttached = true;
}
if (getSettings().screensaver_enabled) {
resetInactivityTimer();
}
} }
// ===== INITIALIZATION ===== // ===== INITIALIZATION =====