From c1850f2577023aa1eb00469031a7c8b1358a7171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bugsounet=20-=20C=C3=A9dric?= Date: Sun, 18 Jun 2023 14:33:03 +0200 Subject: [PATCH] Remote force check update (#3127) updatenotification: allow force scanning with `SCAN_UPDATES` notification from other modules --- CHANGELOG.md | 1 + .../default/updatenotification/node_helper.js | 28 +++++++++++++------ .../updatenotification/updatenotification.js | 11 ++++++-- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29acc643..0eb6cdcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ _This release is scheduled to be released on 2023-07-01._ - Set Timezone `Europe/Berlin` in unit tests (needed for new formatTime tests) - Added no-param-reassign eslint rule and fix warnings - updatenotification: Added `sendUpdatesNotifications` feature. Broadcast update with `UPDATES` notification to other modules +- updatenotification: allow force scanning with `SCAN_UPDATES` notification from other modules ### Removed diff --git a/modules/default/updatenotification/node_helper.js b/modules/default/updatenotification/node_helper.js index 2f11cc7c..607e1458 100644 --- a/modules/default/updatenotification/node_helper.js +++ b/modules/default/updatenotification/node_helper.js @@ -25,15 +25,25 @@ module.exports = NodeHelper.create({ }, async socketNotificationReceived(notification, payload) { - if (notification === "CONFIG") { - this.config = payload; - } else if (notification === "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(); - } + switch (notification) { + case "CONFIG": + this.config = payload; + 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; } }, diff --git a/modules/default/updatenotification/updatenotification.js b/modules/default/updatenotification/updatenotification.js index 00d9e650..73327ec8 100644 --- a/modules/default/updatenotification/updatenotification.js +++ b/modules/default/updatenotification/updatenotification.js @@ -34,9 +34,14 @@ Module.register("updatenotification", { }, notificationReceived(notification) { - if (notification === "DOM_OBJECTS_CREATED") { - this.sendSocketNotification("CONFIG", this.config); - this.sendSocketNotification("MODULES", Object.keys(Module.definitions)); + switch (notification) { + case "DOM_OBJECTS_CREATED": + this.sendSocketNotification("CONFIG", this.config); + this.sendSocketNotification("MODULES", Object.keys(Module.definitions)); + break; + case "SCAN_UPDATES": + this.sendSocketNotification("SCAN_UPDATES"); + break; } },