mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-21 12:55:22 +00:00
Add module 'updatenotification'.
This commit is contained in:
45
modules/default/updatenotification/node_helper.js
Normal file
45
modules/default/updatenotification/node_helper.js
Normal file
@@ -0,0 +1,45 @@
|
||||
var simpleGit = require("simple-git")(__dirname + "/../..");
|
||||
var NodeHelper = require("node_helper");
|
||||
|
||||
module.exports = NodeHelper.create({
|
||||
|
||||
config: {},
|
||||
|
||||
updateTimer: null,
|
||||
|
||||
start: function () {
|
||||
|
||||
},
|
||||
|
||||
socketNotificationReceived: function (notification, payload) {
|
||||
if (notification === "CONFIG") {
|
||||
this.config = payload;
|
||||
this.preformFetch();
|
||||
}
|
||||
},
|
||||
|
||||
preformFetch() {
|
||||
var self = this;
|
||||
simpleGit.fetch().status(function(err, data) {
|
||||
if (!err) {
|
||||
self.sendSocketNotification("STATUS", data);
|
||||
}
|
||||
});
|
||||
|
||||
this.scheduleNextFetch(this.config.updateInterval);
|
||||
},
|
||||
|
||||
scheduleNextFetch: function(delay) {
|
||||
if (delay < 60 * 1000) {
|
||||
delay = 60 * 1000
|
||||
}
|
||||
|
||||
console.log(delay);
|
||||
var self = this;
|
||||
clearTimeout(this.updateTimer);
|
||||
this.updateTimer = setTimeout(function() {
|
||||
self.preformFetch();
|
||||
}, delay);
|
||||
}
|
||||
|
||||
});
|
Reference in New Issue
Block a user