mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Merge pull request #1716 from MrTimscampi/pluginmanager-es6
Migrate PluginManager and PackageManager to ES6
This commit is contained in:
commit
e4a922ad60
9 changed files with 256 additions and 240 deletions
|
@ -40,13 +40,13 @@ module.exports = {
|
||||||
'no-multi-spaces': ['error'],
|
'no-multi-spaces': ['error'],
|
||||||
'no-multiple-empty-lines': ['error', { 'max': 1 }],
|
'no-multiple-empty-lines': ['error', { 'max': 1 }],
|
||||||
'no-trailing-spaces': ['error'],
|
'no-trailing-spaces': ['error'],
|
||||||
'no-unused-expressions': ['error', { 'allowShortCircuit': true, 'allowTernary': true, 'allowTaggedTemplates': true }],
|
'@babel/no-unused-expressions': ['error', { 'allowShortCircuit': true, 'allowTernary': true, 'allowTaggedTemplates': true }],
|
||||||
'no-unused-vars': ['error', { 'vars': 'all', 'args': 'none', 'ignoreRestSiblings': true }],
|
//'no-unused-vars': ['error', { 'vars': 'all', 'args': 'none', 'ignoreRestSiblings': true }],
|
||||||
'one-var': ['error', 'never'],
|
'one-var': ['error', 'never'],
|
||||||
'padded-blocks': ['error', 'never'],
|
'padded-blocks': ['error', 'never'],
|
||||||
//'prefer-const': ['error', {'destructuring': 'all'}],
|
//'prefer-const': ['error', {'destructuring': 'all'}],
|
||||||
'quotes': ['error', 'single', { 'avoidEscape': true, 'allowTemplateLiterals': false }],
|
'quotes': ['error', 'single', { 'avoidEscape': true, 'allowTemplateLiterals': false }],
|
||||||
'semi': ['error'],
|
'@babel/semi': ['error'],
|
||||||
'space-before-blocks': ['error'],
|
'space-before-blocks': ['error'],
|
||||||
'space-infix-ops': 'error',
|
'space-infix-ops': 'error',
|
||||||
'yoda': 'error'
|
'yoda': 'error'
|
||||||
|
@ -106,6 +106,7 @@ module.exports = {
|
||||||
// TODO: Fix warnings and remove these rules
|
// TODO: Fix warnings and remove these rules
|
||||||
'no-redeclare': ['off'],
|
'no-redeclare': ['off'],
|
||||||
'no-useless-escape': ['off'],
|
'no-useless-escape': ['off'],
|
||||||
|
'no-unused-vars': ['off'],
|
||||||
// TODO: Remove after ES6 migration is complete
|
// TODO: Remove after ES6 migration is complete
|
||||||
'import/no-unresolved': ['off']
|
'import/no-unresolved': ['off']
|
||||||
},
|
},
|
||||||
|
|
|
@ -145,6 +145,7 @@
|
||||||
"src/components/multiSelect/multiSelect.js",
|
"src/components/multiSelect/multiSelect.js",
|
||||||
"src/components/notifications/notifications.js",
|
"src/components/notifications/notifications.js",
|
||||||
"src/components/nowPlayingBar/nowPlayingBar.js",
|
"src/components/nowPlayingBar/nowPlayingBar.js",
|
||||||
|
"src/components/packageManager.js",
|
||||||
"src/components/playback/brightnessosd.js",
|
"src/components/playback/brightnessosd.js",
|
||||||
"src/components/playback/mediasession.js",
|
"src/components/playback/mediasession.js",
|
||||||
"src/components/playback/nowplayinghelper.js",
|
"src/components/playback/nowplayinghelper.js",
|
||||||
|
@ -160,6 +161,7 @@
|
||||||
"src/components/playerstats/playerstats.js",
|
"src/components/playerstats/playerstats.js",
|
||||||
"src/components/playlisteditor/playlisteditor.js",
|
"src/components/playlisteditor/playlisteditor.js",
|
||||||
"src/components/playmenu.js",
|
"src/components/playmenu.js",
|
||||||
|
"src/components/pluginManager.js",
|
||||||
"src/components/prompt/prompt.js",
|
"src/components/prompt/prompt.js",
|
||||||
"src/components/recordingcreator/recordingbutton.js",
|
"src/components/recordingcreator/recordingbutton.js",
|
||||||
"src/components/recordingcreator/recordingcreator.js",
|
"src/components/recordingcreator/recordingcreator.js",
|
||||||
|
|
|
@ -1117,7 +1117,7 @@ import 'programStyles';
|
||||||
function importRefreshIndicator() {
|
function importRefreshIndicator() {
|
||||||
if (!refreshIndicatorLoaded) {
|
if (!refreshIndicatorLoaded) {
|
||||||
refreshIndicatorLoaded = true;
|
refreshIndicatorLoaded = true;
|
||||||
/* eslint-disable-next-line no-unused-expressions */
|
/* eslint-disable-next-line @babel/no-unused-expressions */
|
||||||
import('emby-itemrefreshindicator');
|
import('emby-itemrefreshindicator');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1449,7 +1449,7 @@ import 'programStyles';
|
||||||
const userData = item.UserData || {};
|
const userData = item.UserData || {};
|
||||||
|
|
||||||
if (itemHelper.canMarkPlayed(item)) {
|
if (itemHelper.canMarkPlayed(item)) {
|
||||||
/* eslint-disable-next-line no-unused-expressions */
|
/* eslint-disable-next-line @babel/no-unused-expressions */
|
||||||
import('emby-playstatebutton');
|
import('emby-playstatebutton');
|
||||||
html += '<button is="emby-playstatebutton" type="button" data-action="none" class="' + btnCssClass + '" data-id="' + item.Id + '" data-serverid="' + item.ServerId + '" data-itemtype="' + item.Type + '" data-played="' + (userData.Played) + '"><span class="material-icons cardOverlayButtonIcon cardOverlayButtonIcon-hover check"></span></button>';
|
html += '<button is="emby-playstatebutton" type="button" data-action="none" class="' + btnCssClass + '" data-id="' + item.Id + '" data-serverid="' + item.ServerId + '" data-itemtype="' + item.Type + '" data-played="' + (userData.Played) + '"><span class="material-icons cardOverlayButtonIcon cardOverlayButtonIcon-hover check"></span></button>';
|
||||||
}
|
}
|
||||||
|
@ -1457,7 +1457,7 @@ import 'programStyles';
|
||||||
if (itemHelper.canRate(item)) {
|
if (itemHelper.canRate(item)) {
|
||||||
const likes = userData.Likes == null ? '' : userData.Likes;
|
const likes = userData.Likes == null ? '' : userData.Likes;
|
||||||
|
|
||||||
/* eslint-disable-next-line no-unused-expressions */
|
/* eslint-disable-next-line @babel/no-unused-expressions */
|
||||||
import('emby-ratingbutton');
|
import('emby-ratingbutton');
|
||||||
html += '<button is="emby-ratingbutton" type="button" data-action="none" class="' + btnCssClass + '" data-id="' + item.Id + '" data-serverid="' + item.ServerId + '" data-itemtype="' + item.Type + '" data-likes="' + likes + '" data-isfavorite="' + (userData.IsFavorite) + '"><span class="material-icons cardOverlayButtonIcon cardOverlayButtonIcon-hover favorite"></span></button>';
|
html += '<button is="emby-ratingbutton" type="button" data-action="none" class="' + btnCssClass + '" data-id="' + item.Id + '" data-serverid="' + item.ServerId + '" data-itemtype="' + item.Type + '" data-likes="' + likes + '" data-isfavorite="' + (userData.IsFavorite) + '"><span class="material-icons cardOverlayButtonIcon cardOverlayButtonIcon-hover favorite"></span></button>';
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +1,97 @@
|
||||||
define(['appSettings', 'pluginManager'], function (appSettings, pluginManager) {
|
import appSettings from 'appSettings';
|
||||||
'use strict';
|
import pluginManager from 'pluginManager';
|
||||||
|
/* eslint-disable indent */
|
||||||
|
|
||||||
var settingsKey = 'installedpackages1';
|
class PackageManager {
|
||||||
|
#packagesList = [];
|
||||||
|
#settingsKey = 'installedpackages1';
|
||||||
|
|
||||||
function addPackage(packageManager, pkg) {
|
init() {
|
||||||
packageManager.packagesList = packageManager.packagesList.filter(function (p) {
|
console.groupCollapsed('loading packages');
|
||||||
|
var manifestUrls = JSON.parse(appSettings.get(this.#settingsKey) || '[]');
|
||||||
|
|
||||||
|
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');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
get packages() {
|
||||||
|
return this.#packagesList.slice(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
install(url) {
|
||||||
|
return this.loadPackage(url, true).then((pkg) => {
|
||||||
|
var manifestUrls = JSON.parse(appSettings.get(this.#settingsKey) || '[]');
|
||||||
|
|
||||||
|
if (!manifestUrls.includes(url)) {
|
||||||
|
manifestUrls.push(url);
|
||||||
|
appSettings.set(this.#settingsKey, JSON.stringify(manifestUrls));
|
||||||
|
}
|
||||||
|
|
||||||
|
return pkg;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
uninstall(name) {
|
||||||
|
var pkg = this.#packagesList.filter((p) => {
|
||||||
|
return p.name === name;
|
||||||
|
})[0];
|
||||||
|
|
||||||
|
if (pkg) {
|
||||||
|
this.#packagesList = this.#packagesList.filter((p) => {
|
||||||
|
return p.name !== name;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.removeUrl(pkg.url);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
mapPath(pkg, pluginUrl) {
|
||||||
|
var urlLower = pluginUrl.toLowerCase();
|
||||||
|
if (urlLower.startsWith('http:') || urlLower.startsWith('https:') || urlLower.startsWith('file:')) {
|
||||||
|
return pluginUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
var packageUrl = pkg.url;
|
||||||
|
packageUrl = packageUrl.substring(0, packageUrl.lastIndexOf('/'));
|
||||||
|
|
||||||
|
packageUrl += '/';
|
||||||
|
packageUrl += pluginUrl;
|
||||||
|
|
||||||
|
return packageUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
addPackage(pkg) {
|
||||||
|
this.#packagesList = this.#packagesList.filter((p) => {
|
||||||
return p.name !== pkg.name;
|
return p.name !== pkg.name;
|
||||||
});
|
});
|
||||||
|
|
||||||
packageManager.packagesList.push(pkg);
|
this.#packagesList.push(pkg);
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeUrl(url) {
|
removeUrl(url) {
|
||||||
var manifestUrls = JSON.parse(appSettings.get(settingsKey) || '[]');
|
var manifestUrls = JSON.parse(appSettings.get(this.#settingsKey) || '[]');
|
||||||
|
|
||||||
manifestUrls = manifestUrls.filter(function (i) {
|
manifestUrls = manifestUrls.filter((i) => {
|
||||||
return i !== url;
|
return i !== url;
|
||||||
});
|
});
|
||||||
|
|
||||||
appSettings.set(settingsKey, JSON.stringify(manifestUrls));
|
appSettings.set(this.#settingsKey, JSON.stringify(manifestUrls));
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadPackage(packageManager, url, throwError) {
|
loadPackage(url, throwError = false) {
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise((resolve, reject) => {
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
var originalUrl = url;
|
var originalUrl = url;
|
||||||
url += url.indexOf('?') === -1 ? '?' : '&';
|
url += url.indexOf('?') === -1 ? '?' : '&';
|
||||||
|
@ -30,28 +99,28 @@ define(['appSettings', 'pluginManager'], function (appSettings, pluginManager) {
|
||||||
|
|
||||||
xhr.open('GET', url, true);
|
xhr.open('GET', url, true);
|
||||||
|
|
||||||
var onError = function () {
|
var onError = () => {
|
||||||
if (throwError === true) {
|
if (throwError === true) {
|
||||||
reject();
|
reject();
|
||||||
} else {
|
} else {
|
||||||
removeUrl(originalUrl);
|
this.removeUrl(originalUrl);
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
xhr.onload = function (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;
|
||||||
|
|
||||||
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(function (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 {
|
||||||
|
@ -64,71 +133,8 @@ define(['appSettings', 'pluginManager'], function (appSettings, pluginManager) {
|
||||||
xhr.send();
|
xhr.send();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function PackageManager() {
|
|
||||||
this.packagesList = [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PackageManager.prototype.init = function () {
|
/* eslint-enable indent */
|
||||||
var manifestUrls = JSON.parse(appSettings.get(settingsKey) || '[]');
|
|
||||||
|
|
||||||
var instance = this;
|
export default new PackageManager();
|
||||||
return Promise.all(manifestUrls.map(function (u) {
|
|
||||||
return loadPackage(instance, u);
|
|
||||||
})).then(function () {
|
|
||||||
return Promise.resolve();
|
|
||||||
}, function () {
|
|
||||||
return Promise.resolve();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
PackageManager.prototype.packages = function () {
|
|
||||||
return this.packagesList.slice(0);
|
|
||||||
};
|
|
||||||
|
|
||||||
PackageManager.prototype.install = function (url) {
|
|
||||||
return loadPackage(this, url, true).then(function (pkg) {
|
|
||||||
var manifestUrls = JSON.parse(appSettings.get(settingsKey) || '[]');
|
|
||||||
|
|
||||||
if (manifestUrls.indexOf(url) === -1) {
|
|
||||||
manifestUrls.push(url);
|
|
||||||
appSettings.set(settingsKey, JSON.stringify(manifestUrls));
|
|
||||||
}
|
|
||||||
|
|
||||||
return pkg;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
PackageManager.prototype.uninstall = function (name) {
|
|
||||||
var pkg = this.packagesList.filter(function (p) {
|
|
||||||
return p.name === name;
|
|
||||||
})[0];
|
|
||||||
|
|
||||||
if (pkg) {
|
|
||||||
this.packagesList = this.packagesList.filter(function (p) {
|
|
||||||
return p.name !== name;
|
|
||||||
});
|
|
||||||
|
|
||||||
removeUrl(pkg.url);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Promise.resolve();
|
|
||||||
};
|
|
||||||
|
|
||||||
PackageManager.prototype.mapPath = function (pkg, pluginUrl) {
|
|
||||||
var urlLower = pluginUrl.toLowerCase();
|
|
||||||
if (urlLower.indexOf('http:') === 0 || urlLower.indexOf('https:') === 0 || urlLower.indexOf('file:') === 0) {
|
|
||||||
return pluginUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
var packageUrl = pkg.url;
|
|
||||||
packageUrl = packageUrl.substring(0, packageUrl.lastIndexOf('/'));
|
|
||||||
|
|
||||||
packageUrl += '/';
|
|
||||||
packageUrl += pluginUrl;
|
|
||||||
|
|
||||||
return packageUrl;
|
|
||||||
};
|
|
||||||
|
|
||||||
return new PackageManager();
|
|
||||||
});
|
|
||||||
|
|
|
@ -1,10 +1,18 @@
|
||||||
define(['events', 'globalize'], function (events, globalize) {
|
import events from 'events';
|
||||||
'use strict';
|
import globalize from 'globalize';
|
||||||
|
/* eslint-disable indent */
|
||||||
|
|
||||||
// TODO: replace with each plugin version
|
// TODO: replace with each plugin version
|
||||||
var cacheParam = new Date().getTime();
|
var cacheParam = new Date().getTime();
|
||||||
|
|
||||||
function loadStrings(plugin) {
|
class PluginManager {
|
||||||
|
pluginsList = [];
|
||||||
|
|
||||||
|
get plugins() {
|
||||||
|
return this.pluginsList;
|
||||||
|
}
|
||||||
|
|
||||||
|
#loadStrings(plugin) {
|
||||||
var strings = plugin.getTranslations ? plugin.getTranslations() : [];
|
var strings = plugin.getTranslations ? plugin.getTranslations() : [];
|
||||||
return globalize.loadStrings({
|
return globalize.loadStrings({
|
||||||
name: plugin.id || plugin.packageName,
|
name: plugin.id || plugin.packageName,
|
||||||
|
@ -12,26 +20,19 @@ define(['events', 'globalize'], function (events, globalize) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function definePluginRoute(pluginManager, route, plugin) {
|
#definePluginRoute(route, plugin) {
|
||||||
route.contentPath = pluginManager.mapPath(plugin, route.path);
|
route.contentPath = this.mapPath(plugin, route.path);
|
||||||
route.path = pluginManager.mapRoute(plugin, route);
|
route.path = this.#mapRoute(plugin, route);
|
||||||
|
|
||||||
Emby.App.defineRoute(route, plugin.id);
|
Emby.App.defineRoute(route, plugin.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
function PluginManager() {
|
#registerPlugin(plugin) {
|
||||||
this.pluginsList = [];
|
this.#register(plugin);
|
||||||
}
|
|
||||||
|
|
||||||
PluginManager.prototype.loadPlugin = function(pluginSpec) {
|
|
||||||
var instance = this;
|
|
||||||
|
|
||||||
function registerPlugin(plugin) {
|
|
||||||
instance.register(plugin);
|
|
||||||
|
|
||||||
if (plugin.getRoutes) {
|
if (plugin.getRoutes) {
|
||||||
plugin.getRoutes().forEach(function (route) {
|
plugin.getRoutes().forEach((route) => {
|
||||||
definePluginRoute(instance, route, plugin);
|
this.#definePluginRoute(route, plugin);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +41,7 @@ define(['events', 'globalize'], function (events, globalize) {
|
||||||
return Promise.resolve(plugin);
|
return Promise.resolve(plugin);
|
||||||
} else {
|
} else {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
loadStrings(plugin)
|
this.#loadStrings(plugin)
|
||||||
.then(function () {
|
.then(function () {
|
||||||
resolve(plugin);
|
resolve(plugin);
|
||||||
})
|
})
|
||||||
|
@ -49,15 +50,16 @@ define(['events', 'globalize'], function (events, globalize) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loadPlugin(pluginSpec) {
|
||||||
if (typeof pluginSpec === 'string') {
|
if (typeof pluginSpec === 'string') {
|
||||||
console.debug('Loading plugin (via deprecated requirejs method): ' + pluginSpec);
|
console.debug('Loading plugin (via deprecated requirejs method): ' + pluginSpec);
|
||||||
|
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise((resolve, reject) => {
|
||||||
require([pluginSpec], (pluginFactory) => {
|
require([pluginSpec], (pluginFactory) => {
|
||||||
var plugin = pluginFactory.default ? new pluginFactory.default() : new pluginFactory();
|
var plugin = pluginFactory.default ? new pluginFactory.default() : new pluginFactory();
|
||||||
|
|
||||||
// See if it's already installed
|
// See if it's already installed
|
||||||
var existing = instance.pluginsList.filter(function (p) {
|
var existing = this.pluginsList.filter(function (p) {
|
||||||
return p.id === plugin.id;
|
return p.id === plugin.id;
|
||||||
})[0];
|
})[0];
|
||||||
|
|
||||||
|
@ -78,61 +80,57 @@ define(['events', 'globalize'], function (events, globalize) {
|
||||||
paths: paths
|
paths: paths
|
||||||
});
|
});
|
||||||
|
|
||||||
registerPlugin(plugin).then(resolve).catch(reject);
|
this.#registerPlugin(plugin).then(resolve).catch(reject);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else if (pluginSpec.then) {
|
} else if (pluginSpec.then) {
|
||||||
return pluginSpec.then(pluginBuilder => {
|
return pluginSpec.then(pluginBuilder => {
|
||||||
return pluginBuilder();
|
return pluginBuilder();
|
||||||
}).then(plugin => {
|
}).then((plugin) => {
|
||||||
console.debug(`Plugin loaded: ${plugin.id}`);
|
console.debug(`Plugin loaded: ${plugin.id}`);
|
||||||
return registerPlugin(plugin);
|
return this.#registerPlugin(plugin);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const err = new Error('Plugins have to be a Promise that resolves to a plugin builder function or a requirejs urls (deprecated)');
|
const err = new TypeError('Plugins have to be a Promise that resolves to a plugin builder function or a RequireJS url (deprecated)');
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return Promise.reject(err);
|
return Promise.reject(err);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
// In lieu of automatic discovery, plugins will register dynamic objects
|
// In lieu of automatic discovery, plugins will register dynamic objects
|
||||||
// Each object will have the following properties:
|
// Each object will have the following properties:
|
||||||
// name
|
// name
|
||||||
// type (skin, screensaver, etc)
|
// type (skin, screensaver, etc)
|
||||||
PluginManager.prototype.register = function (obj) {
|
#register(obj) {
|
||||||
this.pluginsList.push(obj);
|
this.pluginsList.push(obj);
|
||||||
events.trigger(this, 'registered', [obj]);
|
events.trigger(this, 'registered', [obj]);
|
||||||
};
|
}
|
||||||
|
|
||||||
PluginManager.prototype.ofType = function (type) {
|
ofType(type) {
|
||||||
return this.pluginsList.filter(function (o) {
|
return this.pluginsList.filter((o) => {
|
||||||
return o.type === type;
|
return o.type === type;
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
PluginManager.prototype.plugins = function () {
|
#mapRoute(plugin, route) {
|
||||||
return this.pluginsList;
|
|
||||||
};
|
|
||||||
|
|
||||||
PluginManager.prototype.mapRoute = function (plugin, route) {
|
|
||||||
if (typeof plugin === 'string') {
|
if (typeof plugin === 'string') {
|
||||||
plugin = this.pluginsList.filter(function (p) {
|
plugin = this.pluginsList.filter((p) => {
|
||||||
return (p.id || p.packageName) === plugin;
|
return (p.id || p.packageName) === plugin;
|
||||||
})[0];
|
})[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
route = route.path || route;
|
route = route.path || route;
|
||||||
|
|
||||||
if (route.toLowerCase().indexOf('http') === 0) {
|
if (route.toLowerCase().startsWith('http')) {
|
||||||
return route;
|
return route;
|
||||||
}
|
}
|
||||||
|
|
||||||
return '/plugins/' + plugin.id + '/' + route;
|
return '/plugins/' + plugin.id + '/' + route;
|
||||||
};
|
}
|
||||||
|
|
||||||
PluginManager.prototype.mapPath = function (plugin, path, addCacheParam) {
|
mapPath(plugin, path, addCacheParam) {
|
||||||
if (typeof plugin === 'string') {
|
if (typeof plugin === 'string') {
|
||||||
plugin = this.pluginsList.filter(function (p) {
|
plugin = this.pluginsList.filter((p) => {
|
||||||
return (p.id || p.packageName) === plugin;
|
return (p.id || p.packageName) === plugin;
|
||||||
})[0];
|
})[0];
|
||||||
}
|
}
|
||||||
|
@ -140,12 +138,14 @@ define(['events', 'globalize'], function (events, globalize) {
|
||||||
var url = plugin.baseUrl + '/' + path;
|
var url = plugin.baseUrl + '/' + path;
|
||||||
|
|
||||||
if (addCacheParam) {
|
if (addCacheParam) {
|
||||||
url += url.indexOf('?') === -1 ? '?' : '&';
|
url += url.includes('?') ? '&' : '?';
|
||||||
url += 'v=' + cacheParam;
|
url += 'v=' + cacheParam;
|
||||||
}
|
}
|
||||||
|
|
||||||
return url;
|
return url;
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return new PluginManager();
|
/* eslint-enable indent */
|
||||||
});
|
|
||||||
|
export default new PluginManager();
|
||||||
|
|
|
@ -150,7 +150,7 @@ function tryRemoveElement(elem) {
|
||||||
/**
|
/**
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
name
|
name;
|
||||||
/**
|
/**
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
|
@ -730,7 +730,7 @@ function tryRemoveElement(elem) {
|
||||||
const elem = e.target;
|
const elem = e.target;
|
||||||
this.destroyCustomTrack(elem);
|
this.destroyCustomTrack(elem);
|
||||||
onEndedInternal(this, elem, this.onError);
|
onEndedInternal(this, elem, this.onError);
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
|
@ -760,7 +760,7 @@ function tryRemoveElement(elem) {
|
||||||
}
|
}
|
||||||
|
|
||||||
events.trigger(this, 'timeupdate');
|
events.trigger(this, 'timeupdate');
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
|
@ -773,7 +773,7 @@ function tryRemoveElement(elem) {
|
||||||
const elem = e.target;
|
const elem = e.target;
|
||||||
saveVolume(elem.volume);
|
saveVolume(elem.volume);
|
||||||
events.trigger(this, 'volumechange');
|
events.trigger(this, 'volumechange');
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
|
@ -785,7 +785,7 @@ function tryRemoveElement(elem) {
|
||||||
|
|
||||||
this.onStartedAndNavigatedToOsd();
|
this.onStartedAndNavigatedToOsd();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
|
@ -832,14 +832,14 @@ function tryRemoveElement(elem) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
events.trigger(this, 'playing');
|
events.trigger(this, 'playing');
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
onPlay = () => {
|
onPlay = () => {
|
||||||
events.trigger(this, 'unpause');
|
events.trigger(this, 'unpause');
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
|
@ -865,21 +865,21 @@ function tryRemoveElement(elem) {
|
||||||
*/
|
*/
|
||||||
onClick = () => {
|
onClick = () => {
|
||||||
events.trigger(this, 'click');
|
events.trigger(this, 'click');
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
onDblClick = () => {
|
onDblClick = () => {
|
||||||
events.trigger(this, 'dblclick');
|
events.trigger(this, 'dblclick');
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
onPause = () => {
|
onPause = () => {
|
||||||
events.trigger(this, 'pause');
|
events.trigger(this, 'pause');
|
||||||
}
|
};
|
||||||
|
|
||||||
onWaiting() {
|
onWaiting() {
|
||||||
events.trigger(this, 'waiting');
|
events.trigger(this, 'waiting');
|
||||||
|
@ -929,7 +929,7 @@ function tryRemoveElement(elem) {
|
||||||
}
|
}
|
||||||
|
|
||||||
onErrorInternal(this, type);
|
onErrorInternal(this, type);
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
|
|
|
@ -302,7 +302,7 @@ import 'material-icons';
|
||||||
$(document).on('itemsaved', '.metadataEditorPage', function (e, item) {
|
$(document).on('itemsaved', '.metadataEditorPage', function (e, item) {
|
||||||
updateEditorNode(this, item);
|
updateEditorNode(this, item);
|
||||||
}).on('pagebeforeshow', '.metadataEditorPage', function () {
|
}).on('pagebeforeshow', '.metadataEditorPage', function () {
|
||||||
/* eslint-disable-next-line no-unused-expressions */
|
/* eslint-disable-next-line @babel/no-unused-expressions */
|
||||||
import('css!assets/css/metadataeditor.css');
|
import('css!assets/css/metadataeditor.css');
|
||||||
}).on('pagebeforeshow', '.metadataEditorPage', function () {
|
}).on('pagebeforeshow', '.metadataEditorPage', function () {
|
||||||
var page = this;
|
var page = this;
|
||||||
|
|
|
@ -155,7 +155,7 @@ export function enable() {
|
||||||
function attachGamepadScript(e) {
|
function attachGamepadScript(e) {
|
||||||
console.log('Gamepad connected! Attaching gamepadtokey.js script');
|
console.log('Gamepad connected! Attaching gamepadtokey.js script');
|
||||||
window.removeEventListener('gamepadconnected', attachGamepadScript);
|
window.removeEventListener('gamepadconnected', attachGamepadScript);
|
||||||
/* eslint-disable-next-line no-unused-expressions */
|
/* eslint-disable-next-line @babel/no-unused-expressions */
|
||||||
import('scripts/gamepadtokey');
|
import('scripts/gamepadtokey');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -479,7 +479,7 @@ function initClient() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadPlugins(appHost, browser, shell) {
|
function loadPlugins(appHost, browser, shell) {
|
||||||
console.debug('loading installed plugins');
|
console.groupCollapsed('loading installed plugins');
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
require(['webSettings'], function (webSettings) {
|
require(['webSettings'], function (webSettings) {
|
||||||
webSettings.getPlugins().then(function (list) {
|
webSettings.getPlugins().then(function (list) {
|
||||||
|
@ -497,11 +497,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))
|
||||||
|
.then(function () {
|
||||||
|
console.debug('finished loading plugins');
|
||||||
|
})
|
||||||
|
.catch(() => reject)
|
||||||
|
.finally(() => {
|
||||||
|
console.groupEnd('loading installed plugins');
|
||||||
require(['packageManager'], function (packageManager) {
|
require(['packageManager'], function (packageManager) {
|
||||||
packageManager.init().then(resolve, reject);
|
packageManager.default.init().then(resolve, reject);
|
||||||
});
|
});
|
||||||
}, reject);
|
})
|
||||||
|
;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -510,7 +517,7 @@ function initClient() {
|
||||||
function loadPlugin(url) {
|
function loadPlugin(url) {
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
require(['pluginManager'], function (pluginManager) {
|
require(['pluginManager'], function (pluginManager) {
|
||||||
pluginManager.loadPlugin(url).then(resolve, reject);
|
pluginManager.default.loadPlugin(url).then(resolve, reject);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue