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:
+10
-2
@@ -2239,6 +2239,8 @@ async function saveSettings() {
|
||||
statusEl.style.display = 'block';
|
||||
setTimeout(() => statusEl.style.display = 'none', 4000);
|
||||
}
|
||||
// Re-init screensaver watcher in case it was just enabled
|
||||
initInactivityWatcher();
|
||||
}
|
||||
|
||||
function switchSettingsTab(btn, tabId) {
|
||||
@@ -11890,12 +11892,14 @@ function initScreensaverShortcuts() {
|
||||
_initScreensaverShortcutBtn('screensaver-recipe-btn', 'recipe', null);
|
||||
}
|
||||
|
||||
let _inactivityListenersAttached = false;
|
||||
|
||||
function initInactivityWatcher() {
|
||||
const s = getSettings();
|
||||
if (!s.screensaver_enabled) return; // disabled by default
|
||||
if (!_inactivityListenersAttached) {
|
||||
const events = ['pointerdown', 'pointermove', 'keydown', 'scroll', 'touchstart'];
|
||||
events.forEach(evt => {
|
||||
document.addEventListener(evt, () => {
|
||||
if (!getSettings().screensaver_enabled) return;
|
||||
if (_screensaverActive) {
|
||||
dismissScreensaver();
|
||||
} else {
|
||||
@@ -11903,8 +11907,12 @@ function initInactivityWatcher() {
|
||||
}
|
||||
}, { passive: true });
|
||||
});
|
||||
_inactivityListenersAttached = true;
|
||||
}
|
||||
if (getSettings().screensaver_enabled) {
|
||||
resetInactivityTimer();
|
||||
}
|
||||
}
|
||||
|
||||
// ===== INITIALIZATION =====
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
Reference in New Issue
Block a user