add support for different delays for different pages

This commit is contained in:
sam detweiler 2024-06-22 15:43:33 -05:00
parent a67625905c
commit 17f820b923
2 changed files with 40 additions and 16 deletions

View file

@ -8,6 +8,7 @@ Module.register('MMM-Pages', {
* the page indicator by default, in case people actually want to use the * the page indicator by default, in case people actually want to use the
* sister module. We also don't rotate out modules by default. * sister module. We also don't rotate out modules by default.
*/ */
defaults: { defaults: {
modules: [], modules: [],
excludes: [], // Keep for compatibility excludes: [], // Keep for compatibility
@ -20,8 +21,9 @@ Module.register('MMM-Pages', {
rotationDelay: 10000, rotationDelay: 10000,
homePage: 0, homePage: 0,
useLockString: true, useLockString: true,
pageTimeout: []
}, },
timer:null,
/** /**
* Apply any styles, if we have any. * Apply any styles, if we have any.
*/ */
@ -236,35 +238,54 @@ Module.register('MMM-Pages', {
resetTimerWithDelay: function (delay) { resetTimerWithDelay: function (delay) {
if (this.config.rotationTime > 0) { if (this.config.rotationTime > 0) {
// This timer is the auto rotate function. // This timer is the auto rotate function.
clearInterval(this.timer); if(this.timer){
(this.config.pageTimeout.length?clearTimeout:clearInterval)(this.timer);
this.timer=null
}
// This is delay timer after manually updating. // This is delay timer after manually updating.
clearInterval(this.delayTimer); clearTimeout(this.delayTimer);
let rotation_timeout=this.config.rotationTime
if(this.config.pageTimeout.length){
for(let pageInfo of this.config.pageTimeout){
if((pageInfo.pageNumber) -1 == this.curPage){
rotation_timeout= pageInfo.timeout
break;
}
}
}
const self = this; const self = this;
this.delayTimer = setTimeout(() => { this.delayTimer = setTimeout(() => {
self.timer = setInterval(() => { self.timer = (this.config.pageTimeout.length?setTimeout:setInterval)(() => {
// Inform other modules and page change. // Inform other modules and page change.
// MagicMirror automatically excludes the sender from receiving the // MagicMirror automatically excludes the sender from receiving the
// message, so we need to trigger it for ourselves. // message, so we need to trigger it for ourselves.
self.sendNotification('PAGE_INCREMENT'); self.sendNotification('PAGE_INCREMENT');
self.notificationReceived('PAGE_INCREMENT'); self.notificationReceived('PAGE_INCREMENT');
}, self.config.rotationTime); }, rotation_timeout);
}, delay); }, delay, this);
} else if (this.config.rotationHomePage > 0) { } else if (this.config.rotationHomePage > 0) {
// This timer is the auto rotate function. // This timer is the auto rotate function.
clearInterval(this.timer); (this.config.pageTimeout.length?clearTimeout:clearInterval)(this.timer);
// This is delay timer after manually updating. // This is delay timer after manually updating.
clearInterval(this.delayTimer); clearTimeout(this.delayTimer);
let rotation_timeout=this.config.rotationHomePage
if(this.config.pageTimeout.length){
for(let pageInfo of this.config.pageTimeout){
if((pageInfo.pagenumber) -1 == this.curPage){
rotation_timeout= pageInfo.timeout
break;
}
}
}
const self = this; const self = this;
this.delayTimer = setTimeout(() => { this.delayTimer = setTimeout(() => {
self.timer = setInterval(() => { self.timer = (this.config.pageTimeout.length?setTimeout:setInterval)(() => {
// Inform other modules and page change. // Inform other modules and page change.
// MagicMirror automatically excludes the sender from receiving the // MagicMirror automatically excludes the sender from receiving the
// message, so we need to trigger it for ourselves. // message, so we need to trigger it for ourselves.
self.sendNotification('PAGE_CHANGED', 0); self.sendNotification('PAGE_CHANGED', 0);
self.notificationReceived('PAGE_CHANGED', self.config.homePage); self.notificationReceived('PAGE_CHANGED', self.config.homePage);
}, self.config.rotationHomePage); }, rotation_timeout);
}, delay); }, delay);
} }
}, },
@ -284,8 +305,9 @@ Module.register('MMM-Pages', {
} else { } else {
Log.log(`[Pages]: ${stateBaseString}ing rotation`); Log.log(`[Pages]: ${stateBaseString}ing rotation`);
if (!isRotating) { if (!isRotating) {
clearInterval(this.timer);
clearInterval(this.delayTimer); this.timer_clear_function(this.timer);
clearTimeout(this.delayTimer);
} else { } else {
this.resetTimerWithDelay(this.rotationDelay); this.resetTimerWithDelay(this.rotationDelay);
} }

View file

@ -42,7 +42,7 @@ cd ~/MagicMirror/modules
Clone this repository: Clone this repository:
```bash ```bash
git clone https://github.com/edward-shen/MMM-pages.git git clone https://github.com/sdetweil/MMM-pages.git
``` ```
Configure the module in your config.js file. Configure the module in your config.js file.
@ -154,6 +154,8 @@ if u want a modules content on multiple pages the classes would list those page
| `rotationFirstPage` | *NA* | *NA* | **Deprecated**. Use `rotationHomePage` instead. | | `rotationFirstPage` | *NA* | *NA* | **Deprecated**. Use `rotationHomePage` instead. |
| `homePage` | `int` | `0` | Which page index is the home page. If none is set, this returns to the leftmost page instead. | | `homePage` | `int` | `0` | Which page index is the home page. If none is set, this returns to the leftmost page instead. |
| `useLockString` | `bool` | `true` | Whether or not to use a lock string to show or hide pages. If disabled, other modules may override when modules may be shown. _Advanced users only. Only override this if you know what you're doing._ | `useLockString` | `bool` | `true` | Whether or not to use a lock string to show or hide pages. If disabled, other modules may override when modules may be shown. _Advanced users only. Only override this if you know what you're doing._
| `pageTimeout ` | `[]` | `{pageNumber:x,timeout:nnnn}`| array of structures, enable different timeouts for different pages
|||| pageNumber starts at 1 for the first page, timeout is in milliseconds
For the `module` configuration option, the first element of the outer array For the `module` configuration option, the first element of the outer array
should consist of elements that should be on the first page. The second element should consist of elements that should be on the first page. The second element