2020-08-14 06:36:46 +02:00
|
|
|
import 'core-js/stable';
|
|
|
|
import 'regenerator-runtime/runtime';
|
|
|
|
import 'jquery';
|
|
|
|
import 'fast-text-encoding';
|
|
|
|
import 'intersection-observer';
|
2020-08-14 08:46:34 +02:00
|
|
|
import 'classlist.js';
|
2020-08-14 06:36:46 +02:00
|
|
|
import 'whatwg-fetch';
|
|
|
|
import 'resize-observer-polyfill';
|
|
|
|
import 'jellyfin-noto';
|
|
|
|
import '../assets/css/site.css';
|
2020-10-12 22:17:25 +01:00
|
|
|
import AppInfo from '../components/AppInfo';
|
2020-10-17 19:08:56 +01:00
|
|
|
import { Events } from 'jellyfin-apiclient';
|
|
|
|
import ServerConnections from '../components/ServerConnections';
|
2020-08-14 06:36:46 +02:00
|
|
|
|
|
|
|
// TODO: Move this elsewhere
|
2020-08-08 15:26:03 +02:00
|
|
|
window.getWindowLocationSearch = function(win) {
|
2020-10-07 21:12:14 +09:00
|
|
|
let search = (win || window).location.search;
|
2019-02-23 16:38:53 +00:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
if (!search) {
|
2020-10-07 21:12:14 +09:00
|
|
|
const index = window.location.href.indexOf('?');
|
2019-02-23 16:38:53 +00:00
|
|
|
|
2020-07-30 16:07:13 +02:00
|
|
|
if (index != -1) {
|
2019-02-23 16:38:53 +00:00
|
|
|
search = window.location.href.substring(index);
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-02-23 16:38:53 +00:00
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
return search || '';
|
2020-08-08 15:26:03 +02:00
|
|
|
};
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-08-14 06:36:46 +02:00
|
|
|
// TODO: Move this elsewhere
|
2020-08-08 15:26:03 +02:00
|
|
|
window.getParameterByName = function(name, url) {
|
2020-05-04 12:44:12 +02:00
|
|
|
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
|
2020-10-07 21:12:14 +09:00
|
|
|
const regexS = '[\\?&]' + name + '=([^&#]*)';
|
|
|
|
const regex = new RegExp(regexS, 'i');
|
|
|
|
const results = regex.exec(url || getWindowLocationSearch());
|
2019-02-23 16:38:53 +00:00
|
|
|
|
2020-07-30 16:07:13 +02:00
|
|
|
if (results == null) {
|
2020-05-04 12:44:12 +02:00
|
|
|
return '';
|
2019-02-23 16:38:53 +00:00
|
|
|
}
|
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
return decodeURIComponent(results[1].replace(/\+/g, ' '));
|
2020-07-19 16:15:11 +02:00
|
|
|
};
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-08-14 06:36:46 +02:00
|
|
|
// TODO: Move this elsewhere
|
2020-08-08 15:26:03 +02:00
|
|
|
window.pageClassOn = function(eventName, className, fn) {
|
2019-03-04 20:38:39 +00:00
|
|
|
document.addEventListener(eventName, function (event) {
|
2020-10-07 21:12:14 +09:00
|
|
|
const target = event.target;
|
2019-02-23 16:38:53 +00:00
|
|
|
|
|
|
|
if (target.classList.contains(className)) {
|
2019-03-04 20:38:39 +00:00
|
|
|
fn.call(target, event);
|
2019-02-23 16:38:53 +00:00
|
|
|
}
|
|
|
|
});
|
2020-08-08 15:26:03 +02:00
|
|
|
};
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-08-14 06:36:46 +02:00
|
|
|
// TODO: Move this elsewhere
|
2020-07-19 16:15:11 +02:00
|
|
|
window.pageIdOn = function(eventName, id, fn) {
|
2019-03-04 20:38:39 +00:00
|
|
|
document.addEventListener(eventName, function (event) {
|
2020-10-07 21:12:14 +09:00
|
|
|
const target = event.target;
|
2019-02-23 16:38:53 +00:00
|
|
|
|
|
|
|
if (target.id === id) {
|
2019-03-04 20:38:39 +00:00
|
|
|
fn.call(target, event);
|
2019-02-23 16:38:53 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2019-10-01 00:51:56 +09:00
|
|
|
|
2020-10-12 22:17:25 +01:00
|
|
|
if (self.appMode === 'cordova' || self.appMode === 'android' || self.appMode === 'standalone') {
|
|
|
|
AppInfo.isNativeApp = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Object.freeze(AppInfo);
|
2019-10-01 00:51:56 +09:00
|
|
|
|
2020-07-19 16:15:11 +02:00
|
|
|
function initClient() {
|
2020-10-17 19:08:56 +01:00
|
|
|
function init() {
|
|
|
|
ServerConnections.initApiClient();
|
2019-02-23 16:38:53 +00:00
|
|
|
|
2020-10-17 19:08:56 +01:00
|
|
|
console.debug('initAfterDependencies promises resolved');
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-10-17 19:08:56 +01:00
|
|
|
Promise.all([
|
|
|
|
import('./globalize'),
|
|
|
|
import('./browser')
|
2020-08-14 06:36:46 +02:00
|
|
|
])
|
2020-10-17 19:08:56 +01:00
|
|
|
.then(([globalize, browser]) => {
|
|
|
|
window.Globalize = globalize;
|
|
|
|
loadCoreDictionary(globalize).then(function () {
|
|
|
|
onGlobalizeInit(browser, globalize);
|
2020-08-14 06:36:46 +02:00
|
|
|
});
|
2019-02-23 16:38:53 +00:00
|
|
|
});
|
2020-10-17 19:08:56 +01:00
|
|
|
import('./keyboardNavigation')
|
|
|
|
.then((keyboardnavigation) => {
|
|
|
|
keyboardnavigation.enable();
|
|
|
|
});
|
|
|
|
import('./mouseManager');
|
|
|
|
import('../components/autoFocuser').then((autoFocuser) => {
|
|
|
|
autoFocuser.enable();
|
|
|
|
});
|
|
|
|
Promise.all([
|
|
|
|
import('./globalize'),
|
|
|
|
import('jellyfin-apiclient')
|
|
|
|
])
|
|
|
|
.then(([ globalize, { ConnectionManager } ]) => {
|
|
|
|
Events.on(ConnectionManager, 'localusersignedin', globalize.updateCurrentCulture);
|
2019-02-23 16:38:53 +00:00
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadCoreDictionary(globalize) {
|
2020-10-29 15:28:52 +00:00
|
|
|
const languages = ['ar', 'be-by', 'bg-bg', 'ca', 'cs', 'da', 'de', 'el', 'en-gb', 'en-us', 'es', 'es-ar', 'es-mx', 'fa', 'fi', 'fr', 'fr-ca', 'gsw', 'he', 'hi-in', 'hr', 'hu', 'id', 'it', 'ja', 'kk', 'ko', 'lt-lt', 'ms', 'nb', 'nl', 'pl', 'pt-br', 'pt-pt', 'ro', 'ru', 'sk', 'sl-si', 'sv', 'tr', 'uk', 'vi', 'zh-cn', 'zh-hk', 'zh-tw'];
|
2020-10-07 21:12:14 +09:00
|
|
|
const translations = languages.map(function (language) {
|
2019-02-03 02:31:09 +09:00
|
|
|
return {
|
2019-03-04 20:38:39 +00:00
|
|
|
lang: language,
|
2020-08-16 20:24:45 +02:00
|
|
|
path: language + '.json'
|
2019-02-23 16:38:53 +00:00
|
|
|
};
|
2019-02-03 02:31:09 +09:00
|
|
|
});
|
2020-05-04 12:44:12 +02:00
|
|
|
globalize.defaultModule('core');
|
2019-02-03 02:31:09 +09:00
|
|
|
return globalize.loadStrings({
|
2020-05-04 12:44:12 +02:00
|
|
|
name: 'core',
|
2018-10-23 01:05:09 +03:00
|
|
|
translations: translations
|
2019-02-03 02:31:09 +09:00
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-07-18 09:21:15 +01:00
|
|
|
function onGlobalizeInit(browser, globalize) {
|
2020-08-25 10:12:35 +09:00
|
|
|
if (window.appMode === 'android') {
|
|
|
|
if (window.location.href.toString().toLowerCase().indexOf('start=backgroundsync') !== -1) {
|
2019-02-23 16:38:53 +00:00
|
|
|
return onAppReady(browser);
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-02-23 16:38:53 +00:00
|
|
|
|
2020-07-18 09:21:15 +01:00
|
|
|
document.title = globalize.translateHtml(document.title, 'core');
|
2019-02-23 16:38:53 +00:00
|
|
|
|
|
|
|
if (browser.tv && !browser.android) {
|
2020-05-04 12:44:12 +02:00
|
|
|
console.debug('using system fonts with explicit sizes');
|
2020-08-14 06:36:46 +02:00
|
|
|
import('../assets/css/fonts.sized.css');
|
2019-02-23 16:38:53 +00:00
|
|
|
} else {
|
2020-05-04 12:44:12 +02:00
|
|
|
console.debug('using default fonts');
|
2020-08-14 06:36:46 +02:00
|
|
|
import('../assets/css/fonts.css');
|
2019-02-23 16:38:53 +00:00
|
|
|
}
|
|
|
|
|
2020-10-12 22:17:25 +01:00
|
|
|
import('../assets/css/librarybrowser.css');
|
2020-08-16 20:24:45 +02:00
|
|
|
import('../components/apphost')
|
|
|
|
.then(({ appHost }) => {
|
|
|
|
loadPlugins(appHost, browser).then(function () {
|
|
|
|
onAppReady(browser);
|
|
|
|
});
|
2019-02-23 16:38:53 +00:00
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2019-05-21 22:28:48 +01:00
|
|
|
function loadPlugins(appHost, browser, shell) {
|
2020-08-01 03:01:32 +02:00
|
|
|
console.groupCollapsed('loading installed plugins');
|
2020-08-02 17:28:25 +09:00
|
|
|
return new Promise(function (resolve, reject) {
|
2020-08-16 20:24:45 +02:00
|
|
|
Promise.all([
|
|
|
|
import('./settings/webSettings'),
|
|
|
|
import('../components/pluginManager')
|
|
|
|
])
|
|
|
|
.then(([webSettings, { pluginManager: pluginManager }]) => {
|
|
|
|
console.dir(pluginManager);
|
2020-08-14 06:36:46 +02:00
|
|
|
webSettings.getPlugins().then(function (list) {
|
|
|
|
// these two plugins are dependent on features
|
|
|
|
if (!appHost.supports('remotecontrol')) {
|
|
|
|
list.splice(list.indexOf('sessionPlayer'), 1);
|
|
|
|
|
|
|
|
if (!browser.chrome && !browser.opera) {
|
|
|
|
list.splice(list.indexOf('chromecastPlayer', 1));
|
|
|
|
}
|
2020-08-02 17:28:25 +09:00
|
|
|
}
|
2019-02-23 16:38:53 +00:00
|
|
|
|
2020-08-14 06:36:46 +02:00
|
|
|
// add any native plugins
|
|
|
|
if (window.NativeShell) {
|
|
|
|
list = list.concat(window.NativeShell.getPlugins());
|
|
|
|
}
|
2019-02-23 16:38:53 +00:00
|
|
|
|
2020-08-16 20:24:45 +02:00
|
|
|
Promise.all(list.map((plugin) => {
|
|
|
|
return pluginManager.loadPlugin(import(/* webpackChunkName: "[request]" */ `../plugins/${plugin}`));
|
|
|
|
}))
|
|
|
|
.then(function (pluginPromises) {
|
2020-08-14 06:36:46 +02:00
|
|
|
console.debug('finished loading plugins');
|
|
|
|
})
|
|
|
|
.catch(() => reject)
|
|
|
|
.finally(() => {
|
|
|
|
console.groupEnd('loading installed plugins');
|
|
|
|
import('../components/packageManager')
|
2020-08-16 20:24:45 +02:00
|
|
|
.then(({ default: packageManager }) => {
|
2020-08-14 08:46:34 +02:00
|
|
|
packageManager.init().then(resolve, reject);
|
2020-08-14 06:36:46 +02:00
|
|
|
});
|
|
|
|
})
|
|
|
|
;
|
|
|
|
});
|
2019-02-23 16:38:53 +00:00
|
|
|
});
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onAppReady(browser) {
|
2020-05-04 12:44:12 +02:00
|
|
|
console.debug('begin onAppReady');
|
2019-02-23 16:38:53 +00:00
|
|
|
|
2019-03-09 17:35:38 +00:00
|
|
|
// ensure that appHost is loaded in this point
|
2020-08-14 06:36:46 +02:00
|
|
|
Promise.all([
|
2020-08-16 20:24:45 +02:00
|
|
|
import('../components/apphost'),
|
2020-08-14 06:36:46 +02:00
|
|
|
import('../components/appRouter')
|
|
|
|
])
|
2020-08-16 20:24:45 +02:00
|
|
|
.then(([{ appHost }, { appRouter }]) => {
|
2020-08-14 06:36:46 +02:00
|
|
|
window.Emby = {};
|
|
|
|
|
|
|
|
console.debug('onAppReady: loading dependencies');
|
|
|
|
if (browser.iOS) {
|
|
|
|
import('../assets/css/ios.css');
|
|
|
|
}
|
2019-02-23 17:12:14 +00:00
|
|
|
|
2020-08-14 06:36:46 +02:00
|
|
|
window.Emby.Page = appRouter;
|
|
|
|
|
|
|
|
Promise.all([
|
|
|
|
import('../elements/emby-button/emby-button'),
|
|
|
|
import('./autoThemes'),
|
|
|
|
import('./libraryMenu'),
|
|
|
|
import('./routes')
|
|
|
|
])
|
|
|
|
.then(() => {
|
|
|
|
Emby.Page.start({
|
|
|
|
click: false,
|
|
|
|
hashbang: true
|
|
|
|
});
|
2019-02-23 17:12:14 +00:00
|
|
|
|
2020-08-14 06:36:46 +02:00
|
|
|
import('../components/themeMediaPlayer');
|
|
|
|
import('./autoBackdrops');
|
2019-02-23 16:38:53 +00:00
|
|
|
|
2020-08-14 06:36:46 +02:00
|
|
|
if (!browser.tv && !browser.xboxOne && !browser.ps4) {
|
|
|
|
import('../components/nowPlayingBar/nowPlayingBar');
|
|
|
|
}
|
2019-02-23 16:38:53 +00:00
|
|
|
|
2020-08-14 06:36:46 +02:00
|
|
|
if (appHost.supports('remotecontrol')) {
|
|
|
|
import('../components/playback/playerSelectionMenu');
|
|
|
|
import('../components/playback/remotecontrolautoplay');
|
|
|
|
}
|
2019-11-23 23:25:10 +03:00
|
|
|
|
2020-08-14 06:36:46 +02:00
|
|
|
import('../libraries/screensavermanager');
|
2019-02-23 16:38:53 +00:00
|
|
|
|
2020-08-14 06:36:46 +02:00
|
|
|
if (!appHost.supports('physicalvolumecontrol') || browser.touch) {
|
|
|
|
import('../components/playback/volumeosd');
|
|
|
|
}
|
2019-02-23 16:38:53 +00:00
|
|
|
|
2020-08-14 06:36:46 +02:00
|
|
|
/* eslint-disable-next-line compat/compat */
|
|
|
|
if (navigator.mediaSession || window.NativeShell) {
|
|
|
|
import('../components/playback/mediasession');
|
|
|
|
}
|
2019-02-23 16:38:53 +00:00
|
|
|
|
2020-08-14 06:36:46 +02:00
|
|
|
import('./serverNotifications');
|
2019-02-23 16:38:53 +00:00
|
|
|
|
2020-08-14 06:36:46 +02:00
|
|
|
if (!browser.tv && !browser.xboxOne) {
|
|
|
|
import('../components/playback/playbackorientation');
|
|
|
|
registerServiceWorker();
|
2019-02-23 16:38:53 +00:00
|
|
|
|
2020-08-14 06:36:46 +02:00
|
|
|
if (window.Notification) {
|
|
|
|
import('../components/notifications/notifications');
|
2020-08-13 00:15:02 +03:00
|
|
|
}
|
2020-08-14 06:36:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
import('../components/playback/playerSelectionMenu');
|
|
|
|
|
2020-10-17 19:08:56 +01:00
|
|
|
const apiClient = ServerConnections.currentApiClient();
|
2020-08-14 06:36:46 +02:00
|
|
|
if (apiClient) {
|
|
|
|
fetch(apiClient.getUrl('Branding/Css'))
|
|
|
|
.then(function(response) {
|
|
|
|
if (!response.ok) {
|
|
|
|
throw new Error(response.status + ' ' + response.statusText);
|
|
|
|
}
|
|
|
|
return response.text();
|
|
|
|
})
|
|
|
|
.then(function(css) {
|
|
|
|
let style = document.querySelector('#cssBranding');
|
|
|
|
if (!style) {
|
|
|
|
// Inject the branding css as a dom element in body so it will take
|
|
|
|
// precedence over other stylesheets
|
|
|
|
style = document.createElement('style');
|
|
|
|
style.id = 'cssBranding';
|
|
|
|
document.body.appendChild(style);
|
|
|
|
}
|
|
|
|
style.textContent = css;
|
|
|
|
})
|
|
|
|
.catch(function(err) {
|
|
|
|
console.warn('Error applying custom css', err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2019-10-01 00:51:56 +09:00
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function registerServiceWorker() {
|
2020-04-04 21:29:53 +02:00
|
|
|
/* eslint-disable compat/compat */
|
2020-08-25 10:12:35 +09:00
|
|
|
if (navigator.serviceWorker && window.appMode !== 'cordova' && window.appMode !== 'android') {
|
2019-02-23 16:38:53 +00:00
|
|
|
try {
|
2020-05-04 12:44:12 +02:00
|
|
|
navigator.serviceWorker.register('serviceworker.js');
|
2019-02-23 16:38:53 +00:00
|
|
|
} catch (err) {
|
2020-05-04 12:44:12 +02:00
|
|
|
console.error('error registering serviceWorker: ' + err);
|
2019-02-23 16:38:53 +00:00
|
|
|
}
|
2020-04-04 21:29:53 +02:00
|
|
|
} else {
|
2020-05-04 12:44:12 +02:00
|
|
|
console.warn('serviceWorker unsupported');
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2020-04-04 21:29:53 +02:00
|
|
|
/* eslint-enable compat/compat */
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-10-17 19:08:56 +01:00
|
|
|
//var localApiClient;
|
2019-02-23 16:38:53 +00:00
|
|
|
|
2020-08-14 06:36:46 +02:00
|
|
|
init();
|
2020-07-19 16:15:11 +02:00
|
|
|
}
|
2019-02-23 16:38:53 +00:00
|
|
|
|
2020-07-19 16:15:11 +02:00
|
|
|
initClient();
|
2019-10-01 00:51:56 +09:00
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
pageClassOn('viewshow', 'standalonePage', function () {
|
|
|
|
document.querySelector('.skinHeader').classList.add('noHeaderRight');
|
2019-01-21 17:47:10 +09:00
|
|
|
});
|
2019-10-01 00:51:56 +09:00
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
pageClassOn('viewhide', 'standalonePage', function () {
|
|
|
|
document.querySelector('.skinHeader').classList.remove('noHeaderRight');
|
2018-12-11 00:46:50 -05:00
|
|
|
});
|