From a66a4f62bda6a967b016ce94f84c0693dae47f22 Mon Sep 17 00:00:00 2001 From: Michael Teeuw Date: Sat, 15 Oct 2016 13:08:46 +0200 Subject: [PATCH] Add module 'updatenotification'. --- CHANGELOG.md | 1 + config/config.js.sample | 4 ++ js/defaults.js | 4 ++ modules/default/defaultmodules.js | 3 +- modules/default/updatenotification/README.md | 42 ++++++++++++++ .../default/updatenotification/node_helper.js | 45 ++++++++++++++ .../updatenotification/updatenotification.js | 58 +++++++++++++++++++ package.json | 1 + translations/en.json | 6 +- translations/nl.json | 6 +- 10 files changed, 167 insertions(+), 3 deletions(-) create mode 100644 modules/default/updatenotification/README.md create mode 100644 modules/default/updatenotification/node_helper.js create mode 100644 modules/default/updatenotification/updatenotification.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 39902b38..2d68cd34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Calendar module now broadcasts the event list to all other modules using the notification system. [See documentation](https://github.com/MichMich/MagicMirror/tree/develop/modules/default/calendar) for more information. - Possibility to use the the calendar feed as the source for the weather (currentweather & weatherforecast) location data. [See documentation](https://github.com/MichMich/MagicMirror/tree/develop/modules/default/weatherforecast) for more information. - Added option to show rain amount in the weatherforecast default module +- Add module `updatenotification` to get an update whenever a new version is availabe. [See documentation](https://github.com/MichMich/MagicMirror/tree/develop/modules/default/updatenotification) for more information. ### Updated - Modified translations for Frysk. diff --git a/config/config.js.sample b/config/config.js.sample index e611f872..c2607dbf 100644 --- a/config/config.js.sample +++ b/config/config.js.sample @@ -16,6 +16,10 @@ var config = { { module: 'alert', }, + { + module: "updatenotification", + position: "top_center" + }, { module: 'clock', position: 'top_left' diff --git a/js/defaults.js b/js/defaults.js index 0ec033c3..0f27e817 100644 --- a/js/defaults.js +++ b/js/defaults.js @@ -17,6 +17,10 @@ var defaults = { units: "metric", modules: [ + { + module: "updatenotification", + position: "top_center" + }, { module: "helloworld", position: "upper_third", diff --git a/modules/default/defaultmodules.js b/modules/default/defaultmodules.js index 42e89ee0..fccf3c52 100644 --- a/modules/default/defaultmodules.js +++ b/modules/default/defaultmodules.js @@ -15,7 +15,8 @@ var defaultModules = [ "currentweather", "helloworld", "newsfeed", - "weatherforecast" + "weatherforecast", + "updatenotification" ]; /*************** DO NOT EDIT THE LINE BELOW ***************/ diff --git a/modules/default/updatenotification/README.md b/modules/default/updatenotification/README.md new file mode 100644 index 00000000..7d839087 --- /dev/null +++ b/modules/default/updatenotification/README.md @@ -0,0 +1,42 @@ +# Module: Update Notification +The `updatenotification` module is one of the default modules of the MagicMirror. +This will display a message whenever a new version of the MagicMirror application is available. + +## Using the module + +To use this module, add it to the modules array in the `config/config.js` file: +````javascript +modules: [ + { + module: 'updatenotification', + position: 'top_center', // This can be any of the regions. + config: { + // The config property is optional. + // See 'Configuration options' for more information. + } + } +] +```` + +## Configuration options + +The following properties can be configured: + + + + + + + + + + + + + + + +
OptionDescription
updateIntervalHow often do you want to check for a new version? This value represents the interval in milliseconds.
+
Possible values: Any value above 60000 (1 minute); +
Default value: 600000 (10 minutes); +
\ No newline at end of file diff --git a/modules/default/updatenotification/node_helper.js b/modules/default/updatenotification/node_helper.js new file mode 100644 index 00000000..d049e34b --- /dev/null +++ b/modules/default/updatenotification/node_helper.js @@ -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); + } + +}); \ No newline at end of file diff --git a/modules/default/updatenotification/updatenotification.js b/modules/default/updatenotification/updatenotification.js new file mode 100644 index 00000000..6b79e862 --- /dev/null +++ b/modules/default/updatenotification/updatenotification.js @@ -0,0 +1,58 @@ +Module.register("updatenotification", { + + + + defaults: { + updateInterval: 10 * 60 * 1000, // every 10 minutes + }, + + status: false, + + start: function () { + Log.log("Start updatenotification"); + var self = this; + }, + + notificationReceived: function(notification, payload, sender) { + if (notification === "DOM_OBJECTS_CREATED") { + this.sendSocketNotification("CONFIG", this.config); + } + }, + + socketNotificationReceived: function (notification, payload) { + if (notification === "STATUS") { + this.status = payload; + this.updateDom(1000); + } + }, + + // Override dom generator. + getDom: function () { + var wrapper = document.createElement("div"); + + if (this.status && this.status.behind > 0) { + 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 text = document.createElement("span"); + text.innerHTML = this.translate("UPDATE_NOTIFICATION"); + message.appendChild(text); + + wrapper.appendChild(message); + + var subtext = document.createElement("div"); + subtext.innerHTML = this.translate("UPDATE_INFO") + .replace("COMMIT_COUNT", this.status.behind + " " + ((this.status.behind == 1)? 'commit' : 'commits')) + .replace("BRANCH_NAME", this.status.current); + subtext.className = "xsmall dimmed"; + wrapper.appendChild(subtext); + } + + return wrapper; + } +}); diff --git a/package.json b/package.json index 202c3e59..4d7944e6 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "moment": "latest", "request": "^2.74.0", "rrule": "latest", + "simple-git": "^1.54.0", "snyk": "^1.14.1", "socket.io": "^1.4.6", "valid-url": "latest", diff --git a/translations/en.json b/translations/en.json index a2d5933a..e169ba1b 100644 --- a/translations/en.json +++ b/translations/en.json @@ -24,5 +24,9 @@ "W": "W", "WNW": "WNW", "NW": "NW", - "NNW": "NNW" + "NNW": "NNW", + + /* UPDATE INFO */ + "UPDATE_NOTIFICATION": "MagicMirror² update available.", + "UPDATE_INFO": "The current installation is COMMIT_COUNT behind on the BRANCH_NAME branch." } diff --git a/translations/nl.json b/translations/nl.json index e4e882ea..582b62e6 100644 --- a/translations/nl.json +++ b/translations/nl.json @@ -25,5 +25,9 @@ "W": "W", "WNW": "WNW", "NW": "NW", - "NNW": "NNW" + "NNW": "NNW", + + /* UPDATE INFO */ + "UPDATE_NOTIFICATION": "MagicMirror² update beschikbaar.", + "UPDATE_INFO": "De huidige installatie loopt COMMIT_COUNT achter op de BRANCH_NAME branch." }