90 lines
2.0 KiB
JavaScript
Raw Normal View History

/* MagicMirror²
2020-04-21 14:58:17 +02:00
* 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
refreshInterval: 24 * 60 * 60 * 1000, // one day
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() {
Log.info(`Starting module: ${this.name}`);
this.addFilters();
setInterval(() => {
this.moduleList = {};
this.updateDom(2);
}, this.config.refreshInterval);
2016-10-15 13:08:46 +02:00
},
2021-10-02 14:18:58 +02:00
suspend() {
this.suspended = true;
},
2021-10-02 14:18:58 +02:00
resume() {
this.suspended = false;
this.updateDom(2);
},
notificationReceived(notification) {
2016-10-15 13:08:46 +02:00
if (notification === "DOM_OBJECTS_CREATED") {
this.sendSocketNotification("CONFIG", this.config);
this.sendSocketNotification("MODULES", Object.keys(Module.definitions));
2016-10-15 13:08:46 +02:00
}
},
socketNotificationReceived(notification, payload) {
2016-10-15 13:08:46 +02:00
if (notification === "STATUS") {
2019-06-29 15:59:03 -05:00
this.updateUI(payload);
2016-10-15 17:06:52 +02:00
}
},
getStyles() {
return [`${this.name}.css`];
},
getTemplate() {
return `${this.name}.njk`;
},
getTemplateData() {
return { moduleList: this.moduleList, suspended: this.suspended };
},
updateUI(payload) {
2019-06-29 15:59:03 -05:00
if (payload && payload.behind > 0) {
// if we haven't seen info for this module
if (this.moduleList[payload.module] === undefined) {
2019-06-29 15:59:03 -05:00
// save it
this.moduleList[payload.module] = payload;
this.updateDom(2);
2019-06-29 15:59:03 -05: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
if (this.moduleList[payload.module] !== undefined) {
2019-07-26 00:38:52 -04:00
// remove it
delete this.moduleList[payload.module];
this.updateDom(2);
2019-07-26 00:38:52 -04:00
}
}
2016-10-15 13:08:46 +02:00
},
addFilters() {
this.nunjucksEnvironment().addFilter("diffLink", (text, status) => {
if (status.module !== "default") {
return text;
2019-06-29 15:59:03 -05:00
}
const localRef = status.hash;
const remoteRef = status.tracking.replace(/.*\//, "");
return `<a href="https://github.com/MichMich/MagicMirror/compare/${localRef}...${remoteRef}" class="xsmall dimmed difflink" target="_blank">${text}</a>`;
});
2016-10-15 13:08:46 +02:00
}
});