Skip to content

Commit

Permalink
Revert "Convert module-start to async (MagicMirrorOrg#3049)"
Browse files Browse the repository at this point in the history
This reverts commit 498b440.
  • Loading branch information
veeck committed Mar 7, 2023
1 parent 915fb9b commit 9aa4d5a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 31 deletions.
33 changes: 9 additions & 24 deletions js/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,20 @@ const Loader = (function () {
* Loops thru all modules and requests start for every module.
*/
const startModules = function () {
const modulePromises = [];
for (const module of moduleObjects) {
try {
modulePromises.push(module.start());
} catch (error) {
Log.error(`Error when starting node_helper for module ${module.name}:`);
Log.error(error);
}
module.start();
}

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);
// 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: async function () {
start: 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`;
},

async start() {
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;
await this.showNotification({ title: this.translate("sysTitle"), message });
this.showNotification({ title: this.translate("sysTitle"), message });
}
},

Expand Down
9 changes: 5 additions & 4 deletions modules/default/compliments/compliments.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@ Module.register("compliments", {
},

// Define start sequence.
start: async function () {
start: function () {
Log.info("Starting module: " + this.name);

this.lastComplimentIndex = -1;

if (this.config.remoteFile !== null) {
const response = await this.loadComplimentFile();
this.config.compliments = JSON.parse(response);
this.updateDom();
this.loadComplimentFile().then((response) => {
this.config.compliments = JSON.parse(response);
this.updateDom();
});
}

// Schedule update timer.
Expand Down

0 comments on commit 9aa4d5a

Please sign in to comment.