Fix suggestions

This commit is contained in:
MrTimscampi 2020-08-01 16:04:24 +02:00
parent 4cd83e6f73
commit 57fb43fb04
3 changed files with 32 additions and 20 deletions

View File

@ -11,13 +11,17 @@ import pluginManager from 'pluginManager';
var manifestUrls = JSON.parse(appSettings.get(this.#settingsKey) || '[]'); var manifestUrls = JSON.parse(appSettings.get(this.#settingsKey) || '[]');
var instance = this; var instance = this;
return Promise.all(manifestUrls.map((u) => { return Promise.all(manifestUrls.map((url) => {
return this.loadPackage(instance, u); return this.loadPackage(url);
})).then(() => { }))
.then(() => {
console.debug('finished loading packages');
return Promise.resolve();
})
.catch(() => {
return Promise.resolve();
}).finally(() => {
console.groupEnd('loading packages'); console.groupEnd('loading packages');
return Promise.resolve();
}, () => {
return Promise.resolve();
}); });
} }
@ -26,7 +30,7 @@ import pluginManager from 'pluginManager';
} }
install(url) { 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) || '[]'); var manifestUrls = JSON.parse(appSettings.get(this.#settingsKey) || '[]');
if (!manifestUrls.includes(url)) { if (!manifestUrls.includes(url)) {
@ -69,12 +73,12 @@ import pluginManager from 'pluginManager';
return packageUrl; return packageUrl;
} }
addPackage(packageManager, pkg) { addPackage(pkg) {
packageManager.packagesList = packageManager.packagesList.filter((p) => { this.packagesList = this.packagesList.filter((p) => {
return p.name !== pkg.name; return p.name !== pkg.name;
}); });
packageManager.packagesList.push(pkg); this.packagesList.push(pkg);
} }
removeUrl(url) { removeUrl(url) {
@ -87,7 +91,7 @@ import pluginManager from 'pluginManager';
appSettings.set(this.#settingsKey, JSON.stringify(manifestUrls)); appSettings.set(this.#settingsKey, JSON.stringify(manifestUrls));
} }
loadPackage(packageManager, url, throwError) { loadPackage(url, throwError = false) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
var originalUrl = url; var originalUrl = url;
@ -105,19 +109,19 @@ import pluginManager from 'pluginManager';
} }
}; };
xhr.onload = (e) => { xhr.onload = () => {
if (this.status < 400) { if (this.status < 400) {
var pkg = JSON.parse(this.response); var pkg = JSON.parse(this.response);
pkg.url = originalUrl; pkg.url = originalUrl;
this.addPackage(packageManager, pkg); this.addPackage(pkg);
var plugins = pkg.plugins || []; var plugins = pkg.plugins || [];
if (pkg.plugin) { if (pkg.plugin) {
plugins.push(pkg.plugin); plugins.push(pkg.plugin);
} }
var promises = plugins.map((pluginUrl) => { 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); Promise.all(promises).then(resolve, resolve);
} else { } else {

View File

@ -2,6 +2,7 @@ define(["events", "playbackManager", "pluginManager", "inputManager", "connectio
"use strict"; "use strict";
playbackManager = playbackManager.default || playbackManager; playbackManager = playbackManager.default || playbackManager;
pluginManager = pluginManager.default || pluginManager;
function getMinIdleTime() { function getMinIdleTime() {
// Returns the minimum amount of idle time required before the screen saver can be displayed // Returns the minimum amount of idle time required before the screen saver can be displayed

View File

@ -470,6 +470,7 @@ function initClient() {
require(['apphost', 'css!assets/css/librarybrowser'], function (appHost) { require(['apphost', 'css!assets/css/librarybrowser'], function (appHost) {
loadPlugins(appHost, browser).then(function () { loadPlugins(appHost, browser).then(function () {
console.groupEnd('loading packages');
onAppReady(browser); onAppReady(browser);
}); });
}); });
@ -494,12 +495,18 @@ function initClient() {
list = list.concat(window.NativeShell.getPlugins()); list = list.concat(window.NativeShell.getPlugins());
} }
Promise.all(list.map(loadPlugin)).then(function () { Promise.all(list.map(loadPlugin))
console.groupEnd('loading installed plugins'); .then(function () {
require(['packageManager'], function (packageManager) { console.debug('finished loading plugins');
packageManager.default.init().then(resolve, reject); })
}); .catch(() => reject)
}, reject); .finally(() => {
console.groupEnd('loading installed plugins');
require(['packageManager'], function (packageManager) {
packageManager.default.init().then(resolve, reject);
});
})
;
}); });
}); });
}); });