mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 19:53:36 +00:00
[refactor] Simplify module loading process (#3766)
While debugging a 3rd party module, I looked at how modules are loaded and realized that the `loadModules` method can be implemented much simpler. This refactor makes the method easier to understand and maintain.
This commit is contained in:
parent
86934c8375
commit
e1a53ef2d5
@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
planned for 2025-07-01
|
planned for 2025-07-01
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- [refactor] Simplify module loading process
|
||||||
|
|
||||||
## [2.31.0] - 2025-04-01
|
## [2.31.0] - 2025-04-01
|
||||||
|
|
||||||
Thanks to: @Developer-Incoming, @eltociear, @geraki, @khassel, @KristjanESPERANTO, @MagMar94, @mixasgr, @n8many, @OWL4C, @rejas, @savvadam, @sdetweil.
|
Thanks to: @Developer-Incoming, @eltociear, @geraki, @khassel, @KristjanESPERANTO, @MagMar94, @mixasgr, @n8many, @OWL4C, @rejas, @savvadam, @sdetweil.
|
||||||
|
33
js/loader.js
33
js/loader.js
@ -217,29 +217,22 @@ const Loader = (function () {
|
|||||||
* Load all modules as defined in the config.
|
* Load all modules as defined in the config.
|
||||||
*/
|
*/
|
||||||
async loadModules () {
|
async loadModules () {
|
||||||
let moduleData = await getModuleData();
|
const moduleData = await getModuleData();
|
||||||
const envVars = await getEnvVars();
|
const envVars = await getEnvVars();
|
||||||
const customCss = envVars.customCss;
|
const customCss = envVars.customCss;
|
||||||
|
|
||||||
/**
|
// Load all modules
|
||||||
* @returns {Promise<void>} when all modules are loaded
|
for (const module of moduleData) {
|
||||||
*/
|
await loadModule(module);
|
||||||
const loadNextModule = async function () {
|
}
|
||||||
if (moduleData.length > 0) {
|
|
||||||
const nextModule = moduleData[0];
|
// Load custom.css
|
||||||
await loadModule(nextModule);
|
// Since this happens after loading the modules,
|
||||||
moduleData = moduleData.slice(1);
|
// it overwrites the default styles.
|
||||||
await loadNextModule();
|
await loadFile(customCss);
|
||||||
} else {
|
|
||||||
// All modules loaded. Load custom.css
|
// Start all modules.
|
||||||
// This is done after all the modules so we can
|
await startModules();
|
||||||
// overwrite all the defined styles.
|
|
||||||
await loadFile(customCss);
|
|
||||||
// custom.css loaded. Start all modules.
|
|
||||||
await startModules();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
await loadNextModule();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user