75 lines
1.9 KiB
JavaScript
Raw Normal View History

2021-09-09 19:51:07 +02:00
const GitHelper = require(__dirname + "/git_helper.js");
2020-05-31 22:12:26 +02:00
const defaultModules = require(__dirname + "/../defaultmodules.js");
const NodeHelper = require("node_helper");
2016-10-15 13:08:46 +02:00
module.exports = NodeHelper.create({
config: {},
updateTimer: null,
2019-06-29 15:59:03 -05:00
updateProcessStarted: false,
2016-10-15 13:08:46 +02:00
2021-09-09 19:51:07 +02:00
gitHelper: new GitHelper.gitHelper(),
2021-09-06 23:55:32 +02:00
start: function () {},
2019-06-29 15:59:03 -05:00
configureModules: async function (modules) {
2019-06-29 15:59:03 -05:00
// Push MagicMirror itself , biggest chance it'll show up last in UI and isn't overwritten
// others will be added in front
// this method returns promises so we can't wait for every one to resolve before continuing
2021-09-06 23:55:32 +02:00
this.gitHelper.add("default");
2019-06-29 15:59:03 -05:00
for (let moduleName in modules) {
if (!this.ignoreUpdateChecking(moduleName)) {
2021-09-06 23:55:32 +02:00
this.gitHelper.add(moduleName);
2016-11-16 18:19:44 +01:00
}
}
2016-10-15 13:08:46 +02:00
},
socketNotificationReceived: function (notification, payload) {
if (notification === "CONFIG") {
this.config = payload;
} else if (notification === "MODULES") {
2019-06-29 15:59:03 -05:00
// if this is the 1st time thru the update check process
if (!this.updateProcessStarted) {
this.updateProcessStarted = true;
this.configureModules(payload).then(() => this.performFetch());
2019-06-29 15:59:03 -05:00
}
2016-10-15 13:08:46 +02:00
}
},
performFetch: async function () {
2021-09-06 23:55:32 +02:00
for (let gitInfo of await this.gitHelper.getRepos()) {
this.sendSocketNotification("STATUS", gitInfo);
}
2016-10-15 13:08:46 +02:00
this.scheduleNextFetch(this.config.updateInterval);
},
scheduleNextFetch: function (delay) {
2016-10-15 13:08:46 +02:00
if (delay < 60 * 1000) {
delay = 60 * 1000;
2016-10-15 13:08:46 +02:00
}
let self = this;
2016-10-15 13:08:46 +02:00
clearTimeout(this.updateTimer);
this.updateTimer = setTimeout(function () {
self.performFetch();
2016-10-15 13:08:46 +02:00
}, delay);
},
ignoreUpdateChecking: function (moduleName) {
// Should not check for updates for default modules
if (defaultModules.indexOf(moduleName) >= 0) {
return true;
}
// Should not check for updates for ignored modules
if (this.config.ignoreModules.indexOf(moduleName) >= 0) {
return true;
}
// The rest of the modules that passes should check for updates
return false;
2016-10-15 13:08:46 +02:00
}
2016-10-17 17:03:10 +02:00
});