Check updates for configured modules only

This commit is contained in:
Chris van Marle 2016-11-18 12:53:49 +01:00
parent 0f44fd2290
commit 482dd4db76
2 changed files with 27 additions and 15 deletions

View File

@ -2,6 +2,7 @@ var SimpleGit = require("simple-git");
var simpleGits = []; var simpleGits = [];
var fs = require("fs"); var fs = require("fs");
var path = require("path"); var path = require("path");
var defaultModules = require(__dirname + "/../defaultmodules.js");
var NodeHelper = require("node_helper"); var NodeHelper = require("node_helper");
module.exports = NodeHelper.create({ module.exports = NodeHelper.create({
@ -11,24 +12,36 @@ module.exports = NodeHelper.create({
updateTimer: null, updateTimer: null,
start: function () { start: function () {
var srcdir = __dirname + "/../../"; },
fs.readdir(srcdir, function(err, names) {
if (err) {
console.error("Error reading dir " + srcdir + ": " + err);
return;
}
names.filter(function(name) { configureModules: function(modules) {
return fs.statSync(path.join(srcdir, name)).isDirectory() && name != "node_modules"; for (moduleName in modules) {
}).forEach(function(name) { if (defaultModules.indexOf(moduleName) < 0) {
simpleGits.push({"module": name, "git": SimpleGit(path.join(srcdir, name))}); // Default modules are included in the main MagicMirror repo
}); var moduleFolder = path.normalize(__dirname + "/../../" + moduleName);
});
var stat;
try {
stat = fs.statSync(path.join(moduleFolder, '.git'));
} catch(err) {
// Error when directory .git doesn't exist
// This module is not managed with git, skip
continue;
}
simpleGits.push({"module": moduleName, "git": SimpleGit(moduleFolder)});
}
}
// Push MagicMirror itself last, biggest chance it'll show up last in UI and isn't overwritten
simpleGits.push({"module": "default", "git": SimpleGit(path.normalize(__dirname + "/../../../"))});
}, },
socketNotificationReceived: function (notification, payload) { socketNotificationReceived: function (notification, payload) {
if (notification === "CONFIG") { if (notification === "CONFIG") {
this.config = payload; this.config = payload;
} else if(notification === "MODULES") {
this.configureModules(payload);
this.preformFetch(); this.preformFetch();
} }
}, },

View File

@ -1,7 +1,5 @@
Module.register("updatenotification", { Module.register("updatenotification", {
defaults: { defaults: {
updateInterval: 10 * 60 * 1000, // every 10 minutes updateInterval: 10 * 60 * 1000, // every 10 minutes
}, },
@ -10,12 +8,13 @@ Module.register("updatenotification", {
start: function () { start: function () {
Log.log("Start updatenotification"); Log.log("Start updatenotification");
}, },
notificationReceived: function(notification, payload, sender) { notificationReceived: function(notification, payload, sender) {
if (notification === "DOM_OBJECTS_CREATED") { if (notification === "DOM_OBJECTS_CREATED") {
this.sendSocketNotification("CONFIG", this.config); this.sendSocketNotification("CONFIG", this.config);
this.sendSocketNotification("MODULES", Module.definitions);
this.hide(0,{lockString: self.identifier}); this.hide(0,{lockString: self.identifier});
} }
}, },