Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

### Fixed
Expand Down
33 changes: 24 additions & 9 deletions js/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,35 @@ 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);
}
}

// Notify core of loaded modules.
MM.modulesStarted(moduleObjects);
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);

// Starting modules also hides any modules that have requested to be initially hidden
for (const thisModule of moduleObjects) {
if (thisModule.data.hiddenOnStartup) {
Log.info("Initially hiding " + thisModule.name);
thisModule.hide();
// Starting modules also hides any modules that have requested to be initially hidden
for (const thisModule of moduleObjects) {
if (thisModule.data.hiddenOnStartup) {
Log.info("Initially hiding " + thisModule.name);
thisModule.hide();
}
}
}
});
};

/**
Expand Down
2 changes: 1 addition & 1 deletion js/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},

Expand Down
4 changes: 2 additions & 2 deletions modules/default/alert/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -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 });
}
},

Expand Down
9 changes: 4 additions & 5 deletions modules/default/compliments/compliments.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
this.config.compliments = JSON.parse(response);
this.updateDom();
});
const response = await this.loadComplimentFile();
this.config.compliments = JSON.parse(response);
this.updateDom();
}

// Schedule update timer.
Expand Down