1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Merge pull request #2186 from Maxr1998/fix-plugin-loader

Fix plugin loader for function definitions in window

(cherry picked from commit 3992265189)
Signed-off-by: Joshua M. Boniface <joshua@boniface.me>
This commit is contained in:
Bill Thornton 2020-12-09 14:27:50 -05:00 committed by Joshua M. Boniface
parent 972ecc4106
commit 5f63743ed0

View file

@ -74,14 +74,19 @@ 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 new pluginInstance();
const pluginDefinition = await window[pluginSpec];
if (typeof pluginDefinition !== 'function') {
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') {
throw new TypeError(`Plugin definition doesn't return a class for '${pluginSpec}'`);
}
// init plugin and pass basic dependencies
plugin = new pluginInstance({
plugin = new pluginClass({
events: Events,
loading,
appSettings,
@ -98,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);