From a7fb8ebdd69f324ec4d89b6e7049b5dec50f970f Mon Sep 17 00:00:00 2001 From: Maxr1998 Date: Wed, 9 Dec 2020 11:53:00 +0100 Subject: [PATCH] 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,