From 6887d63cca94fafe69e3de15933b03aedc8bde26 Mon Sep 17 00:00:00 2001 From: Maxr1998 Date: Sun, 6 Dec 2020 11:09:29 +0100 Subject: [PATCH 1/3] Revert "Support plugins as classes" This reverts commit 2dede415df2558c9be4baa48260a69cc10dea8e5. --- src/components/pluginManager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/pluginManager.js b/src/components/pluginManager.js index 6c48b7ef7..9fe44ab43 100644 --- a/src/components/pluginManager.js +++ b/src/components/pluginManager.js @@ -77,7 +77,7 @@ import { playbackManager } from './playback/playbackmanager'; let pluginInstance = await window[pluginSpec]; if (typeof pluginInstance === 'function') { - pluginInstance = await new pluginInstance(); + pluginInstance = await pluginInstance(); } // init plugin and pass basic dependencies From a7fb8ebdd69f324ec4d89b6e7049b5dec50f970f Mon Sep 17 00:00:00 2001 From: Maxr1998 Date: Wed, 9 Dec 2020 11:53:00 +0100 Subject: [PATCH 2/3] Refactor loadPlugin code --- src/components/pluginManager.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/components/pluginManager.js b/src/components/pluginManager.js index 9fe44ab43..5c8ffa134 100644 --- a/src/components/pluginManager.js +++ b/src/components/pluginManager.js @@ -74,14 +74,23 @@ import { playbackManager } from './playback/playbackmanager'; if (typeof pluginSpec === 'string') { if (pluginSpec in window) { console.log(`Loading plugin (via window): ${pluginSpec}`); - let pluginInstance = await window[pluginSpec]; - if (typeof pluginInstance === 'function') { - pluginInstance = await pluginInstance(); + const pluginDefinition = await window[pluginSpec]; + if (typeof pluginDefinition !== 'function') { + const err = new TypeError('Plugin definitions in window have to be an (async) function returning the plugin class'); + console.error(err); + throw err; + } + + const pluginClass = await pluginDefinition(); + if (typeof pluginClass !== 'function') { + const err = new TypeError(`Plugin definition doesn't return a class for '${pluginSpec}'`); + console.error(err); + throw err; } // init plugin and pass basic dependencies - plugin = new pluginInstance({ + plugin = new pluginClass({ events: Events, loading, appSettings, From 224f3ab8cd14ea856bdc7245eff9606884408c8c Mon Sep 17 00:00:00 2001 From: Maxr1998 Date: Wed, 9 Dec 2020 20:23:34 +0100 Subject: [PATCH 3/3] Remove unnecessary duplicate error logging --- src/components/pluginManager.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/components/pluginManager.js b/src/components/pluginManager.js index 5c8ffa134..985b76725 100644 --- a/src/components/pluginManager.js +++ b/src/components/pluginManager.js @@ -77,16 +77,12 @@ import { playbackManager } from './playback/playbackmanager'; const pluginDefinition = await window[pluginSpec]; if (typeof pluginDefinition !== 'function') { - const err = new TypeError('Plugin definitions in window have to be an (async) function returning the plugin class'); - console.error(err); - throw err; + throw new TypeError('Plugin definitions in window have to be an (async) function returning the plugin class'); } const pluginClass = await pluginDefinition(); if (typeof pluginClass !== 'function') { - const err = new TypeError(`Plugin definition doesn't return a class for '${pluginSpec}'`); - console.error(err); - throw err; + throw new TypeError(`Plugin definition doesn't return a class for '${pluginSpec}'`); } // init plugin and pass basic dependencies @@ -107,9 +103,7 @@ import { playbackManager } from './playback/playbackmanager'; const pluginResult = await pluginSpec; plugin = new pluginResult.default; } else { - const err = new TypeError('Plugins have to be a Promise that resolves to a plugin builder function'); - console.error(err); - throw err; + throw new TypeError('Plugins have to be a Promise that resolves to a plugin builder function'); } return this.#preparePlugin(pluginSpec, plugin);