mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-21 12:55:22 +00:00
fixed updatenotification async/await issues and more es6
This commit is contained in:
@@ -1,70 +1,66 @@
|
|||||||
const GitHelper = require(__dirname + "/git_helper.js");
|
const GitHelper = require("./git_helper");
|
||||||
const defaultModules = require(__dirname + "/../defaultmodules.js");
|
const defaultModules = require("../defaultmodules");
|
||||||
const NodeHelper = require("node_helper");
|
const NodeHelper = require("node_helper");
|
||||||
|
|
||||||
|
const ONE_MINUTE = 60 * 1000;
|
||||||
|
|
||||||
module.exports = NodeHelper.create({
|
module.exports = NodeHelper.create({
|
||||||
config: {},
|
config: {},
|
||||||
|
|
||||||
updateTimer: null,
|
updateTimer: null,
|
||||||
updateProcessStarted: false,
|
updateProcessStarted: false,
|
||||||
|
|
||||||
gitHelper: new GitHelper.gitHelper(),
|
gitHelper: new GitHelper(),
|
||||||
|
|
||||||
start: function () {},
|
async configureModules(modules) {
|
||||||
|
for (const moduleName of modules) {
|
||||||
configureModules: async function (modules) {
|
|
||||||
// Push MagicMirror itself , biggest chance it'll show up last in UI and isn't overwritten
|
|
||||||
// others will be added in front
|
|
||||||
// this method returns promises so we can't wait for every one to resolve before continuing
|
|
||||||
this.gitHelper.add("default");
|
|
||||||
|
|
||||||
for (let moduleName in modules) {
|
|
||||||
if (!this.ignoreUpdateChecking(moduleName)) {
|
if (!this.ignoreUpdateChecking(moduleName)) {
|
||||||
this.gitHelper.add(moduleName);
|
await this.gitHelper.add(moduleName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await this.gitHelper.add("default");
|
||||||
},
|
},
|
||||||
|
|
||||||
socketNotificationReceived: function (notification, payload) {
|
async socketNotificationReceived(notification, payload) {
|
||||||
if (notification === "CONFIG") {
|
if (notification === "CONFIG") {
|
||||||
this.config = payload;
|
this.config = payload;
|
||||||
} else if (notification === "MODULES") {
|
} else if (notification === "MODULES") {
|
||||||
// if this is the 1st time thru the update check process
|
// if this is the 1st time thru the update check process
|
||||||
if (!this.updateProcessStarted) {
|
if (!this.updateProcessStarted) {
|
||||||
this.updateProcessStarted = true;
|
this.updateProcessStarted = true;
|
||||||
this.configureModules(payload).then(() => this.performFetch());
|
await this.configureModules(payload);
|
||||||
|
await this.performFetch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
performFetch: async function () {
|
async performFetch() {
|
||||||
for (let gitInfo of await this.gitHelper.getRepos()) {
|
const repos = await this.gitHelper.getRepos();
|
||||||
this.sendSocketNotification("STATUS", gitInfo);
|
|
||||||
|
for (const repo of repos) {
|
||||||
|
this.sendSocketNotification("STATUS", repo);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.scheduleNextFetch(this.config.updateInterval);
|
this.scheduleNextFetch(this.config.updateInterval);
|
||||||
},
|
},
|
||||||
|
|
||||||
scheduleNextFetch: function (delay) {
|
scheduleNextFetch(delay) {
|
||||||
if (delay < 60 * 1000) {
|
|
||||||
delay = 60 * 1000;
|
|
||||||
}
|
|
||||||
|
|
||||||
let self = this;
|
|
||||||
clearTimeout(this.updateTimer);
|
clearTimeout(this.updateTimer);
|
||||||
this.updateTimer = setTimeout(function () {
|
|
||||||
self.performFetch();
|
this.updateTimer = setTimeout(() => {
|
||||||
}, delay);
|
this.performFetch();
|
||||||
|
}, Math.max(delay, ONE_MINUTE));
|
||||||
},
|
},
|
||||||
|
|
||||||
ignoreUpdateChecking: function (moduleName) {
|
ignoreUpdateChecking(moduleName) {
|
||||||
// Should not check for updates for default modules
|
// Should not check for updates for default modules
|
||||||
if (defaultModules.indexOf(moduleName) >= 0) {
|
if (defaultModules.includes(moduleName)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should not check for updates for ignored modules
|
// Should not check for updates for ignored modules
|
||||||
if (this.config.ignoreModules.indexOf(moduleName) >= 0) {
|
if (this.config.ignoreModules.includes(moduleName)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user