From 6647160df743dd83b4152b780a77e6f30d57be67 Mon Sep 17 00:00:00 2001 From: bugsounet Date: Fri, 10 May 2024 14:27:08 +0200 Subject: [PATCH 01/10] check module.module --- CHANGELOG.md | 2 ++ js/app.js | 6 ++++-- js/loader.js | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfa896f6dc..6347c7812e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ _This release is scheduled to be released on 2024-07-01._ ### Fixed +- Fix crash possibility if `module: ` is not defined + ## [2.27.0] - 2024-04-01 Thanks to: @bugsounet, @crazyscot, @illimarkangur, @jkriegshauser, @khassel, @KristjanESPERANTO, @Paranoid93, @rejas, @sdetweil and @vppencilsharpener. diff --git a/js/app.js b/js/app.js index 77d0dc206f..aeda37cc8e 100644 --- a/js/app.js +++ b/js/app.js @@ -253,8 +253,10 @@ function App () { let modules = []; for (const module of config.modules) { - if (!modules.includes(module.module) && !module.disabled) { - modules.push(module.module); + if (module.module) { + if (!module.disabled) modules.push(module.module); + } else { + Log.warn("No module name found for this configuration:", module); } } diff --git a/js/loader.js b/js/loader.js index 0d59858c77..70cef49f18 100644 --- a/js/loader.js +++ b/js/loader.js @@ -50,7 +50,8 @@ const Loader = (function () { * @returns {object[]} module data as configured in config */ const getAllModules = function () { - return config.modules; + const AllModules = config.modules.filter(module => module.module !== undefined); + return AllModules; }; /** From 455ac2412acad1f67b00ab7a2ec46665e553fc79 Mon Sep 17 00:00:00 2001 From: bugsounet Date: Fri, 10 May 2024 21:18:45 +0200 Subject: [PATCH 02/10] fix lint --- js/loader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/loader.js b/js/loader.js index 70cef49f18..4e5d207939 100644 --- a/js/loader.js +++ b/js/loader.js @@ -50,7 +50,7 @@ const Loader = (function () { * @returns {object[]} module data as configured in config */ const getAllModules = function () { - const AllModules = config.modules.filter(module => module.module !== undefined); + const AllModules = config.modules.filter((module) => module.module !== undefined); return AllModules; }; From 90abd39db4b555d285800d384b9f1a311786a499 Mon Sep 17 00:00:00 2001 From: bugsounet Date: Fri, 17 May 2024 19:04:42 +0200 Subject: [PATCH 03/10] check module position --- js/app.js | 10 ++++++++-- js/loader.js | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/js/app.js b/js/app.js index aeda37cc8e..31114c3570 100644 --- a/js/app.js +++ b/js/app.js @@ -251,10 +251,16 @@ function App () { Log.setLogLevel(config.logLevel); + 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"]; + let modules = []; for (const module of config.modules) { - if (module.module) { - if (!module.disabled) modules.push(module.module); + if (module.module && !module.disabled) { + if (positions.indexOf(module.position) > -1 || typeof (module.position) === "undefined") { + modules.push(module.module); + } else { + Log.warn("Invalid module position found for this configuration:", module); + } } else { Log.warn("No module name found for this configuration:", module); } diff --git a/js/loader.js b/js/loader.js index 4e5d207939..0a4fc39566 100644 --- a/js/loader.js +++ b/js/loader.js @@ -7,6 +7,7 @@ const Loader = (function () { const loadedModuleFiles = []; const loadedFiles = []; const moduleObjects = []; + 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"]; /* Private Methods */ @@ -50,7 +51,7 @@ const Loader = (function () { * @returns {object[]} module data as configured in config */ const getAllModules = function () { - const AllModules = config.modules.filter((module) => module.module !== undefined); + const AllModules = config.modules.filter((module) => (module.module !== undefined) && (positions.indexOf(module.position) > -1 || typeof (module.position) === "undefined")); return AllModules; }; From c428128bb871245b9a5c744c02cbad3e83771d89 Mon Sep 17 00:00:00 2001 From: bugsounet Date: Sat, 18 May 2024 13:43:30 +0200 Subject: [PATCH 04/10] test with ajv --- js/check_config.js | 66 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/js/check_config.js b/js/check_config.js index ec5ebcae66..6a514de3eb 100644 --- a/js/check_config.js +++ b/js/check_config.js @@ -5,6 +5,10 @@ const { Linter } = require("eslint"); const linter = new Linter(); +const Ajv = require("ajv"); + +const ajv = new Ajv(); + const rootPath = path.resolve(`${__dirname}/../`); const Log = require(`${rootPath}/js/logger.js`); @@ -59,6 +63,68 @@ function checkConfigFile () { for (const error of errors) { Log.error(`Line ${error.line} column ${error.column}: ${error.message}`); } + return; + } + + Log.info("Checking modules structure configuration... "); + + // Make Ajv schema confguration of modules config + // only scan "module" and "position" + const schema = { + type: "object", + properties: { + modules: { + type: "array", + items: { + type: "object", + properties: { + module: { + type: "string" + }, + position: { + type: "string", + enum: [ + "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" + ] + } + }, + required: ["module"] + } + } + } + }; + + // scan all modules + const validate = ajv.compile(schema); + const data = require(configFileName); + + const valid = validate(data); + if (!valid) { + let module = validate.errors[0].instancePath.split("/")[2]; + let position = validate.errors[0].instancePath.split("/")[3]; + + Log.error(colors.red("This module configuration contains errors:")); + Log.error(data.modules[module]); + if (position) { + Log.error(colors.red(`${position}: ${validate.errors[0].message}`)); + Log.error(validate.errors[0].params.allowedValues); + } else { + Log.error(colors.red(validate.errors[0].message)); + } + } else { + Log.info(colors.green("Your modules structure configuration doesn't contain errors :)")); } } From c427163bdee12149e2709b50d569662c0c777b5d Mon Sep 17 00:00:00 2001 From: bugsounet Date: Sat, 18 May 2024 14:03:23 +0200 Subject: [PATCH 05/10] try to add new ajv --- package-lock.json | 84 ++++++++++++++++++++++++++++------------------- package.json | 1 + 2 files changed, 52 insertions(+), 33 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9be0e71cf5..df2a863d8f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "hasInstallScript": true, "license": "MIT", "dependencies": { + "ajv": "^8.13.0", "ansis": "^3.2.0", "console-stamp": "^3.1.2", "envsub": "^4.1.0", @@ -842,6 +843,21 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/@eslint/eslintrc/node_modules/ajv": { + "version": "6.12.6", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", + "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "dependencies": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, "node_modules/@eslint/eslintrc/node_modules/brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -851,6 +867,11 @@ "concat-map": "0.0.1" } }, + "node_modules/@eslint/eslintrc/node_modules/json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==" + }, "node_modules/@eslint/eslintrc/node_modules/minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", @@ -2236,14 +2257,14 @@ } }, "node_modules/ajv": { - "version": "6.12.6", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", - "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "version": "8.13.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.13.0.tgz", + "integrity": "sha512-PRA911Blj99jR5RMeTunVbNXMF6Lp4vZXnk5GQjcnUWUTsrXtekg/pnmFFI2u/I36Y/2bITGS30GZCXei6uNkA==", "dependencies": { - "fast-deep-equal": "^3.1.1", - "fast-json-stable-stringify": "^2.0.0", - "json-schema-traverse": "^0.4.1", - "uri-js": "^4.2.2" + "fast-deep-equal": "^3.1.3", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2", + "uri-js": "^4.4.1" }, "funding": { "type": "github", @@ -4555,6 +4576,21 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/eslint/node_modules/ajv": { + "version": "6.12.6", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", + "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "dependencies": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, "node_modules/eslint/node_modules/brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -4564,6 +4600,11 @@ "concat-map": "0.0.1" } }, + "node_modules/eslint/node_modules/json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==" + }, "node_modules/eslint/node_modules/minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", @@ -6990,9 +7031,9 @@ "dev": true }, "node_modules/json-schema-traverse": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", - "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==" + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==" }, "node_modules/json-stable-stringify-without-jsonify": { "version": "1.0.1", @@ -9211,7 +9252,6 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", - "dev": true, "engines": { "node": ">=0.10.0" } @@ -10557,22 +10597,6 @@ "node": ">=10.0.0" } }, - "node_modules/table/node_modules/ajv": { - "version": "8.13.0", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.13.0.tgz", - "integrity": "sha512-PRA911Blj99jR5RMeTunVbNXMF6Lp4vZXnk5GQjcnUWUTsrXtekg/pnmFFI2u/I36Y/2bITGS30GZCXei6uNkA==", - "dev": true, - "dependencies": { - "fast-deep-equal": "^3.1.3", - "json-schema-traverse": "^1.0.0", - "require-from-string": "^2.0.2", - "uri-js": "^4.4.1" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/epoberezkin" - } - }, "node_modules/table/node_modules/emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", @@ -10588,12 +10612,6 @@ "node": ">=8" } }, - "node_modules/table/node_modules/json-schema-traverse": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", - "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", - "dev": true - }, "node_modules/table/node_modules/slice-ansi": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-4.0.0.tgz", diff --git a/package.json b/package.json index da54181ef6..419b6c7757 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "*.css": "stylelint --fix" }, "dependencies": { + "ajv": "^8.13.0", "ansis": "^3.2.0", "console-stamp": "^3.1.2", "envsub": "^4.1.0", From e35ffdf9f402eab0a48156f7b6c455555127ff11 Mon Sep 17 00:00:00 2001 From: bugsounet Date: Sat, 8 Jun 2024 13:55:16 +0200 Subject: [PATCH 06/10] fix modules scan when disabled --- js/app.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/app.js b/js/app.js index 31114c3570..befa54aa2d 100644 --- a/js/app.js +++ b/js/app.js @@ -255,7 +255,8 @@ function App () { let modules = []; for (const module of config.modules) { - if (module.module && !module.disabled) { + if (module.disabled) continue; + if (module.module) { if (positions.indexOf(module.position) > -1 || typeof (module.position) === "undefined") { modules.push(module.module); } else { From c14daa35683f2ffcf16f163f2a68a840ec8e6b80 Mon Sep 17 00:00:00 2001 From: bugsounet Date: Tue, 11 Jun 2024 17:51:20 +0200 Subject: [PATCH 07/10] move const positions to getAllmodules function --- js/loader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/loader.js b/js/loader.js index 0a4fc39566..863e8f6709 100644 --- a/js/loader.js +++ b/js/loader.js @@ -7,7 +7,6 @@ const Loader = (function () { const loadedModuleFiles = []; const loadedFiles = []; const moduleObjects = []; - 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"]; /* Private Methods */ @@ -51,6 +50,7 @@ const Loader = (function () { * @returns {object[]} module data as configured in config */ const getAllModules = 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"]; const AllModules = config.modules.filter((module) => (module.module !== undefined) && (positions.indexOf(module.position) > -1 || typeof (module.position) === "undefined")); return AllModules; }; From a89819533f2c24a7cf76310db08f29db4d7ae9e3 Mon Sep 17 00:00:00 2001 From: bugsounet Date: Tue, 11 Jun 2024 18:03:48 +0200 Subject: [PATCH 08/10] bump ajv dep --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index df2a863d8f..9fab311fce 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "hasInstallScript": true, "license": "MIT", "dependencies": { - "ajv": "^8.13.0", + "ajv": "^8.16.0", "ansis": "^3.2.0", "console-stamp": "^3.1.2", "envsub": "^4.1.0", @@ -2257,9 +2257,9 @@ } }, "node_modules/ajv": { - "version": "8.13.0", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.13.0.tgz", - "integrity": "sha512-PRA911Blj99jR5RMeTunVbNXMF6Lp4vZXnk5GQjcnUWUTsrXtekg/pnmFFI2u/I36Y/2bITGS30GZCXei6uNkA==", + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.16.0.tgz", + "integrity": "sha512-F0twR8U1ZU67JIEtekUcLkXkoO5mMMmgGD8sK/xUFzJ805jxHQl92hImFAqqXMyMYjSPOyUPAwHYhB72g5sTXw==", "dependencies": { "fast-deep-equal": "^3.1.3", "json-schema-traverse": "^1.0.0", diff --git a/package.json b/package.json index 419b6c7757..de590cba7a 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "*.css": "stylelint --fix" }, "dependencies": { - "ajv": "^8.13.0", + "ajv": "^8.16.0", "ansis": "^3.2.0", "console-stamp": "^3.1.2", "envsub": "^4.1.0", From af55dce054ea572d2fd58b915bba057f64e87e0a Mon Sep 17 00:00:00 2001 From: bugsounet Date: Tue, 11 Jun 2024 18:35:04 +0200 Subject: [PATCH 09/10] package-lock update --- package-lock.json | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/package-lock.json b/package-lock.json index 81a8ca7be5..ad75ffc8a6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4476,6 +4476,22 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/eslint-plugin-unicorn/node_modules/ajv": { + "version": "6.12.6", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", + "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "dev": true, + "dependencies": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, "node_modules/eslint-plugin-unicorn/node_modules/brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -4527,6 +4543,12 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/eslint-plugin-unicorn/node_modules/json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true + }, "node_modules/eslint-plugin-unicorn/node_modules/minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", From 8c22587eea3df39636e2dde3db44ebf3f0c5d12e Mon Sep 17 00:00:00 2001 From: bugsounet Date: Sun, 23 Jun 2024 14:09:52 +0200 Subject: [PATCH 10/10] add MM.getAvailableModulePosition // add *position* function in Utils --- js/app.js | 4 +--- js/loader.js | 3 +-- js/main.js | 11 +++++++---- js/utils.js | 11 +++++++++++ 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/js/app.js b/js/app.js index befa54aa2d..f6e116d17d 100644 --- a/js/app.js +++ b/js/app.js @@ -251,13 +251,11 @@ function App () { Log.setLogLevel(config.logLevel); - 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"]; - let modules = []; for (const module of config.modules) { if (module.disabled) continue; if (module.module) { - if (positions.indexOf(module.position) > -1 || typeof (module.position) === "undefined") { + if (Utils.moduleHasValidPosition(module.position) || typeof (module.position) === "undefined") { modules.push(module.module); } else { Log.warn("Invalid module position found for this configuration:", module); diff --git a/js/loader.js b/js/loader.js index 863e8f6709..e8dff1907c 100644 --- a/js/loader.js +++ b/js/loader.js @@ -50,8 +50,7 @@ const Loader = (function () { * @returns {object[]} module data as configured in config */ const getAllModules = 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"]; - const AllModules = config.modules.filter((module) => (module.module !== undefined) && (positions.indexOf(module.position) > -1 || typeof (module.position) === "undefined")); + const AllModules = config.modules.filter((module) => (module.module !== undefined) && (MM.getAvailableModulePositions.indexOf(module.position) > -1 || typeof (module.position) === "undefined")); return AllModules; }; diff --git a/js/main.js b/js/main.js index 43ec02ad87..bc69f0bb93 100644 --- a/js/main.js +++ b/js/main.js @@ -450,10 +450,10 @@ const MM = (function () { * an ugly top margin. By using this function, the top bar will be hidden if the * update notification is not visible. */ - 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"]; + const modulePositions = ["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"]; - positions.forEach(function (position) { + const updateWrapperStates = function () { + modulePositions.forEach(function (position) { const wrapper = selectWrapper(position); const moduleWrappers = wrapper.getElementsByClassName("module"); @@ -701,7 +701,10 @@ const MM = (function () { showModule (module, speed, callback, options) { // do not change module.hidden yet, only if we really show it later showModule(module, speed, callback, options); - } + }, + + // return all available module postions. + getAvailableModulePositions: modulePositions }; }()); diff --git a/js/utils.js b/js/utils.js index ba80004bb3..89784f6937 100644 --- a/js/utils.js +++ b/js/utils.js @@ -25,5 +25,16 @@ module.exports = { } catch (e) { Log.error(e); } + }, + + // return all available module positions + getAvailableModulePositions () { + return ["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"]; + }, + + // return if postion is on modulePositions Array (true/false) + moduleHasValidPosition (position) { + if (this.getAvailableModulePositions().indexOf(position) === -1) return false; + return true; } };