From 23245790579ab2b11081f835821cbf173258db3d Mon Sep 17 00:00:00 2001 From: Felix Wiedenbach Date: Thu, 28 Jan 2021 07:33:02 +0100 Subject: [PATCH 1/8] add error to module show callback --- js/main.js | 5 +++-- js/module.js | 8 +++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/js/main.js b/js/main.js index b7138d99..a27e8cca 100644 --- a/js/main.js +++ b/js/main.js @@ -295,6 +295,7 @@ var MM = (function () { // Otherwise cancel show action. if (module.lockStrings.length !== 0 && options.force !== true) { Log.log("Will not show " + module.name + ". LockStrings active: " + module.lockStrings.join(",")); + callback("Active lock strings"); return; } @@ -321,13 +322,13 @@ var MM = (function () { clearTimeout(module.showHideTimer); module.showHideTimer = setTimeout(function () { if (typeof callback === "function") { - callback(); + callback(null); } }, speed); } else { // invoke callback if (typeof callback === "function") { - callback(); + callback(null); } } }; diff --git a/js/module.js b/js/module.js index 14458f8a..bc6a925d 100644 --- a/js/module.js +++ b/js/module.js @@ -432,9 +432,11 @@ var Module = Class.extend({ MM.showModule( this, speed, - function () { - self.resume(); - callback(); + function (error) { + if (!error) { + self.resume(); + } + callback(error); }, options ); From afbdacf136a79fe15fa87859cae31f0ef8c2b735 Mon Sep 17 00:00:00 2001 From: Felix Wiedenbach Date: Thu, 28 Jan 2021 07:46:23 +0100 Subject: [PATCH 2/8] updated changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ee2ca4e..e2025135 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ _This release is scheduled to be released on 2021-04-01._ - Converted newsfeed module to use templates. - Update documentation and help screen about invalid config files. - Moving weather provider specific code and configuration into each provider and making hourly part of the interface. +- Callback for `module.show` also gets triggered if lock strings are active but then contains an error `callback(error)`. ### Removed From d2a7a3b0bb7448f0f27dcb417a3757d4ae427f2a Mon Sep 17 00:00:00 2001 From: Felix Wiedenbach Date: Thu, 28 Jan 2021 21:13:17 +0100 Subject: [PATCH 3/8] more error like message --- js/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/main.js b/js/main.js index a27e8cca..69cae7a2 100644 --- a/js/main.js +++ b/js/main.js @@ -295,7 +295,7 @@ var MM = (function () { // Otherwise cancel show action. if (module.lockStrings.length !== 0 && options.force !== true) { Log.log("Will not show " + module.name + ". LockStrings active: " + module.lockStrings.join(",")); - callback("Active lock strings"); + callback("ERR_ACTIVE_LOCK_STRINGS"); return; } From 41da6f455ab296740c521a1960cb777a92362bb7 Mon Sep 17 00:00:00 2001 From: Felix Wiedenbach Date: Thu, 28 Jan 2021 21:23:48 +0100 Subject: [PATCH 4/8] use error object for callback to include stack trace --- js/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/main.js b/js/main.js index 69cae7a2..d96d0ceb 100644 --- a/js/main.js +++ b/js/main.js @@ -295,7 +295,7 @@ var MM = (function () { // Otherwise cancel show action. if (module.lockStrings.length !== 0 && options.force !== true) { Log.log("Will not show " + module.name + ". LockStrings active: " + module.lockStrings.join(",")); - callback("ERR_ACTIVE_LOCK_STRINGS"); + callback(new Error("ERR_ACTIVE_LOCK_STRINGS")); return; } From 88ed5ed373c5e3505f39ff39a979c0920620ce32 Mon Sep 17 00:00:00 2001 From: Felix Wiedenbach Date: Sat, 6 Feb 2021 21:22:13 +0100 Subject: [PATCH 5/8] add error separate callback --- js/main.js | 16 ++++++++++------ js/module.js | 14 +++++++------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/js/main.js b/js/main.js index f9848aa8..082f2114 100644 --- a/js/main.js +++ b/js/main.js @@ -279,8 +279,9 @@ var MM = (function () { * @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. + * @param {Function} errorCallback Called when the module failed to show. */ - var showModule = function (module, speed, callback, options) { + var showModule = function (module, speed, callback, errorCallback, options) { options = options || {}; // remove lockString if set in options. @@ -295,7 +296,9 @@ var MM = (function () { // Otherwise cancel show action. if (module.lockStrings.length !== 0 && options.force !== true) { Log.log("Will not show " + module.name + ". LockStrings active: " + module.lockStrings.join(",")); - callback(new Error("ERR_ACTIVE_LOCK_STRINGS")); + if (typeof errorCallback === "function") { + errorCallback(new Error("ERR_ACTIVE_LOCK_STRINGS")); + } return; } @@ -322,13 +325,13 @@ var MM = (function () { clearTimeout(module.showHideTimer); module.showHideTimer = setTimeout(function () { if (typeof callback === "function") { - callback(null); + callback(); } }, speed); } else { // invoke callback if (typeof callback === "function") { - callback(null); + callback(); } } }; @@ -587,10 +590,11 @@ var MM = (function () { * @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. + * @param {Function} errorCallback Called when the module failed to show. */ - showModule: function (module, speed, callback, options) { + showModule: function (module, speed, callback, errorCallback, options) { // do not change module.hidden yet, only if we really show it later - showModule(module, speed, callback, options); + showModule(module, speed, callback, errorCallback, options); } }; })(); diff --git a/js/module.js b/js/module.js index a110d74e..976a7cab 100644 --- a/js/module.js +++ b/js/module.js @@ -416,8 +416,9 @@ var Module = Class.extend({ * @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. + * @param {Function} errorCallback Called when the module failed to show. */ - show: function (speed, callback, options) { + show: function (speed, callback, options, errorCallback) { if (typeof callback === "object") { options = callback; callback = function () {}; @@ -425,17 +426,16 @@ var Module = Class.extend({ callback = callback || function () {}; options = options || {}; + errorCallback = errorCallback || function () {}; - var self = this; MM.showModule( this, speed, - function (error) { - if (!error) { - self.resume(); - } - callback(error); + () => { + this.resume(); + callback(); }, + errorCallback, options ); } From 1ed721fb15331a35fd9f4c0e58bdf58c9167e857 Mon Sep 17 00:00:00 2001 From: Felix Wiedenbach Date: Sat, 6 Feb 2021 21:32:57 +0100 Subject: [PATCH 6/8] updated changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 798fdf3a..f15d4823 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ _This release is scheduled to be released on 2021-04-01._ - Added `start:dev` command to the npm scripts for starting electron with devTools open. - Added logging when using deprecated modules weatherforecast or currentweather. - Portuguese translations for "MODULE_CONFIG_CHANGED" and PRECIP. +- `module.show` has now the option for a callback on error. ### Updated @@ -29,7 +30,6 @@ _This release is scheduled to be released on 2021-04-01._ - Moving weather provider specific code and configuration into each provider and making hourly part of the interface. - Bump electron to v11. - Dont update the DOM when a module is not displayed. -- Callback for `module.show` also gets triggered if lock strings are active but then contains an error `callback(error)`. ### Removed From 9d85baee37c2d2eb7e8eda5eb64bb967b9d70a37 Mon Sep 17 00:00:00 2001 From: Felix Wiedenbach Date: Sat, 13 Feb 2021 08:29:13 +0100 Subject: [PATCH 7/8] move error callback into options and rename it --- js/main.js | 12 +++++------- js/module.js | 5 +---- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/js/main.js b/js/main.js index 082f2114..f836e78b 100644 --- a/js/main.js +++ b/js/main.js @@ -279,9 +279,8 @@ var MM = (function () { * @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. - * @param {Function} errorCallback Called when the module failed to show. */ - var showModule = function (module, speed, callback, errorCallback, options) { + var showModule = function (module, speed, callback, options) { options = options || {}; // remove lockString if set in options. @@ -296,8 +295,8 @@ var MM = (function () { // Otherwise cancel show action. if (module.lockStrings.length !== 0 && options.force !== true) { Log.log("Will not show " + module.name + ". LockStrings active: " + module.lockStrings.join(",")); - if (typeof errorCallback === "function") { - errorCallback(new Error("ERR_ACTIVE_LOCK_STRINGS")); + if (typeof options.onError === "function") { + options.onError(new Error("ERR_ACTIVE_LOCK_STRINGS")); } return; } @@ -590,11 +589,10 @@ var MM = (function () { * @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. - * @param {Function} errorCallback Called when the module failed to show. */ - showModule: function (module, speed, callback, errorCallback, options) { + showModule: function (module, speed, callback, options) { // do not change module.hidden yet, only if we really show it later - showModule(module, speed, callback, errorCallback, options); + showModule(module, speed, callback, options); } }; })(); diff --git a/js/module.js b/js/module.js index 976a7cab..2e2c94a9 100644 --- a/js/module.js +++ b/js/module.js @@ -416,9 +416,8 @@ var Module = Class.extend({ * @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. - * @param {Function} errorCallback Called when the module failed to show. */ - show: function (speed, callback, options, errorCallback) { + show: function (speed, callback, options) { if (typeof callback === "object") { options = callback; callback = function () {}; @@ -426,7 +425,6 @@ var Module = Class.extend({ callback = callback || function () {}; options = options || {}; - errorCallback = errorCallback || function () {}; MM.showModule( this, @@ -435,7 +433,6 @@ var Module = Class.extend({ this.resume(); callback(); }, - errorCallback, options ); } From b2a21b937d577b0fcc4f2dbebdbc9122d8f9790e Mon Sep 17 00:00:00 2001 From: Michael Teeuw Date: Tue, 23 Feb 2021 14:11:54 +0100 Subject: [PATCH 8/8] Change error string. --- js/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/main.js b/js/main.js index d8b735bb..6f5d9484 100644 --- a/js/main.js +++ b/js/main.js @@ -296,7 +296,7 @@ var MM = (function () { if (module.lockStrings.length !== 0 && options.force !== true) { Log.log("Will not show " + module.name + ". LockStrings active: " + module.lockStrings.join(",")); if (typeof options.onError === "function") { - options.onError(new Error("ERR_ACTIVE_LOCK_STRINGS")); + options.onError(new Error("LOCK_STRING_ACTIVE")); } return; }