2020-05-31 22:12:26 +02:00
|
|
|
const NodeHelper = require("node_helper");
|
2023-03-22 23:53:10 +01:00
|
|
|
const defaultModules = require("../defaultmodules");
|
|
|
|
const GitHelper = require("./git_helper");
|
2023-11-10 12:43:34 +01:00
|
|
|
const UpdateHelper = require("./update_helper");
|
2016-10-15 13:08:46 +02:00
|
|
|
|
2021-09-18 03:53:40 +02:00
|
|
|
const ONE_MINUTE = 60 * 1000;
|
|
|
|
|
2016-10-15 13:08:46 +02:00
|
|
|
module.exports = NodeHelper.create({
|
|
|
|
config: {},
|
|
|
|
|
|
|
|
updateTimer: null,
|
2019-06-29 15:59:03 -05:00
|
|
|
updateProcessStarted: false,
|
2016-10-15 13:08:46 +02:00
|
|
|
|
2021-09-18 03:53:40 +02:00
|
|
|
gitHelper: new GitHelper(),
|
2023-11-10 12:43:34 +01:00
|
|
|
updateHelper: null,
|
2019-06-29 15:59:03 -05:00
|
|
|
|
2021-09-18 03:53:40 +02:00
|
|
|
async configureModules(modules) {
|
|
|
|
for (const moduleName of modules) {
|
2020-02-11 18:13:39 +01:00
|
|
|
if (!this.ignoreUpdateChecking(moduleName)) {
|
2021-09-18 03:53:40 +02:00
|
|
|
await this.gitHelper.add(moduleName);
|
2016-11-16 18:19:44 +01:00
|
|
|
}
|
2016-11-18 12:53:49 +01:00
|
|
|
}
|
2021-09-18 03:53:40 +02:00
|
|
|
|
2023-01-12 09:14:20 +01:00
|
|
|
if (!this.ignoreUpdateChecking("MagicMirror")) {
|
|
|
|
await this.gitHelper.add("MagicMirror");
|
|
|
|
}
|
2016-10-15 13:08:46 +02:00
|
|
|
},
|
|
|
|
|
2021-09-18 03:53:40 +02:00
|
|
|
async socketNotificationReceived(notification, payload) {
|
2023-06-18 14:33:03 +02:00
|
|
|
switch (notification) {
|
|
|
|
case "CONFIG":
|
|
|
|
this.config = payload;
|
2023-11-10 12:43:34 +01:00
|
|
|
this.updateHelper = new UpdateHelper(this.config);
|
|
|
|
await this.updateHelper.check_PM2_Process();
|
2023-06-18 14:33:03 +02:00
|
|
|
break;
|
|
|
|
case "MODULES":
|
|
|
|
// if this is the 1st time thru the update check process
|
|
|
|
if (!this.updateProcessStarted) {
|
|
|
|
this.updateProcessStarted = true;
|
|
|
|
await this.configureModules(payload);
|
|
|
|
await this.performFetch();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "SCAN_UPDATES":
|
|
|
|
// 1st time of check allows to force new scan
|
|
|
|
if (this.updateProcessStarted) {
|
|
|
|
clearTimeout(this.updateTimer);
|
|
|
|
await this.performFetch();
|
|
|
|
}
|
|
|
|
break;
|
2016-10-15 13:08:46 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2021-09-18 03:53:40 +02:00
|
|
|
async performFetch() {
|
|
|
|
const repos = await this.gitHelper.getRepos();
|
|
|
|
|
|
|
|
for (const repo of repos) {
|
2023-11-10 12:43:34 +01:00
|
|
|
this.sendSocketNotification("REPO_STATUS", repo);
|
2021-03-13 11:12:08 +01:00
|
|
|
}
|
2016-10-15 13:08:46 +02:00
|
|
|
|
2023-11-10 12:43:34 +01:00
|
|
|
const updates = await this.gitHelper.checkUpdates();
|
|
|
|
|
|
|
|
if (this.config.sendUpdatesNotifications && updates.length) {
|
|
|
|
this.sendSocketNotification("UPDATES", updates);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (updates.length) {
|
|
|
|
const updateResult = await this.updateHelper.parse(updates);
|
|
|
|
for (const update of updateResult) {
|
|
|
|
if (update.inProgress) {
|
|
|
|
this.sendSocketNotification("UPDATE_STATUS", update);
|
|
|
|
}
|
|
|
|
}
|
2023-06-08 22:41:48 +02:00
|
|
|
}
|
|
|
|
|
2016-10-15 13:08:46 +02:00
|
|
|
this.scheduleNextFetch(this.config.updateInterval);
|
|
|
|
},
|
|
|
|
|
2021-09-18 03:53:40 +02:00
|
|
|
scheduleNextFetch(delay) {
|
2016-10-15 13:08:46 +02:00
|
|
|
clearTimeout(this.updateTimer);
|
2021-09-18 03:53:40 +02:00
|
|
|
|
2023-08-16 14:21:02 +02:00
|
|
|
this.updateTimer = setTimeout(
|
|
|
|
() => {
|
|
|
|
this.performFetch();
|
|
|
|
},
|
|
|
|
Math.max(delay, ONE_MINUTE)
|
|
|
|
);
|
2020-02-11 18:13:39 +01:00
|
|
|
},
|
|
|
|
|
2021-09-18 03:53:40 +02:00
|
|
|
ignoreUpdateChecking(moduleName) {
|
2020-02-11 18:13:39 +01:00
|
|
|
// Should not check for updates for default modules
|
2021-09-18 03:53:40 +02:00
|
|
|
if (defaultModules.includes(moduleName)) {
|
2020-02-11 18:13:39 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Should not check for updates for ignored modules
|
2021-09-18 03:53:40 +02:00
|
|
|
if (this.config.ignoreModules.includes(moduleName)) {
|
2020-02-11 18:13:39 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The rest of the modules that passes should check for updates
|
|
|
|
return false;
|
2016-10-15 13:08:46 +02:00
|
|
|
}
|
2016-10-17 17:03:10 +02:00
|
|
|
});
|