Skip to content

Commit

Permalink
Merge pull request #6 from MichMich/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Ybbet authored Sep 20, 2023
2 parents cc1a8b8 + 8b1c279 commit 4ee6318
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 55 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ _This release is scheduled to be released on 2023-10-01._
- Update typescript definition for modules
- Cleaned up nunjuck templates
- Replace `node-fetch` with internal fetch (#2649) and remove `digest-fetch`
- Updated the French translation according to the English file.

### Fixed

Expand All @@ -46,6 +47,8 @@ _This release is scheduled to be released on 2023-10-01._
- Fix ipWhiteList test (#3179)
- Fix newsfeed: Convert HTML entities, codes and tag in description (#3191)
- Respect width/height (no fullscreen) if set in electronOptions (together with `fullscreen: false`) in `config.js` (#3174)
- Fix: AnimateCSS merge hide() and show() animated css class when we do multiple call
- Fix `Uncaught SyntaxError: Identifier 'getCorsUrl' has already been declared (at utils.js:1:1)` when using `clock` and `weather` module (#3204)

## [2.24.0] - 2023-07-01

Expand Down Expand Up @@ -88,6 +91,7 @@ Special thanks to @khassel, @rejas and @sdetweil for taking over most (if not al
- Fix date not shown when clock in analog mode (#3100)
- Fix envcanada today percentage-of-precipitation (#3106)
- Fix updatenotification where no branch is checked out but e.g. a version tag (#3130)
- Fix yr weather provider after changes in yr API (#3189)

## [2.23.0] - 2023-04-04

Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<script type="text/javascript" src="#CONFIG_FILE#"></script>
<script type="text/javascript" src="vendor/vendor.js"></script>
<script type="text/javascript" src="modules/default/defaultmodules.js"></script>
<script type="text/javascript" src="modules/default/utils.js"></script>
<script type="text/javascript" src="js/logger.js"></script>
<script type="text/javascript" src="translations/translations.js"></script>
<script type="text/javascript" src="js/translator.js"></script>
Expand Down
53 changes: 26 additions & 27 deletions js/animateCSS.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,36 +130,35 @@ const AnimateCSSOut = [

/**
* Create an animation with Animate CSS
* resolved as Promise when done
* @param {string} [element] div element to animate.
* @param {string} [animation] animation name.
* @param {number} [animationTime] animation duration.
*/
function AnimateCSS(element, animation, animationTime) {
/* We create a Promise and return it */
return new Promise((resolve) => {
const animationName = `animate__${animation}`;
const node = document.getElementById(element);
if (!node) {
// don't execute animate and resolve
Log.warn(`AnimateCSS: node not found for`, element);
resolve();
return;
}
node.style.setProperty("--animate-duration", `${animationTime}s`);
node.classList.add("animate__animated", animationName);

/**
* When the animation ends, we clean the classes and resolve the Promise
* @param {object} event object
*/
function handleAnimationEnd(event) {
node.classList.remove("animate__animated", animationName);
node.style.removeProperty("--animate-duration", `${animationTime}s`);
event.stopPropagation();
resolve();
}
function addAnimateCSS(element, animation, animationTime) {
const animationName = `animate__${animation}`;
const node = document.getElementById(element);
if (!node) {
// don't execute animate: we don't find div
Log.warn(`addAnimateCSS: node not found for`, element);
return;
}
node.style.setProperty("--animate-duration", `${animationTime}s`);
node.classList.add("animate__animated", animationName);
}

node.addEventListener("animationend", handleAnimationEnd, { once: true });
});
/**
* Remove an animation with Animate CSS
* @param {string} [element] div element to animate.
* @param {string} [animation] animation name.
*/
function removeAnimateCSS(element, animation) {
const animationName = `animate__${animation}`;
const node = document.getElementById(element);
if (!node) {
// don't execute animate: we don't find div
Log.warn(`removeAnimateCSS: node not found for`, element);
return;
}
node.classList.remove("animate__animated", animationName);
node.style.removeProperty("--animate-duration");
}
69 changes: 51 additions & 18 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global Loader, defaults, Translator, AnimateCSS, AnimateCSSIn, AnimateCSSOut */
/* global Loader, defaults, Translator, addAnimateCSS, removeAnimateCSS, AnimateCSSIn, AnimateCSSOut */

/* MagicMirror²
* Main System
Expand Down Expand Up @@ -57,7 +57,7 @@ const MM = (function () {
// create the domCreationPromise with AnimateCSS (with animateIn of module definition)
// or just display it
var domCreationPromise;
if (haveAnimateIn) domCreationPromise = updateDom(module, 1000, null, haveAnimateIn, true);
if (haveAnimateIn) domCreationPromise = updateDom(module, { options: { speed: 1000, animate: { in: haveAnimateIn } } }, true);
else domCreationPromise = updateDom(module, 0);

domCreationPromises.push(domCreationPromise);
Expand Down Expand Up @@ -269,7 +269,7 @@ const MM = (function () {
* @param {Function} callback Called when the animation is done.
* @param {object} [options] Optional settings for the hide method.
*/
const hideModule = async function (module, speed, callback, options = {}) {
const hideModule = function (module, speed, callback, options = {}) {
// set lockString if set in options.
if (options.lockString) {
// Log.log("Has lockstring: " + options.lockString);
Expand All @@ -281,7 +281,17 @@ const MM = (function () {
const moduleWrapper = document.getElementById(module.identifier);
if (moduleWrapper !== null) {
clearTimeout(module.showHideTimer);

// reset all animations if needed
if (module.hasAnimateOut) {
removeAnimateCSS(module.identifier, module.hasAnimateOut);
Log.debug(`${module.identifier} Force remove animateOut (in hide): ${module.hasAnimateOut}`);
module.hasAnimateOut = false;
}
if (module.hasAnimateIn) {
removeAnimateCSS(module.identifier, module.hasAnimateIn);
Log.debug(`${module.identifier} Force remove animateIn (in hide): ${module.hasAnimateIn}`);
module.hasAnimateIn = false;
}
// haveAnimateName for verify if we are using AninateCSS library
// we check AnimateCSSOut Array for validate it
// and finaly return the animate name or `null` (for default MM² animation)
Expand All @@ -294,16 +304,22 @@ const MM = (function () {
if (haveAnimateName) {
// with AnimateCSS
Log.debug(`${module.identifier} Has animateOut: ${haveAnimateName}`);
await AnimateCSS(module.identifier, haveAnimateName, speed / 1000);
// AnimateCSS is now done
moduleWrapper.style.opacity = 0;
moduleWrapper.classList.add("hidden");
moduleWrapper.style.position = "fixed";
module.hasAnimateOut = haveAnimateName;
addAnimateCSS(module.identifier, haveAnimateName, speed / 1000);
module.showHideTimer = setTimeout(function () {
removeAnimateCSS(module.identifier, haveAnimateName);
Log.debug(`${module.identifier} Remove animateOut: ${module.hasAnimateOut}`);
// AnimateCSS is now done
moduleWrapper.style.opacity = 0;
moduleWrapper.classList.add("hidden");
moduleWrapper.style.position = "fixed";
module.hasAnimateOut = false;

updateWrapperStates();
if (typeof callback === "function") {
callback();
}
updateWrapperStates();
if (typeof callback === "function") {
callback();
}
}, speed);
} else {
// default MM² Animate
moduleWrapper.style.transition = `opacity ${speed / 1000}s`;
Expand Down Expand Up @@ -338,7 +354,7 @@ const MM = (function () {
* @param {Function} callback Called when the animation is done.
* @param {object} [options] Optional settings for the show method.
*/
const showModule = async function (module, speed, callback, options = {}) {
const showModule = function (module, speed, callback, options = {}) {
// remove lockString if set in options.
if (options.lockString) {
const index = module.lockStrings.indexOf(options.lockString);
Expand All @@ -356,6 +372,17 @@ const MM = (function () {
}
return;
}
// reset all animations if needed
if (module.hasAnimateOut) {
removeAnimateCSS(module.identifier, module.hasAnimateOut);
Log.debug(`${module.identifier} Force remove animateOut (in show): ${module.hasAnimateOut}`);
module.hasAnimateOut = false;
}
if (module.hasAnimateIn) {
removeAnimateCSS(module.identifier, module.hasAnimateIn);
Log.debug(`${module.identifier} Force remove animateIn (in show): ${module.hasAnimateIn}`);
module.hasAnimateIn = false;
}

module.hidden = false;

Expand Down Expand Up @@ -392,10 +419,16 @@ const MM = (function () {
if (haveAnimateName) {
// with AnimateCSS
Log.debug(`${module.identifier} Has animateIn: ${haveAnimateName}`);
await AnimateCSS(module.identifier, haveAnimateName, speed / 1000);
if (typeof callback === "function") {
callback();
}
module.hasAnimateIn = haveAnimateName;
addAnimateCSS(module.identifier, haveAnimateName, speed / 1000);
module.showHideTimer = setTimeout(function () {
removeAnimateCSS(module.identifier, haveAnimateName);
Log.debug(`${module.identifier} Remove animateIn: ${haveAnimateName}`);
module.hasAnimateIn = false;
if (typeof callback === "function") {
callback();
}
}, speed);
} else {
// default MM² Animate
module.showHideTimer = setTimeout(function () {
Expand Down
2 changes: 2 additions & 0 deletions js/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ const Module = Class.extend({
this.name = data.name;
this.identifier = data.identifier;
this.hidden = false;
this.hasAnimateIn = false;
this.hasAnimateOut = false;

this.setConfig(data.config, data.configDeepMerge);
},
Expand Down
2 changes: 1 addition & 1 deletion modules/default/clock/clock.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Module.register("clock", {
},
// Define required scripts.
getScripts: function () {
return ["moment.js", "moment-timezone.js", "suncalc.js", this.file("../utils.js")];
return ["moment.js", "moment-timezone.js", "suncalc.js"];
},
// Define styles.
getStyles: function () {
Expand Down
11 changes: 3 additions & 8 deletions modules/default/weather/providers/yr.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,7 @@ WeatherProvider.register("yr", {
if (hours.length < 2) {
hours = `0${hours}`;
}

return `${this.config.apiBase}/sunrise/2.0/.json?date=${date}&days=${days}&height=${altitude}&lat=${lat}&lon=${lon}&offset=${utcOffsetPrefix}${hours}%3A${minutes}`;
return `${this.config.apiBase}/sunrise/2.3/sun?lat=${lat}&lon=${lon}&date=${date}&offset=${utcOffsetPrefix}${hours}%3A${minutes}`;
},

cacheStellarData(data) {
Expand All @@ -362,8 +361,6 @@ WeatherProvider.register("yr", {

getWeatherDataFrom(forecast, stellarData, units) {
const weather = new WeatherObject();
const stellarTimesToday = stellarData?.today ? this.getStellarTimesFrom(stellarData.today, moment().format("YYYY-MM-DD")) : undefined;
const stellarTimesTomorrow = stellarData?.tomorrow ? this.getStellarTimesFrom(stellarData.tomorrow, moment().add(1, "days").format("YYYY-MM-DD")) : undefined;

weather.date = moment(forecast.time);
weather.windSpeed = forecast.data.instant.details.wind_speed;
Expand All @@ -377,10 +374,8 @@ WeatherProvider.register("yr", {
weather.precipitationProbability = forecast.precipitationProbability;
weather.precipitationUnits = units.precipitation_amount;

if (stellarTimesToday) {
weather.sunset = moment(stellarTimesToday.sunset.time);
weather.sunrise = weather.sunset < moment() && stellarTimesTomorrow ? moment(stellarTimesTomorrow.sunrise.time) : moment(stellarTimesToday.sunrise.time);
}
weather.sunrise = stellarData?.today?.properties?.sunrise?.time;
weather.sunset = stellarData?.today?.properties?.sunset?.time;

return weather;
},
Expand Down
2 changes: 1 addition & 1 deletion modules/default/weather/weather.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Module.register("weather", {

// Return the scripts that are necessary for the weather module.
getScripts: function () {
return ["moment.js", this.file("../utils.js"), "weatherutils.js", "weatherobject.js", this.file("providers/overrideWrapper.js"), "weatherprovider.js", "suncalc.js", this.file(`providers/${this.config.weatherProvider.toLowerCase()}.js`)];
return ["moment.js", "weatherutils.js", "weatherobject.js", this.file("providers/overrideWrapper.js"), "weatherprovider.js", "suncalc.js", this.file(`providers/${this.config.weatherProvider.toLowerCase()}.js`)];
},

// Override getHeader method.
Expand Down
7 changes: 7 additions & 0 deletions translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,16 @@

"FEELS": "Ressenti {DEGREE}",
"PRECIP_POP": "Probabilité de précipitations",
"PRECIP_AMOUNT": "Quantité des précipitations",

"MODULE_CONFIG_CHANGED": "Les options de configuration du module {MODULE_NAME} ont changé.\nVeuillez consulter la documentation.",
"MODULE_CONFIG_ERROR": "Erreur dans le module {MODULE_NAME}. {ERROR}",
"MODULE_ERROR_MALFORMED_URL": "URL mal formée.",
"MODULE_ERROR_NO_CONNECTION": "Pas de connexion Internet.",
"MODULE_ERROR_UNAUTHORIZED": "L'autorisation à échouée.",
"MODULE_ERROR_UNSPECIFIED": "Consultez les journaux pour plus de détails.",

"NEWSFEED_NO_ITEMS": "Aucune nouvelle pour le moment.",

"UPDATE_NOTIFICATION": "Une mise à jour de MagicMirror² est disponible",
"UPDATE_NOTIFICATION_MODULE": "Une mise à jour est disponible pour le module {MODULE_NAME}.",
Expand Down

0 comments on commit 4ee6318

Please sign in to comment.