From 4084c57789eab8c536457c95009f8037f2a9d3b6 Mon Sep 17 00:00:00 2001 From: Sam Detweiler Date: Sat, 29 Jun 2019 15:59:03 -0500 Subject: [PATCH 1/6] fix updatenotification to not crash --- .../default/updatenotification/node_helper.js | 38 +++--- .../updatenotification/updatenotification.js | 111 +++++++++++------- 2 files changed, 92 insertions(+), 57 deletions(-) diff --git a/modules/default/updatenotification/node_helper.js b/modules/default/updatenotification/node_helper.js index f4014519..de23d730 100644 --- a/modules/default/updatenotification/node_helper.js +++ b/modules/default/updatenotification/node_helper.js @@ -10,11 +10,17 @@ module.exports = NodeHelper.create({ config: {}, updateTimer: null, + updateProcessStarted: false, start: function () { }, configureModules: function(modules) { + + // Push MagicMirror itself , biggest chance it'll show up last in UI and isn't overwritten + // others will be added in front, asynchronously + simpleGits.push({"module": "default", "git": SimpleGit(path.normalize(__dirname + "/../../../"))}); + for (moduleName in modules) { if (defaultModules.indexOf(moduleName) < 0) { // Default modules are included in the main MagicMirror repo @@ -22,6 +28,7 @@ module.exports = NodeHelper.create({ var stat; try { + //console.log("checking git for module="+moduleName) stat = fs.statSync(path.join(moduleFolder, ".git")); } catch(err) { // Error when directory .git doesn't exist @@ -36,40 +43,41 @@ module.exports = NodeHelper.create({ // No valid remote for folder, skip return; } - // Folder has .git and has at least one git remote, watch this folder - simpleGits.push({"module": mn, "git": git}); + simpleGits.unshift({"module": mn, "git": git}); }); }(moduleName, 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(); + // if this is the 1st time thru the update check process + if(this.updateProcessStarted==false ){ + this.updateProcessStarted=true; + this.configureModules(payload); + this.preformFetch(); + } } }, preformFetch() { - var self = this; - + var self=this; simpleGits.forEach(function(sg) { sg.git.fetch().status(function(err, data) { data.module = sg.module; if (!err) { - sg.git.log({"-1": null}, function(err, data2) { - if (!err && data2.latest && "hash" in data2.latest) { - data.hash = data2.latest.hash; - self.sendSocketNotification("STATUS", data); - } - }); + sg.git.log({"-1": null}, + function(err, data2) { + if (!err && data2.latest && "hash" in data2.latest) { + this.bound_data.hash = data2.latest.hash; + self.sendSocketNotification("STATUS", this.bound_data); + } + }.bind({bound_data:data}) + ); } }); }); diff --git a/modules/default/updatenotification/updatenotification.js b/modules/default/updatenotification/updatenotification.js index e3e55fc5..07925ead 100644 --- a/modules/default/updatenotification/updatenotification.js +++ b/modules/default/updatenotification/updatenotification.js @@ -2,41 +2,56 @@ Module.register("updatenotification", { defaults: { updateInterval: 10 * 60 * 1000, // every 10 minutes + refreshInterval: 24 * 60 * 60 * 1000, // one day }, - status: false, + suspended: false, + moduleList: {}, start: function () { + var self = this Log.log("Start updatenotification"); - + setInterval( () => { self.moduleList = {};self.updateDom(2) } , self.config.refreshInterval) }, 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 }); + //this.hide(0, { lockString: self.identifier }); } }, socketNotificationReceived: function (notification, payload) { if (notification === "STATUS") { - this.status = payload; - this.updateUI(); + this.updateUI(payload); } }, - updateUI: function () { + updateUI: function (payload) { var self = this; - if (this.status && this.status.behind > 0) { - self.updateDom(0); - self.show(1000, { lockString: self.identifier }); - } + if (payload && payload.behind > 0) { + // if we haven't seen info for this module + if(this.moduleList[payload.module] == undefined){ + // save it + this.moduleList[payload.module]=payload; + self.updateDom(2); + } + //self.show(1000, { lockString: self.identifier }); + + } else if (payload && payload.behind == 0){ + // if the module WAS in the list, but shouldn't be + if(this.moduleList[payload.module] != undefined){ + // remove it + delete this.moduleList[payload.module] + self.updateDom(2); + } + } }, - diffLink: function(text) { - var localRef = this.status.hash; - var remoteRef = this.status.tracking.replace(/.*\//, ""); + diffLink: function(module, text) { + var localRef = module.hash; + var remoteRef = module.tracking.replace(/.*\//, ""); return " 0) { - var message = document.createElement("div"); - message.className = "small bright"; + var message = document.createElement("div"); + message.className = "small bright"; - var icon = document.createElement("i"); - icon.className = "fa fa-exclamation-circle"; - icon.innerHTML = " "; - message.appendChild(icon); + var icon = document.createElement("i"); + icon.className = "fa fa-exclamation-circle"; + icon.innerHTML = " "; + message.appendChild(icon); - var updateInfoKeyName = this.status.behind == 1 ? "UPDATE_INFO_SINGLE" : "UPDATE_INFO_MULTIPLE"; - var subtextHtml = this.translate(updateInfoKeyName, { - COMMIT_COUNT: this.status.behind, - BRANCH_NAME: this.status.current - }); + var updateInfoKeyName = m.behind == 1 ? "UPDATE_INFO_SINGLE" : "UPDATE_INFO_MULTIPLE"; - var text = document.createElement("span"); - if (this.status.module == "default") { - text.innerHTML = this.translate("UPDATE_NOTIFICATION"); - subtextHtml = this.diffLink(subtextHtml); - } else { - text.innerHTML = this.translate("UPDATE_NOTIFICATION_MODULE", { - MODULE_NAME: this.status.module + var subtextHtml = this.translate(updateInfoKeyName, { + COMMIT_COUNT: m.behind, + BRANCH_NAME: m.current }); + + var text = document.createElement("span"); + if (m.module == "default") { + text.innerHTML = this.translate("UPDATE_NOTIFICATION"); + subtextHtml = this.diffLink(m,subtextHtml); + } else { + text.innerHTML = this.translate("UPDATE_NOTIFICATION_MODULE", { + MODULE_NAME: m.module + }); + } + message.appendChild(text); + + wrapper.appendChild(message); + + var subtext = document.createElement("div"); + subtext.innerHTML = subtextHtml; + subtext.className = "xsmall dimmed"; + wrapper.appendChild(subtext); } - message.appendChild(text); - - wrapper.appendChild(message); - - var subtext = document.createElement("div"); - subtext.innerHTML = subtextHtml; - subtext.className = "xsmall dimmed"; - wrapper.appendChild(subtext); } - return wrapper; + }, + + suspend: function() { + this.suspended=true; + }, + resume: function() { + this.suspended=false; + this.updateDom(2); } }); From 4a5c6f1d39f88a96a6467ef2e1675216bb639395 Mon Sep 17 00:00:00 2001 From: sam detweiler Date: Sun, 30 Jun 2019 07:18:45 -0500 Subject: [PATCH 2/6] Update CHANGELOG.md add info on updatenotification module improvements --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b89b1bc..32d039f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +### Updated updatenotification default module +- properly handle race conditions, stop crash +- display for a short time, not forever + --- ❤️ **Donate:** Enjoying MagicMirror²? [Please consider a donation!](https://magicmirror.builders/donate) With your help we can continue to improve the MagicMirror² core. From 7315f7d28308949ab83c6b7dd3053549e58fbc24 Mon Sep 17 00:00:00 2001 From: Sam Detweiler Date: Mon, 1 Jul 2019 12:35:47 -0500 Subject: [PATCH 3/6] fix conflict with master repo develop branch --- .../default/updatenotification/node_helper.js | 18 ++++++++---------- .../updatenotification/updatenotification.js | 12 +++++++----- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/modules/default/updatenotification/node_helper.js b/modules/default/updatenotification/node_helper.js index de23d730..1f9d2f4d 100644 --- a/modules/default/updatenotification/node_helper.js +++ b/modules/default/updatenotification/node_helper.js @@ -65,19 +65,17 @@ module.exports = NodeHelper.create({ }, preformFetch() { - var self=this; + var self = this; simpleGits.forEach(function(sg) { sg.git.fetch().status(function(err, data) { data.module = sg.module; if (!err) { - sg.git.log({"-1": null}, - function(err, data2) { - if (!err && data2.latest && "hash" in data2.latest) { - this.bound_data.hash = data2.latest.hash; - self.sendSocketNotification("STATUS", this.bound_data); - } - }.bind({bound_data:data}) - ); + sg.git.log({"-1": null}, function(err, data2) { + if (!err && data2.latest && "hash" in data2.latest) { + data.hash = data2.latest.hash; + self.sendSocketNotification("STATUS", data); + } + }); } }); }); @@ -87,7 +85,7 @@ module.exports = NodeHelper.create({ scheduleNextFetch: function(delay) { if (delay < 60 * 1000) { - delay = 60 * 1000 + delay = 60 * 1000; } var self = this; diff --git a/modules/default/updatenotification/updatenotification.js b/modules/default/updatenotification/updatenotification.js index 07925ead..54952054 100644 --- a/modules/default/updatenotification/updatenotification.js +++ b/modules/default/updatenotification/updatenotification.js @@ -2,16 +2,17 @@ Module.register("updatenotification", { defaults: { updateInterval: 10 * 60 * 1000, // every 10 minutes - refreshInterval: 24 * 60 * 60 * 1000, // one day + refreshInterval: 24 * 60 * 60 * 1000, // one day }, + status: false, suspended: false, - moduleList: {}, + moduleList: {}, start: function () { - var self = this + var self = this; Log.log("Start updatenotification"); - setInterval( () => { self.moduleList = {};self.updateDom(2) } , self.config.refreshInterval) + setInterval( () => { self.moduleList = {};self.updateDom(2) } , self.config.refreshInterval) }, notificationReceived: function (notification, payload, sender) { @@ -24,6 +25,7 @@ Module.register("updatenotification", { socketNotificationReceived: function (notification, payload) { if (notification === "STATUS") { + //this.status = payload; this.updateUI(payload); } }, @@ -62,7 +64,7 @@ Module.register("updatenotification", { // Override dom generator. getDom: function () { - wrapper = document.createElement("div"); + var wrapper = document.createElement("div"); if(this.suspended==false){ // process the hash of module info found for(key of Object.keys(this.moduleList)){ From 7ef8a5bb11980490dd45ce8ceea6dbac3a50bf16 Mon Sep 17 00:00:00 2001 From: Sam Detweiler Date: Mon, 1 Jul 2019 12:45:40 -0500 Subject: [PATCH 4/6] fix conflict with develop branch --- modules/default/updatenotification/updatenotification.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/default/updatenotification/updatenotification.js b/modules/default/updatenotification/updatenotification.js index 54952054..58c3995c 100644 --- a/modules/default/updatenotification/updatenotification.js +++ b/modules/default/updatenotification/updatenotification.js @@ -5,7 +5,6 @@ Module.register("updatenotification", { refreshInterval: 24 * 60 * 60 * 1000, // one day }, - status: false, suspended: false, moduleList: {}, @@ -25,7 +24,6 @@ Module.register("updatenotification", { socketNotificationReceived: function (notification, payload) { if (notification === "STATUS") { - //this.status = payload; this.updateUI(payload); } }, From 00148b4cc8c765dd84088a525833ed1d1d318ff1 Mon Sep 17 00:00:00 2001 From: Michael Teeuw Date: Mon, 1 Jul 2019 20:22:52 +0200 Subject: [PATCH 5/6] Prepare 2.9.0-develop --- CHANGELOG.md | 10 ++++++++++ package-lock.json | 2 +- package.json | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bfcf5820..c7f21230 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,16 @@ This project adheres to [Semantic Versioning](http://semver.org/). ❤️ **Donate:** Enjoying MagicMirror²? [Please consider a donation!](https://magicmirror.builders/donate) With your help we can continue to improve the MagicMirror² core. +## [2.9.0] - Unreleased (Develop Branch) + +*This release is scheduled to be released on 2019-10-01.* + +### Added + +### Updated + +### Fixed + ## [2.8.0] - 2019-07-01 ℹ️ **Note:** This update uses new dependencies. Please update using the following command: `git pull && npm install`. If you are having issues running Electron, make sure your [Raspbian is up to date](https://www.raspberrypi.org/documentation/raspbian/updating.md). diff --git a/package-lock.json b/package-lock.json index d812656a..17b8ce12 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "magicmirror", - "version": "2.8.0", + "version": "2.9.0-develop", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index e6efee6b..1f7e7402 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "magicmirror", - "version": "2.8.0", + "version": "2.9.0-develop", "description": "The open source modular smart mirror platform.", "main": "js/electron.js", "scripts": { From 13313d0b2556f8ca95eede7e841b7308acabab4f Mon Sep 17 00:00:00 2001 From: Michael Teeuw Date: Mon, 1 Jul 2019 20:27:37 +0200 Subject: [PATCH 6/6] Fix changelog. --- CHANGELOG.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7497c2ce..f9b24985 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,10 +3,6 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). -### Updated updatenotification default module -- properly handle race conditions, stop crash -- display for a short time, not forever - --- ❤️ **Donate:** Enjoying MagicMirror²? [Please consider a donation!](https://magicmirror.builders/donate) With your help we can continue to improve the MagicMirror² core. @@ -18,8 +14,10 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Added ### Updated +- Updatenotification module: Display update notification for a limited (configurable) time. ### Fixed +- Updatenotification module: Properly handle race conditions, prevent crash. ## [2.8.0] - 2019-07-01