diff --git a/modules/default/updatenotification/node_helper.js b/modules/default/updatenotification/node_helper.js index c6a38da1..6147c061 100644 --- a/modules/default/updatenotification/node_helper.js +++ b/modules/default/updatenotification/node_helper.js @@ -2,6 +2,7 @@ var SimpleGit = require("simple-git"); var simpleGits = []; var fs = require("fs"); var path = require("path"); +var defaultModules = require(__dirname + "/../defaultmodules.js"); var NodeHelper = require("node_helper"); module.exports = NodeHelper.create({ @@ -11,24 +12,36 @@ module.exports = NodeHelper.create({ updateTimer: null, 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) { - return fs.statSync(path.join(srcdir, name)).isDirectory() && name != "node_modules"; - }).forEach(function(name) { - simpleGits.push({"module": name, "git": SimpleGit(path.join(srcdir, name))}); - }); - }); + configureModules: function(modules) { + for (moduleName in modules) { + if (defaultModules.indexOf(moduleName) < 0) { + // 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) { if (notification === "CONFIG") { this.config = payload; + } else if(notification === "MODULES") { + this.configureModules(payload); this.preformFetch(); } }, diff --git a/modules/default/updatenotification/updatenotification.js b/modules/default/updatenotification/updatenotification.js index 2f0870ed..31b45c40 100644 --- a/modules/default/updatenotification/updatenotification.js +++ b/modules/default/updatenotification/updatenotification.js @@ -1,7 +1,5 @@ Module.register("updatenotification", { - - defaults: { updateInterval: 10 * 60 * 1000, // every 10 minutes }, @@ -10,12 +8,13 @@ Module.register("updatenotification", { start: function () { Log.log("Start updatenotification"); - + }, notificationReceived: function(notification, payload, sender) { if (notification === "DOM_OBJECTS_CREATED") { this.sendSocketNotification("CONFIG", this.config); + this.sendSocketNotification("MODULES", Module.definitions); this.hide(0,{lockString: self.identifier}); } },