From d174bf1716935841f5a1b02805dfca812a0187e1 Mon Sep 17 00:00:00 2001 From: Kristjan ESPERANTO <35647502+KristjanESPERANTO@users.noreply.github.com> Date: Sat, 26 Jul 2025 10:28:59 +0200 Subject: [PATCH] refactor: simplify rotation control logic in `setRotation` method --- MMM-pages.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/MMM-pages.js b/MMM-pages.js index de34a76..db2e0e0 100644 --- a/MMM-pages.js +++ b/MMM-pages.js @@ -267,26 +267,26 @@ Module.register('MMM-pages', { }, /** - * Pause or resume the page rotation. If the provided isRotating value is - * set to true, it will resume the rotation. If the requested - * state (f.e. isRotating === true) equals the current state, print a warning - * and do nothing. + * Toggles page rotation. * - * @param {boolean} isRotating the parameter, if you want to pause or resume. + * @param {boolean} shouldRotate - True to resume rotation, false to pause it. */ - setRotation(isRotating) { - const stateBaseString = isRotating ? 'resum' : 'paus'; - if (isRotating === !this.rotationPaused) { - Log.warn(`[MMM-pages] was asked to ${stateBaseString}e but rotation is already ${stateBaseString}ed!`); + setRotation(shouldRotate) { + const action = shouldRotate ? 'resume' : 'pause'; + Log.debug(`[MMM-pages] setRotation called: ${action} rotation`); + if (shouldRotate === !this.rotationPaused) { + Log.debug(`[MMM-pages] Rotation already ${shouldRotate ? 'running' : 'paused'}!`); } else { - Log.log(`[MMM-pages] ${stateBaseString}ing rotation`); - if (isRotating) { + if (shouldRotate) { this.resetTimerWithDelay(this.config.rotationDelay); + this.rotationPaused = false; + Log.debug('[MMM-pages] Rotation resumed'); } else { clearInterval(this.timer); clearInterval(this.delayTimer); + this.rotationPaused = true; + Log.debug('[MMM-pages] Rotation paused'); } - this.rotationPaused = isRotating; } },