refactor: simplify rotation control logic in setRotation method

This commit is contained in:
Kristjan ESPERANTO 2025-07-26 10:28:59 +02:00
parent 5b7384c9c0
commit d174bf1716
No known key found for this signature in database

View file

@ -267,26 +267,26 @@ Module.register('MMM-pages', {
}, },
/** /**
* Pause or resume the page rotation. If the provided isRotating value is * Toggles page rotation.
* 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.
* *
* @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) { setRotation(shouldRotate) {
const stateBaseString = isRotating ? 'resum' : 'paus'; const action = shouldRotate ? 'resume' : 'pause';
if (isRotating === !this.rotationPaused) { Log.debug(`[MMM-pages] setRotation called: ${action} rotation`);
Log.warn(`[MMM-pages] was asked to ${stateBaseString}e but rotation is already ${stateBaseString}ed!`); if (shouldRotate === !this.rotationPaused) {
Log.debug(`[MMM-pages] Rotation already ${shouldRotate ? 'running' : 'paused'}!`);
} else { } else {
Log.log(`[MMM-pages] ${stateBaseString}ing rotation`); if (shouldRotate) {
if (isRotating) {
this.resetTimerWithDelay(this.config.rotationDelay); this.resetTimerWithDelay(this.config.rotationDelay);
this.rotationPaused = false;
Log.debug('[MMM-pages] Rotation resumed');
} else { } else {
clearInterval(this.timer); clearInterval(this.timer);
clearInterval(this.delayTimer); clearInterval(this.delayTimer);
this.rotationPaused = true;
Log.debug('[MMM-pages] Rotation paused');
} }
this.rotationPaused = isRotating;
} }
}, },