mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-21 12:55:22 +00:00
Add module 'updatenotification'.
This commit is contained in:
42
modules/default/updatenotification/README.md
Normal file
42
modules/default/updatenotification/README.md
Normal file
@@ -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:
|
||||
|
||||
<table width="100%">
|
||||
<!-- why, markdown... -->
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Option</th>
|
||||
<th width="100%">Description</th>
|
||||
</tr>
|
||||
<thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><code>updateInterval</code></td>
|
||||
<td>How often do you want to check for a new version? This value represents the interval in milliseconds.<br>
|
||||
<br><b>Possible values:</b> Any value above <code>60000</code> (1 minute);
|
||||
<br><b>Default value:</b> <code>600000</code> (10 minutes);
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
45
modules/default/updatenotification/node_helper.js
Normal file
45
modules/default/updatenotification/node_helper.js
Normal file
@@ -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);
|
||||
}
|
||||
|
||||
});
|
58
modules/default/updatenotification/updatenotification.js
Normal file
58
modules/default/updatenotification/updatenotification.js
Normal file
@@ -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;
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user