MagicMirror/js/main.js

594 lines
18 KiB
JavaScript
Raw Normal View History

/* global Loader, defaults, Translator */
2014-02-19 16:45:36 +01:00
/* MagicMirror²
2016-03-24 17:19:32 +01:00
* Main System
*
2020-04-28 23:05:28 +02:00
* By Michael Teeuw https://michaelteeuw.nl
2016-03-24 17:19:32 +01:00
* MIT Licensed.
*/
2021-04-18 15:29:10 +02:00
const MM = (function () {
let modules = [];
2014-02-24 16:35:48 +01:00
2016-03-24 17:19:32 +01:00
/* Private Methods */
2014-02-19 16:45:36 +01:00
2020-08-01 17:06:46 +02:00
/**
* Create dom objects for all modules that are configured for a specific position.
2016-03-24 17:19:32 +01:00
*/
2021-04-18 15:29:10 +02:00
const createDomObjects = function () {
const domCreationPromises = [];
modules.forEach(function (module) {
if (typeof module.data.position !== "string") {
return;
}
2014-02-26 14:14:29 +01:00
2021-04-18 15:29:10 +02:00
const wrapper = selectWrapper(module.data.position);
2016-03-29 13:28:15 +02:00
2021-04-18 15:29:10 +02:00
const dom = document.createElement("div");
dom.id = module.identifier;
dom.className = module.name;
2016-03-31 17:05:35 +02:00
if (typeof module.data.classes === "string") {
Release 2.23.0 (#3078) ## [2.23.0] - 2023-04-04 Thanks to: @angeldeejay, @buxxi, @CarJem, @dariom, @DaveChild, @dWoolridge, @grenagit, @Hirschberger, @KristjanESPERANTO, @MagMar94, @naveensrinivasan, @nfogal, @psieg, @rajniszp, @retroflex, @SkySails and @tomzt. Special thanks to @khassel, @rejas and @sdetweil for taking over most (if not all) of the work on this release as project collaborators. This version would not be there without their effort. Thank you guys! You are awesome! ### Added - Added increments for hourly forecasts in weather module (#2996) - Added tests for hourly weather forecast - Added possibility to ignore MagicMirror repo in updatenotification module - Added Pirate Weather as new weather provider (#3005) - Added possibility to use your own templates in Alert module - Added error message if `<modulename>.js` file is missing in module folder to get a hint in the logs (#2403) - Added possibility to use environment variables in `config.js` (#1756) - Added option `pastDaysCount` to default calendar module to control of how many days past events should be displayed - Added thai language to alert module - Added option `sendNotifications` in clock module (#3056) ### Removed - Removed darksky weather provider - Removed unneeded (and unwanted) '.' after the year in calendar repeatingCountTitle (#2896) ### Updated - Use develop as target branch for dependabot - Update issue template, contributing doc and sample config - The weather modules clearly separates precipitation amount and probability (risk of rain/snow) - This requires all providers that only supports probability to change the config from `showPrecipitationAmount` to `showPrecipitationProbability`. - Update tests for weather and calendar module - Changed updatenotification module for MagicMirror repo only: Send only notifications for `master` if there is a tag on a newer commit - Update dates in Calendar widgets every minute - Cleanup jest coverage for patches - Update `stylelint` dependencies, switch to `stylelint-config-standard` and handle `stylelint` issues, update `main.css` matching new rules - Update Eslint config, add new rule and handle issue - Convert lots of callbacks to async/await - Revise require imports (#3071 and #3072) ### Fixed - Fix wrong day labels in envcanada forecast (#2987) - Fix for missing default class name prefix for customEvents in calendar - Fix electron flashing white screen on startup (#1919) - Fix weathergov provider hourly forecast (#3008) - Fix message display with HTML code into alert module (#2828) - Fix typo in french translation - Yr wind direction is no longer inverted - Fix async node_helper stopping electron start (#2487) - The wind direction arrow now points in the direction the wind is flowing, not into the wind (#3019) - Fix precipitation css styles and rounding value - Fix wrong vertical alignment of calendar title column when wrapEvents is true (#3053) - Fix empty news feed stopping the reload forever - Fix e2e tests (failed after async changes) by running calendar and newsfeed tests last - Lint: Use template literals instead of string concatenation - Fix default alert module to render HTML for title and message - Fix Open-Meteo wind speed units
2023-04-04 20:44:32 +02:00
dom.className = `module ${dom.className} ${module.data.classes}`;
}
2016-03-31 17:05:35 +02:00
dom.opacity = 0;
wrapper.appendChild(dom);
2014-02-24 16:35:48 +01:00
2021-04-18 15:29:10 +02:00
const moduleHeader = document.createElement("header");
moduleHeader.innerHTML = module.getHeader();
moduleHeader.className = "module-header";
dom.appendChild(moduleHeader);
if (typeof module.getHeader() === "undefined" || module.getHeader() !== "") {
2020-07-10 23:12:17 +02:00
moduleHeader.style.display = "none;";
} else {
moduleHeader.style.display = "block;";
2019-03-08 11:33:02 +01:00
}
2016-03-31 17:05:35 +02:00
2021-04-18 15:29:10 +02:00
const moduleContent = document.createElement("div");
moduleContent.className = "module-content";
dom.appendChild(moduleContent);
2016-03-31 17:05:35 +02:00
2021-04-18 15:29:10 +02:00
const domCreationPromise = updateDom(module, 0);
domCreationPromises.push(domCreationPromise);
domCreationPromise
.then(function () {
sendNotification("MODULE_DOM_CREATED", null, null, module);
})
.catch(Log.error);
});
2014-02-24 16:35:48 +01:00
2016-11-12 20:03:56 +01:00
updateWrapperStates();
Promise.all(domCreationPromises).then(function () {
sendNotification("DOM_OBJECTS_CREATED");
});
2016-03-24 17:19:32 +01:00
};
2014-04-21 16:51:21 +02:00
2020-08-01 17:06:46 +02:00
/**
2016-03-24 17:19:32 +01:00
* Select the wrapper dom object for a specific position.
2020-08-01 17:06:46 +02:00
* @param {string} position The name of the position.
Release 2.22.0 (#2983) ## [2.22.0] - 2023-01-01 Thanks to: @angeldeejay, @buxxi, @dariom, @dWoolridge, @KristjanESPERANTO, @MagMar94, @naveensrinivasan, @retroflex, @SkySails and @Tom. Special thanks to @khassel, @rejas and @sdetweil for taking over most (if not all) of the work on this release as project collaborators. This version would not be there without their effort. Thank you! ### Added - Added test for remoteFile option in compliments module - Added hourlyWeather functionality to Weather.gov weather provider - Removed weatherEndpoint definition from weathergov.js (not used) - Added css class names "today" and "tomorrow" for default calendar - Added Collaboration.md - Added new github action for dependency review (#2862) - Added a WeatherProvider for Open-Meteo - Added Yr as a weather provider - Added config options "ignoreXOriginHeader" and "ignoreContentSecurityPolicy" ### Removed - Removed usage of internal fetch function of node until it is more stable ### Updated - Cleaned up test directory (#2937) and jest config (#2959) - Wait for all modules to start before declaring the system ready (#2487) - Updated e2e tests (moved `done()` in helper functions) and use es6 syntax in all tests - Updated da translation - Rework weather module - Make sure smhi provider api only gets a maximum of 6 digits coordinates (#2955) - Use fetch instead of XMLHttpRequest in weatherprovider (#2935) - Reworked how weatherproviders handle units (#2849) - Use unix() method for parsing times, fix suntimes on the way (#2950) - Refactor conversion functions into utils class (#2958) - The `cors`-method in `server.js` now supports sending and recieving HTTP headers - Replace `&hellip;` by `…` - Cleanup compliments module - Updated dependencies including electron to v22 (#2903) ### Fixed - Correctly show apparent temperature in SMHI weather provider - Ensure updatenotification module isn't shown when local is _ahead_ of remote - Handle node_helper errors during startup (#2944) - Possibility to change FontAwesome class in calendar, so icons like `fab fa-facebook-square` works. - Fix cors problems with newsfeed articles (as far as possible), allow disabling cors per feed with option `useCorsProxy: false` (#2840) - Tests not waiting for the application to start and stop before starting the next test - Fix electron tests failing sometimes in github workflow - Fixed gap in clock module when displayed on the left side with displayType=digital - Fixed playwright issue by upgrading to v1.29.1 (#2969) Signed-off-by: naveen <172697+naveensrinivasan@users.noreply.github.com> Co-authored-by: Karsten Hassel <hassel@gmx.de> Co-authored-by: Malte Hallström <46646495+SkySails@users.noreply.github.com> Co-authored-by: Veeck <github@veeck.de> Co-authored-by: veeck <michael@veeck.de> Co-authored-by: dWoolridge <dwoolridge@charter.net> Co-authored-by: Johan <jojjepersson@yahoo.se> Co-authored-by: Dario Mratovich <dario_mratovich@hotmail.com> Co-authored-by: Dario Mratovich <dario.mratovich@outlook.com> Co-authored-by: Magnus <34011212+MagMar94@users.noreply.github.com> Co-authored-by: Naveen <172697+naveensrinivasan@users.noreply.github.com> Co-authored-by: buxxi <buxxi@omfilm.net> Co-authored-by: Thomas Hirschberger <47733292+Tom-Hirschberger@users.noreply.github.com> Co-authored-by: Kristjan ESPERANTO <35647502+KristjanESPERANTO@users.noreply.github.com> Co-authored-by: Andrés Vanegas Jiménez <142350+angeldeejay@users.noreply.github.com>
2023-01-01 18:09:08 +01:00
* @returns {HTMLElement | void} the wrapper element
2016-03-24 17:19:32 +01:00
*/
2021-04-18 15:29:10 +02:00
const selectWrapper = function (position) {
const classes = position.replace("_", " ");
const parentWrapper = document.getElementsByClassName(classes);
2016-03-24 17:19:32 +01:00
if (parentWrapper.length > 0) {
2021-04-18 15:29:10 +02:00
const wrapper = parentWrapper[0].getElementsByClassName("container");
2016-03-24 17:19:32 +01:00
if (wrapper.length > 0) {
return wrapper[0];
}
}
};
2014-02-19 17:02:17 +01:00
2020-08-01 17:06:46 +02:00
/**
2016-03-24 17:19:32 +01:00
* Send a notification to all modules.
2020-08-01 17:06:46 +02:00
* @param {string} notification The identifier of the notification.
* @param {*} payload The payload of the notification.
* @param {Module} sender The module that sent the notification.
* @param {Module} [sendTo] The (optional) module to send the notification to.
2016-03-24 17:19:32 +01:00
*/
2021-04-18 15:29:10 +02:00
const sendNotification = function (notification, payload, sender, sendTo) {
for (const m in modules) {
const module = modules[m];
if (module !== sender && (!sendTo || module === sendTo)) {
2016-03-24 17:19:32 +01:00
module.notificationReceived(notification, payload, sender);
}
}
};
2020-08-01 17:06:46 +02:00
/**
2016-03-24 17:19:32 +01:00
* Update the dom for a specific module.
2020-08-01 17:06:46 +02:00
* @param {Module} module The module that needs an update.
* @param {number} [speed] The (optional) number of microseconds for the animation.
* @returns {Promise} Resolved when the dom is fully updated.
2016-03-24 17:19:32 +01:00
*/
2021-04-18 15:29:10 +02:00
const updateDom = function (module, speed) {
return new Promise(function (resolve) {
2021-04-18 15:29:10 +02:00
const newHeader = module.getHeader();
let newContentPromise = module.getDom();
2018-01-01 10:55:39 -06:00
if (!(newContentPromise instanceof Promise)) {
// convert to a promise if not already one to avoid if/else's everywhere
newContentPromise = Promise.resolve(newContentPromise);
}
2018-01-01 10:55:39 -06:00
newContentPromise
.then(function (newContent) {
2021-04-18 15:29:10 +02:00
const updatePromise = updateDomWithContent(module, speed, newHeader, newContent);
2018-01-01 10:55:39 -06:00
updatePromise.then(resolve).catch(Log.error);
})
.catch(Log.error);
2018-01-01 09:42:34 -06:00
});
};
2020-08-01 17:06:46 +02:00
/**
2018-01-01 10:38:00 -06:00
* Update the dom with the specified content
2020-08-01 17:06:46 +02:00
* @param {Module} module The module that needs an update.
* @param {number} [speed] The (optional) number of microseconds for the animation.
* @param {string} newHeader The new header that is generated.
* @param {HTMLElement} newContent The new content that is generated.
* @returns {Promise} Resolved when the module dom has been updated.
2018-01-01 10:38:00 -06:00
*/
2021-04-18 15:29:10 +02:00
const updateDomWithContent = function (module, speed, newHeader, newContent) {
return new Promise(function (resolve) {
2018-01-01 09:42:34 -06:00
if (module.hidden || !speed) {
updateModuleContent(module, newHeader, newContent);
resolve();
return;
}
2016-03-31 19:15:58 +02:00
2016-09-20 17:22:24 +02:00
if (!moduleNeedsUpdate(module, newHeader, newContent)) {
2018-01-01 09:42:34 -06:00
resolve();
2016-03-31 19:15:58 +02:00
return;
}
if (!speed) {
2016-09-20 17:22:24 +02:00
updateModuleContent(module, newHeader, newContent);
2018-01-01 09:42:34 -06:00
resolve();
2016-03-31 19:15:58 +02:00
return;
}
hideModule(module, speed / 2, function () {
2016-09-20 17:22:24 +02:00
updateModuleContent(module, newHeader, newContent);
2016-03-31 19:15:58 +02:00
if (!module.hidden) {
showModule(module, speed / 2);
}
2018-01-01 09:42:34 -06:00
resolve();
2016-03-31 19:15:58 +02:00
});
2018-01-01 09:42:34 -06:00
});
2016-03-31 19:15:58 +02:00
};
2020-08-01 17:06:46 +02:00
/**
2016-03-31 19:15:58 +02:00
* Check if the content has changed.
2020-08-01 17:06:46 +02:00
* @param {Module} module The module to check.
* @param {string} newHeader The new header that is generated.
* @param {HTMLElement} newContent The new content that is generated.
* @returns {boolean} True if the module need an update, false otherwise
2016-03-31 19:15:58 +02:00
*/
2021-04-18 15:29:10 +02:00
const moduleNeedsUpdate = function (module, newHeader, newContent) {
const moduleWrapper = document.getElementById(module.identifier);
if (moduleWrapper === null) {
return false;
}
2021-04-18 15:29:10 +02:00
const contentWrapper = moduleWrapper.getElementsByClassName("module-content");
const headerWrapper = moduleWrapper.getElementsByClassName("module-header");
2016-03-29 13:28:15 +02:00
2021-04-18 15:29:10 +02:00
let headerNeedsUpdate = false;
let contentNeedsUpdate;
2016-03-29 13:28:15 +02:00
2016-09-20 17:22:24 +02:00
if (headerWrapper.length > 0) {
2016-10-25 12:30:24 +02:00
headerNeedsUpdate = newHeader !== headerWrapper[0].innerHTML;
2016-09-20 17:22:24 +02:00
}
2021-04-18 15:29:10 +02:00
const tempContentWrapper = document.createElement("div");
2016-09-20 17:22:24 +02:00
tempContentWrapper.appendChild(newContent);
contentNeedsUpdate = tempContentWrapper.innerHTML !== contentWrapper[0].innerHTML;
return headerNeedsUpdate || contentNeedsUpdate;
2016-03-31 19:15:58 +02:00
};
2016-03-24 17:19:32 +01:00
2020-08-01 17:06:46 +02:00
/**
2016-03-31 19:15:58 +02:00
* Update the content of a module on screen.
2020-08-01 17:06:46 +02:00
* @param {Module} module The module to check.
* @param {string} newHeader The new header that is generated.
* @param {HTMLElement} newContent The new content that is generated.
2016-03-31 19:15:58 +02:00
*/
2021-04-18 15:29:10 +02:00
const updateModuleContent = function (module, newHeader, newContent) {
const moduleWrapper = document.getElementById(module.identifier);
if (moduleWrapper === null) {
return;
}
2021-04-18 15:29:10 +02:00
const headerWrapper = moduleWrapper.getElementsByClassName("module-header");
const contentWrapper = moduleWrapper.getElementsByClassName("module-content");
2016-09-20 17:22:24 +02:00
contentWrapper[0].innerHTML = "";
contentWrapper[0].appendChild(newContent);
headerWrapper[0].innerHTML = newHeader;
2020-07-10 23:12:17 +02:00
if (headerWrapper.length > 0 && newHeader) {
headerWrapper[0].style.display = "block";
2020-07-10 23:12:17 +02:00
} else {
headerWrapper[0].style.display = "none";
}
2016-03-31 19:15:58 +02:00
};
2016-03-24 17:19:32 +01:00
2020-08-01 17:06:46 +02:00
/**
2016-03-31 19:15:58 +02:00
* Hide the module.
2020-08-01 17:06:46 +02:00
* @param {Module} module The module to hide.
* @param {number} speed The speed of the hide animation.
* @param {Function} callback Called when the animation is done.
* @param {object} [options] Optional settings for the hide method.
2016-03-31 19:15:58 +02:00
*/
Release 2.24.0 (#3141) Signed-off-by: naveen <172697+naveensrinivasan@users.noreply.github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Karsten Hassel <hassel@gmx.de> Co-authored-by: Malte Hallström <46646495+SkySails@users.noreply.github.com> Co-authored-by: Veeck <github@veeck.de> Co-authored-by: veeck <michael@veeck.de> Co-authored-by: dWoolridge <dwoolridge@charter.net> Co-authored-by: Johan <jojjepersson@yahoo.se> Co-authored-by: Dario Mratovich <dario_mratovich@hotmail.com> Co-authored-by: Dario Mratovich <dario.mratovich@outlook.com> Co-authored-by: Magnus <34011212+MagMar94@users.noreply.github.com> Co-authored-by: Naveen <172697+naveensrinivasan@users.noreply.github.com> Co-authored-by: buxxi <buxxi@omfilm.net> Co-authored-by: Thomas Hirschberger <47733292+Tom-Hirschberger@users.noreply.github.com> Co-authored-by: Kristjan ESPERANTO <35647502+KristjanESPERANTO@users.noreply.github.com> Co-authored-by: Andrés Vanegas Jiménez <142350+angeldeejay@users.noreply.github.com> Co-authored-by: Dave Child <dave@addedbytes.com> Co-authored-by: grenagit <46225780+grenagit@users.noreply.github.com> Co-authored-by: Grena <grena@grenabox.fr> Co-authored-by: Magnus Marthinsen <magmar@online.no> Co-authored-by: Patrick <psieg@users.noreply.github.com> Co-authored-by: Piotr Rajnisz <56397164+rajniszp@users.noreply.github.com> Co-authored-by: Suthep Yonphimai <tomzt@users.noreply.github.com> Co-authored-by: CarJem Generations (Carter Wallace) <cwallacecs@gmail.com> Co-authored-by: Nicholas Fogal <nfogal.misc@gmail.com> Co-authored-by: JakeBinney <126349119+JakeBinney@users.noreply.github.com> Co-authored-by: OWL4C <124401812+OWL4C@users.noreply.github.com> Co-authored-by: Oscar Björkman <17575446+oscarb@users.noreply.github.com> Co-authored-by: Ismar Slomic <ismar@slomic.no> Co-authored-by: Jørgen Veum-Wahlberg <jorgen.wahlberg@amedia.no> Co-authored-by: Eddie Hung <6740044+eddiehung@users.noreply.github.com> Co-authored-by: Bugsounet - Cédric <github@bugsounet.fr> Co-authored-by: bugsounet <bugsounet@bugsounet.fr> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-01 21:17:31 +02:00
const hideModule = function (module, speed, callback, options = {}) {
// set lockString if set in options.
if (options.lockString) {
// Log.log("Has lockstring: " + options.lockString);
if (module.lockStrings.indexOf(options.lockString) === -1) {
module.lockStrings.push(options.lockString);
}
}
2021-04-18 15:29:10 +02:00
const moduleWrapper = document.getElementById(module.identifier);
2016-03-31 19:15:58 +02:00
if (moduleWrapper !== null) {
Release 2.23.0 (#3078) ## [2.23.0] - 2023-04-04 Thanks to: @angeldeejay, @buxxi, @CarJem, @dariom, @DaveChild, @dWoolridge, @grenagit, @Hirschberger, @KristjanESPERANTO, @MagMar94, @naveensrinivasan, @nfogal, @psieg, @rajniszp, @retroflex, @SkySails and @tomzt. Special thanks to @khassel, @rejas and @sdetweil for taking over most (if not all) of the work on this release as project collaborators. This version would not be there without their effort. Thank you guys! You are awesome! ### Added - Added increments for hourly forecasts in weather module (#2996) - Added tests for hourly weather forecast - Added possibility to ignore MagicMirror repo in updatenotification module - Added Pirate Weather as new weather provider (#3005) - Added possibility to use your own templates in Alert module - Added error message if `<modulename>.js` file is missing in module folder to get a hint in the logs (#2403) - Added possibility to use environment variables in `config.js` (#1756) - Added option `pastDaysCount` to default calendar module to control of how many days past events should be displayed - Added thai language to alert module - Added option `sendNotifications` in clock module (#3056) ### Removed - Removed darksky weather provider - Removed unneeded (and unwanted) '.' after the year in calendar repeatingCountTitle (#2896) ### Updated - Use develop as target branch for dependabot - Update issue template, contributing doc and sample config - The weather modules clearly separates precipitation amount and probability (risk of rain/snow) - This requires all providers that only supports probability to change the config from `showPrecipitationAmount` to `showPrecipitationProbability`. - Update tests for weather and calendar module - Changed updatenotification module for MagicMirror repo only: Send only notifications for `master` if there is a tag on a newer commit - Update dates in Calendar widgets every minute - Cleanup jest coverage for patches - Update `stylelint` dependencies, switch to `stylelint-config-standard` and handle `stylelint` issues, update `main.css` matching new rules - Update Eslint config, add new rule and handle issue - Convert lots of callbacks to async/await - Revise require imports (#3071 and #3072) ### Fixed - Fix wrong day labels in envcanada forecast (#2987) - Fix for missing default class name prefix for customEvents in calendar - Fix electron flashing white screen on startup (#1919) - Fix weathergov provider hourly forecast (#3008) - Fix message display with HTML code into alert module (#2828) - Fix typo in french translation - Yr wind direction is no longer inverted - Fix async node_helper stopping electron start (#2487) - The wind direction arrow now points in the direction the wind is flowing, not into the wind (#3019) - Fix precipitation css styles and rounding value - Fix wrong vertical alignment of calendar title column when wrapEvents is true (#3053) - Fix empty news feed stopping the reload forever - Fix e2e tests (failed after async changes) by running calendar and newsfeed tests last - Lint: Use template literals instead of string concatenation - Fix default alert module to render HTML for title and message - Fix Open-Meteo wind speed units
2023-04-04 20:44:32 +02:00
moduleWrapper.style.transition = `opacity ${speed / 1000}s`;
2016-03-31 19:15:58 +02:00
moduleWrapper.style.opacity = 0;
moduleWrapper.classList.add("hidden");
2016-03-24 17:19:32 +01:00
2016-04-08 17:27:02 +02:00
clearTimeout(module.showHideTimer);
module.showHideTimer = setTimeout(function () {
2016-04-01 10:25:54 +02:00
// To not take up any space, we just make the position absolute.
// since it's fade out anyway, we can see it lay above or
2016-04-01 10:25:54 +02:00
// below other modules. This works way better than adjusting
// the .display property.
2016-10-16 17:24:21 +02:00
moduleWrapper.style.position = "fixed";
2016-04-01 10:25:54 +02:00
updateWrapperStates();
if (typeof callback === "function") {
callback();
}
2016-03-31 19:15:58 +02:00
}, speed);
} else {
2018-06-07 16:31:49 +02:00
// invoke callback even if no content, issue 1308
if (typeof callback === "function") {
callback();
}
2018-06-07 07:59:07 -05:00
}
2016-03-31 19:15:58 +02:00
};
2020-08-01 17:06:46 +02:00
/**
2016-03-31 19:15:58 +02:00
* Show the module.
2020-08-01 17:06:46 +02:00
* @param {Module} module The module to show.
* @param {number} speed The speed of the show animation.
* @param {Function} callback Called when the animation is done.
* @param {object} [options] Optional settings for the show method.
2016-03-31 19:15:58 +02:00
*/
Release 2.24.0 (#3141) Signed-off-by: naveen <172697+naveensrinivasan@users.noreply.github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Karsten Hassel <hassel@gmx.de> Co-authored-by: Malte Hallström <46646495+SkySails@users.noreply.github.com> Co-authored-by: Veeck <github@veeck.de> Co-authored-by: veeck <michael@veeck.de> Co-authored-by: dWoolridge <dwoolridge@charter.net> Co-authored-by: Johan <jojjepersson@yahoo.se> Co-authored-by: Dario Mratovich <dario_mratovich@hotmail.com> Co-authored-by: Dario Mratovich <dario.mratovich@outlook.com> Co-authored-by: Magnus <34011212+MagMar94@users.noreply.github.com> Co-authored-by: Naveen <172697+naveensrinivasan@users.noreply.github.com> Co-authored-by: buxxi <buxxi@omfilm.net> Co-authored-by: Thomas Hirschberger <47733292+Tom-Hirschberger@users.noreply.github.com> Co-authored-by: Kristjan ESPERANTO <35647502+KristjanESPERANTO@users.noreply.github.com> Co-authored-by: Andrés Vanegas Jiménez <142350+angeldeejay@users.noreply.github.com> Co-authored-by: Dave Child <dave@addedbytes.com> Co-authored-by: grenagit <46225780+grenagit@users.noreply.github.com> Co-authored-by: Grena <grena@grenabox.fr> Co-authored-by: Magnus Marthinsen <magmar@online.no> Co-authored-by: Patrick <psieg@users.noreply.github.com> Co-authored-by: Piotr Rajnisz <56397164+rajniszp@users.noreply.github.com> Co-authored-by: Suthep Yonphimai <tomzt@users.noreply.github.com> Co-authored-by: CarJem Generations (Carter Wallace) <cwallacecs@gmail.com> Co-authored-by: Nicholas Fogal <nfogal.misc@gmail.com> Co-authored-by: JakeBinney <126349119+JakeBinney@users.noreply.github.com> Co-authored-by: OWL4C <124401812+OWL4C@users.noreply.github.com> Co-authored-by: Oscar Björkman <17575446+oscarb@users.noreply.github.com> Co-authored-by: Ismar Slomic <ismar@slomic.no> Co-authored-by: Jørgen Veum-Wahlberg <jorgen.wahlberg@amedia.no> Co-authored-by: Eddie Hung <6740044+eddiehung@users.noreply.github.com> Co-authored-by: Bugsounet - Cédric <github@bugsounet.fr> Co-authored-by: bugsounet <bugsounet@bugsounet.fr> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-01 21:17:31 +02:00
const showModule = function (module, speed, callback, options = {}) {
// remove lockString if set in options.
if (options.lockString) {
2021-04-18 15:29:10 +02:00
const index = module.lockStrings.indexOf(options.lockString);
if (index !== -1) {
module.lockStrings.splice(index, 1);
}
}
// Check if there are no more lockstrings set, or the force option is set.
// Otherwise cancel show action.
if (module.lockStrings.length !== 0 && options.force !== true) {
Release 2.23.0 (#3078) ## [2.23.0] - 2023-04-04 Thanks to: @angeldeejay, @buxxi, @CarJem, @dariom, @DaveChild, @dWoolridge, @grenagit, @Hirschberger, @KristjanESPERANTO, @MagMar94, @naveensrinivasan, @nfogal, @psieg, @rajniszp, @retroflex, @SkySails and @tomzt. Special thanks to @khassel, @rejas and @sdetweil for taking over most (if not all) of the work on this release as project collaborators. This version would not be there without their effort. Thank you guys! You are awesome! ### Added - Added increments for hourly forecasts in weather module (#2996) - Added tests for hourly weather forecast - Added possibility to ignore MagicMirror repo in updatenotification module - Added Pirate Weather as new weather provider (#3005) - Added possibility to use your own templates in Alert module - Added error message if `<modulename>.js` file is missing in module folder to get a hint in the logs (#2403) - Added possibility to use environment variables in `config.js` (#1756) - Added option `pastDaysCount` to default calendar module to control of how many days past events should be displayed - Added thai language to alert module - Added option `sendNotifications` in clock module (#3056) ### Removed - Removed darksky weather provider - Removed unneeded (and unwanted) '.' after the year in calendar repeatingCountTitle (#2896) ### Updated - Use develop as target branch for dependabot - Update issue template, contributing doc and sample config - The weather modules clearly separates precipitation amount and probability (risk of rain/snow) - This requires all providers that only supports probability to change the config from `showPrecipitationAmount` to `showPrecipitationProbability`. - Update tests for weather and calendar module - Changed updatenotification module for MagicMirror repo only: Send only notifications for `master` if there is a tag on a newer commit - Update dates in Calendar widgets every minute - Cleanup jest coverage for patches - Update `stylelint` dependencies, switch to `stylelint-config-standard` and handle `stylelint` issues, update `main.css` matching new rules - Update Eslint config, add new rule and handle issue - Convert lots of callbacks to async/await - Revise require imports (#3071 and #3072) ### Fixed - Fix wrong day labels in envcanada forecast (#2987) - Fix for missing default class name prefix for customEvents in calendar - Fix electron flashing white screen on startup (#1919) - Fix weathergov provider hourly forecast (#3008) - Fix message display with HTML code into alert module (#2828) - Fix typo in french translation - Yr wind direction is no longer inverted - Fix async node_helper stopping electron start (#2487) - The wind direction arrow now points in the direction the wind is flowing, not into the wind (#3019) - Fix precipitation css styles and rounding value - Fix wrong vertical alignment of calendar title column when wrapEvents is true (#3053) - Fix empty news feed stopping the reload forever - Fix e2e tests (failed after async changes) by running calendar and newsfeed tests last - Lint: Use template literals instead of string concatenation - Fix default alert module to render HTML for title and message - Fix Open-Meteo wind speed units
2023-04-04 20:44:32 +02:00
Log.log(`Will not show ${module.name}. LockStrings active: ${module.lockStrings.join(",")}`);
if (typeof options.onError === "function") {
2021-02-23 14:11:54 +01:00
options.onError(new Error("LOCK_STRING_ACTIVE"));
2021-02-06 21:22:13 +01:00
}
return;
}
2017-01-28 12:26:52 +01:00
module.hidden = false;
// If forced show, clean current lockstrings.
if (module.lockStrings.length !== 0 && options.force === true) {
Release 2.23.0 (#3078) ## [2.23.0] - 2023-04-04 Thanks to: @angeldeejay, @buxxi, @CarJem, @dariom, @DaveChild, @dWoolridge, @grenagit, @Hirschberger, @KristjanESPERANTO, @MagMar94, @naveensrinivasan, @nfogal, @psieg, @rajniszp, @retroflex, @SkySails and @tomzt. Special thanks to @khassel, @rejas and @sdetweil for taking over most (if not all) of the work on this release as project collaborators. This version would not be there without their effort. Thank you guys! You are awesome! ### Added - Added increments for hourly forecasts in weather module (#2996) - Added tests for hourly weather forecast - Added possibility to ignore MagicMirror repo in updatenotification module - Added Pirate Weather as new weather provider (#3005) - Added possibility to use your own templates in Alert module - Added error message if `<modulename>.js` file is missing in module folder to get a hint in the logs (#2403) - Added possibility to use environment variables in `config.js` (#1756) - Added option `pastDaysCount` to default calendar module to control of how many days past events should be displayed - Added thai language to alert module - Added option `sendNotifications` in clock module (#3056) ### Removed - Removed darksky weather provider - Removed unneeded (and unwanted) '.' after the year in calendar repeatingCountTitle (#2896) ### Updated - Use develop as target branch for dependabot - Update issue template, contributing doc and sample config - The weather modules clearly separates precipitation amount and probability (risk of rain/snow) - This requires all providers that only supports probability to change the config from `showPrecipitationAmount` to `showPrecipitationProbability`. - Update tests for weather and calendar module - Changed updatenotification module for MagicMirror repo only: Send only notifications for `master` if there is a tag on a newer commit - Update dates in Calendar widgets every minute - Cleanup jest coverage for patches - Update `stylelint` dependencies, switch to `stylelint-config-standard` and handle `stylelint` issues, update `main.css` matching new rules - Update Eslint config, add new rule and handle issue - Convert lots of callbacks to async/await - Revise require imports (#3071 and #3072) ### Fixed - Fix wrong day labels in envcanada forecast (#2987) - Fix for missing default class name prefix for customEvents in calendar - Fix electron flashing white screen on startup (#1919) - Fix weathergov provider hourly forecast (#3008) - Fix message display with HTML code into alert module (#2828) - Fix typo in french translation - Yr wind direction is no longer inverted - Fix async node_helper stopping electron start (#2487) - The wind direction arrow now points in the direction the wind is flowing, not into the wind (#3019) - Fix precipitation css styles and rounding value - Fix wrong vertical alignment of calendar title column when wrapEvents is true (#3053) - Fix empty news feed stopping the reload forever - Fix e2e tests (failed after async changes) by running calendar and newsfeed tests last - Lint: Use template literals instead of string concatenation - Fix default alert module to render HTML for title and message - Fix Open-Meteo wind speed units
2023-04-04 20:44:32 +02:00
Log.log(`Force show of module: ${module.name}`);
module.lockStrings = [];
}
2021-04-18 15:29:10 +02:00
const moduleWrapper = document.getElementById(module.identifier);
2016-03-31 19:15:58 +02:00
if (moduleWrapper !== null) {
Release 2.23.0 (#3078) ## [2.23.0] - 2023-04-04 Thanks to: @angeldeejay, @buxxi, @CarJem, @dariom, @DaveChild, @dWoolridge, @grenagit, @Hirschberger, @KristjanESPERANTO, @MagMar94, @naveensrinivasan, @nfogal, @psieg, @rajniszp, @retroflex, @SkySails and @tomzt. Special thanks to @khassel, @rejas and @sdetweil for taking over most (if not all) of the work on this release as project collaborators. This version would not be there without their effort. Thank you guys! You are awesome! ### Added - Added increments for hourly forecasts in weather module (#2996) - Added tests for hourly weather forecast - Added possibility to ignore MagicMirror repo in updatenotification module - Added Pirate Weather as new weather provider (#3005) - Added possibility to use your own templates in Alert module - Added error message if `<modulename>.js` file is missing in module folder to get a hint in the logs (#2403) - Added possibility to use environment variables in `config.js` (#1756) - Added option `pastDaysCount` to default calendar module to control of how many days past events should be displayed - Added thai language to alert module - Added option `sendNotifications` in clock module (#3056) ### Removed - Removed darksky weather provider - Removed unneeded (and unwanted) '.' after the year in calendar repeatingCountTitle (#2896) ### Updated - Use develop as target branch for dependabot - Update issue template, contributing doc and sample config - The weather modules clearly separates precipitation amount and probability (risk of rain/snow) - This requires all providers that only supports probability to change the config from `showPrecipitationAmount` to `showPrecipitationProbability`. - Update tests for weather and calendar module - Changed updatenotification module for MagicMirror repo only: Send only notifications for `master` if there is a tag on a newer commit - Update dates in Calendar widgets every minute - Cleanup jest coverage for patches - Update `stylelint` dependencies, switch to `stylelint-config-standard` and handle `stylelint` issues, update `main.css` matching new rules - Update Eslint config, add new rule and handle issue - Convert lots of callbacks to async/await - Revise require imports (#3071 and #3072) ### Fixed - Fix wrong day labels in envcanada forecast (#2987) - Fix for missing default class name prefix for customEvents in calendar - Fix electron flashing white screen on startup (#1919) - Fix weathergov provider hourly forecast (#3008) - Fix message display with HTML code into alert module (#2828) - Fix typo in french translation - Yr wind direction is no longer inverted - Fix async node_helper stopping electron start (#2487) - The wind direction arrow now points in the direction the wind is flowing, not into the wind (#3019) - Fix precipitation css styles and rounding value - Fix wrong vertical alignment of calendar title column when wrapEvents is true (#3053) - Fix empty news feed stopping the reload forever - Fix e2e tests (failed after async changes) by running calendar and newsfeed tests last - Lint: Use template literals instead of string concatenation - Fix default alert module to render HTML for title and message - Fix Open-Meteo wind speed units
2023-04-04 20:44:32 +02:00
moduleWrapper.style.transition = `opacity ${speed / 1000}s`;
2019-06-04 09:33:53 +02:00
// Restore the position. See hideModule() for more info.
2016-04-05 14:35:11 -04:00
moduleWrapper.style.position = "static";
moduleWrapper.classList.remove("hidden");
2016-03-24 17:19:32 +01:00
updateWrapperStates();
// Waiting for DOM-changes done in updateWrapperStates before we can start the animation.
2021-04-18 15:29:10 +02:00
const dummy = moduleWrapper.parentElement.parentElement.offsetHeight;
moduleWrapper.style.opacity = 1;
2016-04-08 17:27:02 +02:00
clearTimeout(module.showHideTimer);
module.showHideTimer = setTimeout(function () {
if (typeof callback === "function") {
2021-02-06 21:22:13 +01:00
callback();
}
2016-03-31 19:15:58 +02:00
}, speed);
2020-03-19 19:03:25 +01:00
} else {
// invoke callback
if (typeof callback === "function") {
2021-02-06 21:22:13 +01:00
callback();
}
2016-03-31 19:15:58 +02:00
}
2016-03-24 17:19:32 +01:00
};
2020-08-01 17:06:46 +02:00
/**
* Checks for all positions if it has visible content.
* If not, if will hide the position to prevent unwanted margins.
2019-06-04 09:33:53 +02:00
* This method should be called by the show and hide methods.
2016-11-24 00:26:40 -03:00
*
* Example:
* If the top_bar only contains the update notification. And no update is available,
* the update notification is hidden. The top bar still occupies space making for
2016-11-24 00:26:40 -03:00
* an ugly top margin. By using this function, the top bar will be hidden if the
* update notification is not visible.
*/
2021-04-18 15:29:10 +02:00
const updateWrapperStates = function () {
const positions = ["top_bar", "top_left", "top_center", "top_right", "upper_third", "middle_center", "lower_third", "bottom_left", "bottom_center", "bottom_right", "bottom_bar", "fullscreen_above", "fullscreen_below"];
2016-11-24 00:26:40 -03:00
positions.forEach(function (position) {
2021-04-18 15:29:10 +02:00
const wrapper = selectWrapper(position);
const moduleWrappers = wrapper.getElementsByClassName("module");
2021-04-18 15:29:10 +02:00
let showWrapper = false;
Array.prototype.forEach.call(moduleWrappers, function (moduleWrapper) {
if (moduleWrapper.style.position === "" || moduleWrapper.style.position === "static") {
showWrapper = true;
2016-11-24 00:26:40 -03:00
}
});
wrapper.style.display = showWrapper ? "block" : "none";
});
};
2020-08-01 17:06:46 +02:00
/**
* Loads the core config and combines it with the system defaults.
2016-03-24 17:19:32 +01:00
*/
2021-04-18 15:29:10 +02:00
const loadConfig = function () {
// FIXME: Think about how to pass config around without breaking tests
/* eslint-disable */
2016-04-05 14:35:11 -04:00
if (typeof config === "undefined") {
config = defaults;
2016-04-05 14:35:11 -04:00
Log.error("Config file is missing! Please create a config file.");
2016-03-24 17:19:32 +01:00
return;
}
config = Object.assign({}, defaults, config);
/* eslint-enable */
2016-03-24 17:19:32 +01:00
};
2020-08-01 17:06:46 +02:00
/**
2016-03-31 17:05:35 +02:00
* Adds special selectors on a collection of modules.
2020-08-01 17:06:46 +02:00
* @param {Module[]} modules Array of modules.
2016-03-31 17:05:35 +02:00
*/
2021-04-18 15:29:10 +02:00
const setSelectionMethodsForModules = function (modules) {
2020-08-01 17:06:46 +02:00
/**
* Filter modules with the specified classes.
* @param {string|string[]} className one or multiple classnames (array or space divided).
* @returns {Module[]} Filtered collection of modules.
2016-03-31 17:05:35 +02:00
*/
2021-04-18 15:29:10 +02:00
const withClass = function (className) {
2017-02-07 23:51:13 +01:00
return modulesByClass(className, true);
2016-03-31 17:05:35 +02:00
};
2020-08-01 17:06:46 +02:00
/**
* Filter modules without the specified classes.
* @param {string|string[]} className one or multiple classnames (array or space divided).
* @returns {Module[]} Filtered collection of modules.
2016-03-31 17:05:35 +02:00
*/
2021-04-18 15:29:10 +02:00
const exceptWithClass = function (className) {
2017-02-08 00:05:28 +01:00
return modulesByClass(className, false);
2016-03-31 17:05:35 +02:00
};
2020-08-01 17:06:46 +02:00
/**
* Filters a collection of modules based on classname(s).
* @param {string|string[]} className one or multiple classnames (array or space divided).
* @param {boolean} include if the filter should include or exclude the modules with the specific classes.
* @returns {Module[]} Filtered collection of modules.
2017-02-07 23:51:13 +01:00
*/
2021-04-18 15:29:10 +02:00
const modulesByClass = function (className, include) {
let searchClasses = className;
2017-02-08 00:05:28 +01:00
if (typeof className === "string") {
searchClasses = className.split(" ");
}
2021-04-18 15:29:10 +02:00
const newModules = modules.filter(function (module) {
const classes = module.data.classes.toLowerCase().split(" ");
2017-02-08 00:05:28 +01:00
2021-04-18 15:29:10 +02:00
for (const searchClass of searchClasses) {
2017-02-08 00:05:28 +01:00
if (classes.indexOf(searchClass.toLowerCase()) !== -1) {
return include;
}
}
return !include;
});
setSelectionMethodsForModules(newModules);
return newModules;
};
2017-02-07 23:51:13 +01:00
2020-08-01 17:06:46 +02:00
/**
2016-03-31 17:05:35 +02:00
* Removes a module instance from the collection.
2020-08-01 17:06:46 +02:00
* @param {object} module The module instance to remove from the collection.
* @returns {Module[]} Filtered collection of modules.
2016-03-31 17:05:35 +02:00
*/
2021-04-18 15:29:10 +02:00
const exceptModule = function (module) {
const newModules = modules.filter(function (mod) {
return mod.identifier !== module.identifier;
});
2016-03-31 17:05:35 +02:00
setSelectionMethodsForModules(newModules);
return newModules;
};
2020-08-01 17:06:46 +02:00
/**
2016-03-31 17:05:35 +02:00
* Walks thru a collection of modules and executes the callback with the module as an argument.
2020-08-01 17:06:46 +02:00
* @param {Function} callback The function to execute with the module as an argument.
2016-03-31 17:05:35 +02:00
*/
2021-04-18 15:29:10 +02:00
const enumerate = function (callback) {
modules.map(function (module) {
2016-03-31 17:05:35 +02:00
callback(module);
});
2016-03-31 17:05:35 +02:00
};
if (typeof modules.withClass === "undefined") {
Object.defineProperty(modules, "withClass", { value: withClass, enumerable: false });
}
if (typeof modules.exceptWithClass === "undefined") {
Object.defineProperty(modules, "exceptWithClass", { value: exceptWithClass, enumerable: false });
}
if (typeof modules.exceptModule === "undefined") {
Object.defineProperty(modules, "exceptModule", { value: exceptModule, enumerable: false });
}
if (typeof modules.enumerate === "undefined") {
Object.defineProperty(modules, "enumerate", { value: enumerate, enumerable: false });
}
2016-03-31 17:05:35 +02:00
};
2016-03-31 19:15:58 +02:00
2016-03-24 17:19:32 +01:00
return {
/* Public Methods */
2020-08-01 17:06:46 +02:00
/**
2016-03-24 17:19:32 +01:00
* Main init method.
*/
Release 2.23.0 (#3078) ## [2.23.0] - 2023-04-04 Thanks to: @angeldeejay, @buxxi, @CarJem, @dariom, @DaveChild, @dWoolridge, @grenagit, @Hirschberger, @KristjanESPERANTO, @MagMar94, @naveensrinivasan, @nfogal, @psieg, @rajniszp, @retroflex, @SkySails and @tomzt. Special thanks to @khassel, @rejas and @sdetweil for taking over most (if not all) of the work on this release as project collaborators. This version would not be there without their effort. Thank you guys! You are awesome! ### Added - Added increments for hourly forecasts in weather module (#2996) - Added tests for hourly weather forecast - Added possibility to ignore MagicMirror repo in updatenotification module - Added Pirate Weather as new weather provider (#3005) - Added possibility to use your own templates in Alert module - Added error message if `<modulename>.js` file is missing in module folder to get a hint in the logs (#2403) - Added possibility to use environment variables in `config.js` (#1756) - Added option `pastDaysCount` to default calendar module to control of how many days past events should be displayed - Added thai language to alert module - Added option `sendNotifications` in clock module (#3056) ### Removed - Removed darksky weather provider - Removed unneeded (and unwanted) '.' after the year in calendar repeatingCountTitle (#2896) ### Updated - Use develop as target branch for dependabot - Update issue template, contributing doc and sample config - The weather modules clearly separates precipitation amount and probability (risk of rain/snow) - This requires all providers that only supports probability to change the config from `showPrecipitationAmount` to `showPrecipitationProbability`. - Update tests for weather and calendar module - Changed updatenotification module for MagicMirror repo only: Send only notifications for `master` if there is a tag on a newer commit - Update dates in Calendar widgets every minute - Cleanup jest coverage for patches - Update `stylelint` dependencies, switch to `stylelint-config-standard` and handle `stylelint` issues, update `main.css` matching new rules - Update Eslint config, add new rule and handle issue - Convert lots of callbacks to async/await - Revise require imports (#3071 and #3072) ### Fixed - Fix wrong day labels in envcanada forecast (#2987) - Fix for missing default class name prefix for customEvents in calendar - Fix electron flashing white screen on startup (#1919) - Fix weathergov provider hourly forecast (#3008) - Fix message display with HTML code into alert module (#2828) - Fix typo in french translation - Yr wind direction is no longer inverted - Fix async node_helper stopping electron start (#2487) - The wind direction arrow now points in the direction the wind is flowing, not into the wind (#3019) - Fix precipitation css styles and rounding value - Fix wrong vertical alignment of calendar title column when wrapEvents is true (#3053) - Fix empty news feed stopping the reload forever - Fix e2e tests (failed after async changes) by running calendar and newsfeed tests last - Lint: Use template literals instead of string concatenation - Fix default alert module to render HTML for title and message - Fix Open-Meteo wind speed units
2023-04-04 20:44:32 +02:00
init: async function () {
2022-01-26 23:47:51 +01:00
Log.info("Initializing MagicMirror².");
2016-03-24 17:19:32 +01:00
loadConfig();
2020-07-04 22:02:39 +02:00
Log.setLogLevel(config.logLevel);
Release 2.23.0 (#3078) ## [2.23.0] - 2023-04-04 Thanks to: @angeldeejay, @buxxi, @CarJem, @dariom, @DaveChild, @dWoolridge, @grenagit, @Hirschberger, @KristjanESPERANTO, @MagMar94, @naveensrinivasan, @nfogal, @psieg, @rajniszp, @retroflex, @SkySails and @tomzt. Special thanks to @khassel, @rejas and @sdetweil for taking over most (if not all) of the work on this release as project collaborators. This version would not be there without their effort. Thank you guys! You are awesome! ### Added - Added increments for hourly forecasts in weather module (#2996) - Added tests for hourly weather forecast - Added possibility to ignore MagicMirror repo in updatenotification module - Added Pirate Weather as new weather provider (#3005) - Added possibility to use your own templates in Alert module - Added error message if `<modulename>.js` file is missing in module folder to get a hint in the logs (#2403) - Added possibility to use environment variables in `config.js` (#1756) - Added option `pastDaysCount` to default calendar module to control of how many days past events should be displayed - Added thai language to alert module - Added option `sendNotifications` in clock module (#3056) ### Removed - Removed darksky weather provider - Removed unneeded (and unwanted) '.' after the year in calendar repeatingCountTitle (#2896) ### Updated - Use develop as target branch for dependabot - Update issue template, contributing doc and sample config - The weather modules clearly separates precipitation amount and probability (risk of rain/snow) - This requires all providers that only supports probability to change the config from `showPrecipitationAmount` to `showPrecipitationProbability`. - Update tests for weather and calendar module - Changed updatenotification module for MagicMirror repo only: Send only notifications for `master` if there is a tag on a newer commit - Update dates in Calendar widgets every minute - Cleanup jest coverage for patches - Update `stylelint` dependencies, switch to `stylelint-config-standard` and handle `stylelint` issues, update `main.css` matching new rules - Update Eslint config, add new rule and handle issue - Convert lots of callbacks to async/await - Revise require imports (#3071 and #3072) ### Fixed - Fix wrong day labels in envcanada forecast (#2987) - Fix for missing default class name prefix for customEvents in calendar - Fix electron flashing white screen on startup (#1919) - Fix weathergov provider hourly forecast (#3008) - Fix message display with HTML code into alert module (#2828) - Fix typo in french translation - Yr wind direction is no longer inverted - Fix async node_helper stopping electron start (#2487) - The wind direction arrow now points in the direction the wind is flowing, not into the wind (#3019) - Fix precipitation css styles and rounding value - Fix wrong vertical alignment of calendar title column when wrapEvents is true (#3053) - Fix empty news feed stopping the reload forever - Fix e2e tests (failed after async changes) by running calendar and newsfeed tests last - Lint: Use template literals instead of string concatenation - Fix default alert module to render HTML for title and message - Fix Open-Meteo wind speed units
2023-04-04 20:44:32 +02:00
await Translator.loadCoreTranslations(config.language);
await Loader.loadModules();
2016-03-24 17:19:32 +01:00
},
2020-08-01 17:06:46 +02:00
/**
2016-03-24 17:19:32 +01:00
* Gets called when all modules are started.
2020-08-01 17:06:46 +02:00
* @param {Module[]} moduleObjects All module instances.
2016-03-24 17:19:32 +01:00
*/
modulesStarted: function (moduleObjects) {
2016-03-24 17:19:32 +01:00
modules = [];
2020-12-29 21:45:35 +01:00
moduleObjects.forEach((module) => modules.push(module));
2016-03-24 17:19:32 +01:00
2016-04-05 14:35:11 -04:00
Log.info("All modules started!");
sendNotification("ALL_MODULES_STARTED");
2016-03-24 17:19:32 +01:00
createDomObjects();
},
2020-08-01 17:06:46 +02:00
/**
2016-03-24 17:19:32 +01:00
* Send a notification to all modules.
2020-08-01 17:06:46 +02:00
* @param {string} notification The identifier of the notification.
* @param {*} payload The payload of the notification.
* @param {Module} sender The module that sent the notification.
2016-03-24 17:19:32 +01:00
*/
sendNotification: function (notification, payload, sender) {
2016-03-24 17:19:32 +01:00
if (arguments.length < 3) {
2016-04-05 14:35:11 -04:00
Log.error("sendNotification: Missing arguments.");
2016-03-24 17:19:32 +01:00
return;
}
2016-04-05 14:35:11 -04:00
if (typeof notification !== "string") {
Log.error("sendNotification: Notification should be a string.");
2016-03-24 17:19:32 +01:00
return;
}
if (!(sender instanceof Module)) {
2016-04-05 14:35:11 -04:00
Log.error("sendNotification: Sender should be a module.");
2016-03-24 17:19:32 +01:00
return;
}
// Further implementation is done in the private method.
sendNotification(notification, payload, sender);
},
2020-08-01 17:06:46 +02:00
/**
2016-03-24 17:19:32 +01:00
* Update the dom for a specific module.
2020-08-01 17:06:46 +02:00
* @param {Module} module The module that needs an update.
* @param {number} [speed] The number of microseconds for the animation.
2016-03-24 17:19:32 +01:00
*/
updateDom: function (module, speed) {
2016-03-24 17:19:32 +01:00
if (!(module instanceof Module)) {
2016-04-05 14:35:11 -04:00
Log.error("updateDom: Sender should be a module.");
2016-03-24 17:19:32 +01:00
return;
}
if (!module.data.position) {
Log.warn("module tries to update the DOM without being displayed.");
return;
}
2016-03-24 17:19:32 +01:00
// Further implementation is done in the private method.
updateDom(module, speed);
2016-03-31 17:05:35 +02:00
},
2020-08-01 17:06:46 +02:00
/**
2016-03-31 17:06:39 +02:00
* Returns a collection of all modules currently active.
2020-08-01 17:06:46 +02:00
* @returns {Module[]} A collection of all modules currently active.
2016-03-31 17:06:39 +02:00
*/
getModules: function () {
2016-03-31 17:05:35 +02:00
setSelectionMethodsForModules(modules);
return modules;
2016-03-31 19:15:58 +02:00
},
2020-08-01 17:06:46 +02:00
/**
2016-03-31 19:15:58 +02:00
* Hide the module.
2020-08-01 17:06:46 +02:00
* @param {Module} module The module to hide.
* @param {number} speed The speed of the hide animation.
* @param {Function} callback Called when the animation is done.
* @param {object} [options] Optional settings for the hide method.
2016-03-31 19:15:58 +02:00
*/
hideModule: function (module, speed, callback, options) {
2016-04-01 10:44:17 +02:00
module.hidden = true;
hideModule(module, speed, callback, options);
2016-03-31 19:15:58 +02:00
},
2020-08-01 17:06:46 +02:00
/**
2016-03-31 19:15:58 +02:00
* Show the module.
2020-08-01 17:06:46 +02:00
* @param {Module} module The module to show.
* @param {number} speed The speed of the show animation.
* @param {Function} callback Called when the animation is done.
* @param {object} [options] Optional settings for the show method.
2016-03-31 19:15:58 +02:00
*/
showModule: function (module, speed, callback, options) {
2017-01-28 12:26:52 +01:00
// do not change module.hidden yet, only if we really show it later
showModule(module, speed, callback, options);
2016-03-24 17:19:32 +01:00
}
};
})();
2016-04-18 20:03:12 +02:00
// Add polyfill for Object.assign.
2019-06-05 09:32:10 +02:00
if (typeof Object.assign !== "function") {
(function () {
Object.assign = function (target) {
2016-05-03 19:09:38 -04:00
"use strict";
if (target === undefined || target === null) {
throw new TypeError("Cannot convert undefined or null to object");
}
2021-04-18 15:29:10 +02:00
const output = Object(target);
for (let index = 1; index < arguments.length; index++) {
const source = arguments[index];
2016-05-03 19:09:38 -04:00
if (source !== undefined && source !== null) {
2021-04-18 15:29:10 +02:00
for (const nextKey in source) {
2016-05-03 19:09:38 -04:00
if (source.hasOwnProperty(nextKey)) {
output[nextKey] = source[nextKey];
}
}
}
}
return output;
};
})();
}
2016-04-18 20:03:12 +02:00
2016-03-24 17:19:32 +01:00
MM.init();