2020-04-21 14:58:17 +02:00
|
|
|
/* Magic Mirror
|
|
|
|
* Module: UpdateNotification
|
|
|
|
*
|
2020-04-28 23:05:28 +02:00
|
|
|
* By Michael Teeuw https://michaelteeuw.nl
|
2020-04-21 14:58:17 +02:00
|
|
|
* MIT Licensed.
|
|
|
|
*/
|
2016-10-15 13:08:46 +02:00
|
|
|
Module.register("updatenotification", {
|
|
|
|
defaults: {
|
|
|
|
updateInterval: 10 * 60 * 1000, // every 10 minutes
|
2019-07-01 12:35:47 -05:00
|
|
|
refreshInterval: 24 * 60 * 60 * 1000, // one day
|
2020-02-11 18:13:39 +01:00
|
|
|
ignoreModules: []
|
2016-10-15 13:08:46 +02:00
|
|
|
},
|
|
|
|
|
2019-06-29 15:59:03 -05:00
|
|
|
suspended: false,
|
2019-07-26 00:38:52 -04:00
|
|
|
moduleList: {},
|
2016-10-15 13:08:46 +02:00
|
|
|
|
|
|
|
start: function () {
|
2019-07-26 00:38:52 -04:00
|
|
|
var self = this;
|
2016-10-15 13:08:46 +02:00
|
|
|
Log.log("Start updatenotification");
|
2020-05-11 22:22:32 +02:00
|
|
|
setInterval(() => {
|
|
|
|
self.moduleList = {};
|
|
|
|
self.updateDom(2);
|
|
|
|
}, self.config.refreshInterval);
|
2016-10-15 13:08:46 +02:00
|
|
|
},
|
|
|
|
|
2017-07-17 14:23:24 +02:00
|
|
|
notificationReceived: function (notification, payload, sender) {
|
2016-10-15 13:08:46 +02:00
|
|
|
if (notification === "DOM_OBJECTS_CREATED") {
|
|
|
|
this.sendSocketNotification("CONFIG", this.config);
|
2016-11-18 12:53:49 +01:00
|
|
|
this.sendSocketNotification("MODULES", Module.definitions);
|
2019-06-29 15:59:03 -05:00
|
|
|
//this.hide(0, { lockString: self.identifier });
|
2016-10-15 13:08:46 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
socketNotificationReceived: function (notification, payload) {
|
|
|
|
if (notification === "STATUS") {
|
2019-06-29 15:59:03 -05:00
|
|
|
this.updateUI(payload);
|
2016-10-15 17:06:52 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-06-29 15:59:03 -05:00
|
|
|
updateUI: function (payload) {
|
2016-10-15 17:06:52 +02:00
|
|
|
var self = this;
|
2019-06-29 15:59:03 -05:00
|
|
|
if (payload && payload.behind > 0) {
|
|
|
|
// if we haven't seen info for this module
|
2020-05-11 22:22:32 +02:00
|
|
|
if (this.moduleList[payload.module] === undefined) {
|
2019-06-29 15:59:03 -05:00
|
|
|
// save it
|
2020-05-11 22:22:32 +02:00
|
|
|
this.moduleList[payload.module] = payload;
|
2019-06-29 15:59:03 -05:00
|
|
|
self.updateDom(2);
|
|
|
|
}
|
|
|
|
//self.show(1000, { lockString: self.identifier });
|
2020-05-11 22:22:32 +02:00
|
|
|
} else if (payload && payload.behind === 0) {
|
2019-07-26 00:38:52 -04:00
|
|
|
// if the module WAS in the list, but shouldn't be
|
2020-05-11 22:22:32 +02:00
|
|
|
if (this.moduleList[payload.module] !== undefined) {
|
2019-07-26 00:38:52 -04:00
|
|
|
// remove it
|
|
|
|
delete this.moduleList[payload.module];
|
|
|
|
self.updateDom(2);
|
|
|
|
}
|
|
|
|
}
|
2016-10-15 13:08:46 +02:00
|
|
|
},
|
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
diffLink: function (module, text) {
|
2019-06-29 15:59:03 -05:00
|
|
|
var localRef = module.hash;
|
|
|
|
var remoteRef = module.tracking.replace(/.*\//, "");
|
2020-05-11 22:22:32 +02:00
|
|
|
return '<a href="https://github.com/MichMich/MagicMirror/compare/' + localRef + "..." + remoteRef + '" ' + 'class="xsmall dimmed" ' + 'style="text-decoration: none;" ' + 'target="_blank" >' + text + "</a>";
|
2017-10-16 09:35:25 +02:00
|
|
|
},
|
|
|
|
|
2016-10-15 13:08:46 +02:00
|
|
|
// Override dom generator.
|
|
|
|
getDom: function () {
|
2019-07-01 12:35:47 -05:00
|
|
|
var wrapper = document.createElement("div");
|
2020-05-11 22:22:32 +02:00
|
|
|
if (this.suspended === false) {
|
2019-06-29 15:59:03 -05:00
|
|
|
// process the hash of module info found
|
2020-05-11 22:22:32 +02:00
|
|
|
for (var key of Object.keys(this.moduleList)) {
|
2020-05-02 10:39:09 +02:00
|
|
|
let m = this.moduleList[key];
|
2016-10-15 13:08:46 +02:00
|
|
|
|
2019-06-29 15:59:03 -05:00
|
|
|
var message = document.createElement("div");
|
|
|
|
message.className = "small bright";
|
2016-10-15 13:08:46 +02:00
|
|
|
|
2019-06-29 15:59:03 -05:00
|
|
|
var icon = document.createElement("i");
|
|
|
|
icon.className = "fa fa-exclamation-circle";
|
|
|
|
icon.innerHTML = " ";
|
|
|
|
message.appendChild(icon);
|
|
|
|
|
2020-04-21 15:13:06 +02:00
|
|
|
var updateInfoKeyName = m.behind === 1 ? "UPDATE_INFO_SINGLE" : "UPDATE_INFO_MULTIPLE";
|
2016-10-15 13:08:46 +02:00
|
|
|
|
2019-06-29 15:59:03 -05:00
|
|
|
var subtextHtml = this.translate(updateInfoKeyName, {
|
|
|
|
COMMIT_COUNT: m.behind,
|
|
|
|
BRANCH_NAME: m.current
|
|
|
|
});
|
|
|
|
|
|
|
|
var text = document.createElement("span");
|
2020-04-21 15:13:06 +02:00
|
|
|
if (m.module === "default") {
|
2019-06-29 15:59:03 -05:00
|
|
|
text.innerHTML = this.translate("UPDATE_NOTIFICATION");
|
2020-05-11 22:22:32 +02:00
|
|
|
subtextHtml = this.diffLink(m, subtextHtml);
|
2019-06-29 15:59:03 -05:00
|
|
|
} 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);
|
|
|
|
}
|
|
|
|
}
|
2016-10-15 13:08:46 +02:00
|
|
|
return wrapper;
|
2019-06-29 15:59:03 -05:00
|
|
|
},
|
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
suspend: function () {
|
|
|
|
this.suspended = true;
|
2019-06-29 15:59:03 -05:00
|
|
|
},
|
2020-05-11 22:22:32 +02:00
|
|
|
resume: function () {
|
|
|
|
this.suspended = false;
|
2019-06-29 15:59:03 -05:00
|
|
|
this.updateDom(2);
|
2016-10-15 13:08:46 +02:00
|
|
|
}
|
|
|
|
});
|