Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changend scheduling to support pause reload if module is hidden #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions MMM-iFrameReload.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,25 @@ Module.register("MMM-iFrameReload",{
refreshInterval: 3600,
animationSpeed: 1000
},
myUpdateInterval: null,

// Define start sequence.
start: function() {
Log.info("Starting module: " + this.name);
this.scheduleUpdate(this.config.refreshInterval);
this.scheduleUpdate();
},

suspend : function() {
Log.info("Suspending module: " + this.name);
this.cancelUpdate();
},

resume : function() {
Log.info("Resuming module: " + this.name);
this.updateFrame();
this.scheduleUpdate();
},

// Override dom generator.
getDom: function() {
var iframe = document.createElement("IFRAME");
Expand All @@ -32,16 +45,19 @@ Module.register("MMM-iFrameReload",{
iframe.src = this.config.url;
return iframe;
},
scheduleUpdate: function(delay) {
var nextLoad = this.config.refreshInterval;
if (typeof delay !== "undefined" && delay >= 0) {
nextLoad = delay * 1000; // Convert seconds to millis
}

scheduleUpdate: function() {
var interval = this.config.refreshInterval * 1000; // Convert seconds to millis
var self = this;
setTimeout(function() {
this.myUpdateInterval = setInterval(function() {
self.updateFrame();
}, nextLoad);
}, interval);
},

cancelUpdate: function() {
clearInterval(this.myUpdateInterval);
},

updateFrame: function() {
if (this.config.url === "") {
Log.error("Tried to refresh, iFrameReload URL not set!");
Expand All @@ -52,6 +68,5 @@ Module.register("MMM-iFrameReload",{
Log.info("attempting to update dom for iFrameReload");
Log.info('/"this/" module is: ' + this);
this.updateDom(this.config.animationSpeed);
this.scheduleUpdate(this.config.refreshInterval);
}
});