diff --git a/js/loader.js b/js/loader.js index fce17d1f54..a1ebbcac9a 100644 --- a/js/loader.js +++ b/js/loader.js @@ -16,31 +16,28 @@ const Loader = (function () { /* Private Methods */ /** - * Loops thru all modules and requests load for every module. + * Loops through all modules and requests load for every module. */ - const loadModules = function () { + const loadModules = async function () { let moduleData = getModuleData(); - const loadNextModule = function () { + const loadNextModule = async function () { if (moduleData.length > 0) { const nextModule = moduleData[0]; - loadModule(nextModule, function () { - moduleData = moduleData.slice(1); - loadNextModule(); - }); + await loadModule(nextModule); + moduleData = moduleData.slice(1); + await loadNextModule(); } else { // All modules loaded. Load custom.css // This is done after all the modules so we can // overwrite all the defined styles. - - loadFile(config.customCss).then(() => { - // custom.css loaded. Start all modules. - startModules(); - }); + await loadFile(config.customCss); + // custom.css loaded. Start all modules. + startModules(); } }; - loadNextModule(); + await loadNextModule(); }; /** @@ -130,32 +127,28 @@ const Loader = (function () { }; /** - * Load modules via ajax request and create module objects.s + * Load modules via ajax request and create module objects. * * @param {object} module Information about the module we want to load. * @param {Function} callback Function called when done. */ - const loadModule = function (module, callback) { + const loadModule = async function (module) { const url = module.path + module.file; - const afterLoad = function () { + const afterLoad = async function () { const moduleObject = Module.create(module.name); if (moduleObject) { - bootstrapModule(module, moduleObject).then(() => { - callback(); - }); - } else { - callback(); + await bootstrapModule(module, moduleObject); } + return Promise.resolve(); }; if (loadedModuleFiles.indexOf(url) !== -1) { - afterLoad(); + await afterLoad(); } else { - loadFile(url).then(() => { - loadedModuleFiles.push(url); - afterLoad(); - }); + await loadFile(url); + loadedModuleFiles.push(url); + await afterLoad(); } }; @@ -232,8 +225,8 @@ const Loader = (function () { /** * Load all modules as defined in the config. */ - loadModules: function () { - loadModules(); + loadModules: async function () { + await loadModules(); }, /** diff --git a/js/main.js b/js/main.js index d310d3cab5..b5ee784e16 100644 --- a/js/main.js +++ b/js/main.js @@ -479,13 +479,14 @@ const MM = (function () { /** * Main init method. */ - init: function () { + init: async function () { Log.info("Initializing MagicMirror²."); loadConfig(); Log.setLogLevel(config.logLevel); - Translator.loadCoreTranslations(config.language).then(() => Loader.loadModules()); + await Translator.loadCoreTranslations(config.language); + await Loader.loadModules(); }, /**