Convert module-start to async (#3049)

Similar to the node_helper async start PR...

---------

Co-authored-by: veeck <michael@veeck.de>
This commit is contained in:
Veeck 2023-02-22 18:58:29 +01:00 committed by GitHub
parent fe0b915a5d
commit 498b440174
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 19 deletions

View File

@ -37,6 +37,7 @@ _This release is scheduled to be released on 2023-04-01._
- Update dates in Calendar widgets every minute
- Cleanup jest coverage for patches
- Update `stylelint` dependencies, switch to `stylelint-config-standard` and handle `stylelint` issues
- Convert module start to async/await
- Convert translator callbacks to async/await
- Convert app-start/-stop callbacks to async/awaits

View File

@ -47,9 +47,23 @@ const Loader = (function () {
* Loops thru all modules and requests start for every module.
*/
const startModules = function () {
const modulePromises = [];
for (const module of moduleObjects) {
module.start();
try {
modulePromises.push(module.start());
} catch (error) {
Log.error(`Error when starting node_helper for module ${module.name}:`);
Log.error(error);
}
}
Promise.allSettled(modulePromises).then((results) => {
// Log errors that happened during async node_helper startup
results.forEach((result) => {
if (result.status === "rejected") {
Log.error(result.reason);
}
});
// Notify core of loaded modules.
MM.modulesStarted(moduleObjects);
@ -61,6 +75,7 @@ const Loader = (function () {
thisModule.hide();
}
}
});
};
/**

View File

@ -40,7 +40,7 @@ const Module = Class.extend({
/**
* Called when the module is started.
*/
start: function () {
start: async function () {
Log.info("Starting module: " + this.name);
},

View File

@ -44,7 +44,7 @@ Module.register("alert", {
return `templates/${type}.njk`;
},
start() {
async start() {
Log.info(`Starting module: ${this.name}`);
if (this.config.effect === "slide") {
@ -53,7 +53,7 @@ Module.register("alert", {
if (this.config.welcome_message) {
const message = this.config.welcome_message === true ? this.translate("welcome") : this.config.welcome_message;
this.showNotification({ title: this.translate("sysTitle"), message });
await this.showNotification({ title: this.translate("sysTitle"), message });
}
},

View File

@ -33,16 +33,15 @@ Module.register("compliments", {
},
// Define start sequence.
start: function () {
start: async function () {
Log.info("Starting module: " + this.name);
this.lastComplimentIndex = -1;
if (this.config.remoteFile !== null) {
this.loadComplimentFile().then((response) => {
const response = await this.loadComplimentFile();
this.config.compliments = JSON.parse(response);
this.updateDom();
});
}
// Schedule update timer.