diff --git a/src/components/packageManager.js b/src/components/packageManager.js index 7e2b1362c7..358529ba79 100644 --- a/src/components/packageManager.js +++ b/src/components/packageManager.js @@ -11,13 +11,17 @@ import pluginManager from 'pluginManager'; var manifestUrls = JSON.parse(appSettings.get(this.#settingsKey) || '[]'); var instance = this; - return Promise.all(manifestUrls.map((u) => { - return this.loadPackage(instance, u); - })).then(() => { + return Promise.all(manifestUrls.map((url) => { + return this.loadPackage(url); + })) + .then(() => { + console.debug('finished loading packages'); + return Promise.resolve(); + }) + .catch(() => { + return Promise.resolve(); + }).finally(() => { console.groupEnd('loading packages'); - return Promise.resolve(); - }, () => { - return Promise.resolve(); }); } @@ -26,7 +30,7 @@ import pluginManager from 'pluginManager'; } install(url) { - return this.loadPackage(this, url, true).then((pkg) => { + return this.loadPackage(url, true).then((pkg) => { var manifestUrls = JSON.parse(appSettings.get(this.#settingsKey) || '[]'); if (!manifestUrls.includes(url)) { @@ -69,12 +73,12 @@ import pluginManager from 'pluginManager'; return packageUrl; } - addPackage(packageManager, pkg) { - packageManager.packagesList = packageManager.packagesList.filter((p) => { + addPackage(pkg) { + this.packagesList = this.packagesList.filter((p) => { return p.name !== pkg.name; }); - packageManager.packagesList.push(pkg); + this.packagesList.push(pkg); } removeUrl(url) { @@ -87,7 +91,7 @@ import pluginManager from 'pluginManager'; appSettings.set(this.#settingsKey, JSON.stringify(manifestUrls)); } - loadPackage(packageManager, url, throwError) { + loadPackage(url, throwError = false) { return new Promise((resolve, reject) => { var xhr = new XMLHttpRequest(); var originalUrl = url; @@ -105,19 +109,19 @@ import pluginManager from 'pluginManager'; } }; - xhr.onload = (e) => { + xhr.onload = () => { if (this.status < 400) { var pkg = JSON.parse(this.response); pkg.url = originalUrl; - this.addPackage(packageManager, pkg); + this.addPackage(pkg); var plugins = pkg.plugins || []; if (pkg.plugin) { plugins.push(pkg.plugin); } var promises = plugins.map((pluginUrl) => { - return pluginManager.loadPlugin(packageManager.mapPath(pkg, pluginUrl)); + return pluginManager.loadPlugin(this.mapPath(pkg, pluginUrl)); }); Promise.all(promises).then(resolve, resolve); } else { diff --git a/src/libraries/screensavermanager.js b/src/libraries/screensavermanager.js index 557b31e0f4..6d025ac67f 100644 --- a/src/libraries/screensavermanager.js +++ b/src/libraries/screensavermanager.js @@ -2,6 +2,7 @@ define(["events", "playbackManager", "pluginManager", "inputManager", "connectio "use strict"; playbackManager = playbackManager.default || playbackManager; + pluginManager = pluginManager.default || pluginManager; function getMinIdleTime() { // Returns the minimum amount of idle time required before the screen saver can be displayed diff --git a/src/scripts/site.js b/src/scripts/site.js index 7b5a72c042..7919ed510f 100644 --- a/src/scripts/site.js +++ b/src/scripts/site.js @@ -470,6 +470,7 @@ function initClient() { require(['apphost', 'css!assets/css/librarybrowser'], function (appHost) { loadPlugins(appHost, browser).then(function () { + console.groupEnd('loading packages'); onAppReady(browser); }); }); @@ -494,12 +495,18 @@ function initClient() { list = list.concat(window.NativeShell.getPlugins()); } - Promise.all(list.map(loadPlugin)).then(function () { - console.groupEnd('loading installed plugins'); - require(['packageManager'], function (packageManager) { - packageManager.default.init().then(resolve, reject); - }); - }, reject); + Promise.all(list.map(loadPlugin)) + .then(function () { + console.debug('finished loading plugins'); + }) + .catch(() => reject) + .finally(() => { + console.groupEnd('loading installed plugins'); + require(['packageManager'], function (packageManager) { + packageManager.default.init().then(resolve, reject); + }); + }) + ; }); }); });