mirror of
https://github.com/edward-shen/MMM-pages.git
synced 2025-07-27 04:03:37 -07:00
refactor: simplify rotation control logic in setRotation
method
This commit is contained in:
parent
5b7384c9c0
commit
d174bf1716
1 changed files with 12 additions and 12 deletions
24
MMM-pages.js
24
MMM-pages.js
|
@ -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;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue