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';
|
2020-11-06 00:00:34 +00:00
|
|
|
import '../assets/css/site.scss';
|
2020-10-17 19:08:56 +01:00
|
|
|
import { Events } from 'jellyfin-apiclient';
|
|
|
|
import ServerConnections from '../components/ServerConnections';
|
2020-10-18 20:00:39 +01:00
|
|
|
import globalize from './globalize';
|
|
|
|
import browser from './browser';
|
|
|
|
import keyboardNavigation from './keyboardNavigation';
|
|
|
|
import './mouseManager';
|
|
|
|
import autoFocuser from '../components/autoFocuser';
|
|
|
|
import { appHost } from '../components/apphost';
|
|
|
|
import { getPlugins } from './settings/webSettings';
|
|
|
|
import { pluginManager } from '../components/pluginManager';
|
|
|
|
import packageManager from '../components/packageManager';
|
|
|
|
import { appRouter } from '../components/appRouter';
|
2020-11-09 00:14:33 +00:00
|
|
|
import '../elements/emby-button/emby-button';
|
|
|
|
import './autoThemes';
|
|
|
|
import './libraryMenu';
|
|
|
|
import './routes';
|
|
|
|
import '../components/themeMediaPlayer';
|
|
|
|
import './autoBackdrops';
|
2020-11-28 10:00:53 -05:00
|
|
|
import { pageClassOn, serverAddress } from './clientUtils';
|
2020-11-09 00:14:33 +00:00
|
|
|
import '../libraries/screensavermanager';
|
|
|
|
import './serverNotifications';
|
|
|
|
import '../components/playback/playerSelectionMenu';
|
2020-11-27 20:19:11 +03:00
|
|
|
import '../legacy/focusPreventScroll';
|
|
|
|
import '../legacy/vendorStyles';
|
2020-12-03 16:25:50 +01:00
|
|
|
import SyncPlay from '../components/syncPlay/core';
|
2020-09-25 09:44:30 +02:00
|
|
|
import { playbackManager } from '../components/playback/playbackmanager';
|
2020-11-23 14:27:54 +01:00
|
|
|
import SyncPlayNoActivePlayer from '../components/syncPlay/ui/players/NoActivePlayer';
|
|
|
|
import SyncPlayHtmlVideoPlayer from '../components/syncPlay/ui/players/HtmlVideoPlayer';
|
|
|
|
import SyncPlayHtmlAudioPlayer from '../components/syncPlay/ui/players/HtmlAudioPlayer';
|
2021-04-24 14:33:07 -04:00
|
|
|
import { currentSettings } from './settings/userSettings';
|
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) {
|
2021-01-26 22:49:01 -05: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-10-18 20:00:39 +01:00
|
|
|
function loadCoreDictionary() {
|
2020-12-30 01:07:45 -05:00
|
|
|
const languages = ['af', 'ar', 'be-by', 'bg-bg', 'bn_bd', 'ca', 'cs', 'da', 'de', 'el', 'en-gb', 'en-us', 'eo', 'es', 'es-419', 'es-ar', 'es_do', 'es-mx', 'fa', 'fi', 'fil', 'fr', 'fr-ca', 'gl', 'gsw', 'he', 'hi-in', 'hr', 'hu', 'id', 'it', 'ja', 'kk', 'ko', 'lt-lt', 'mr', 'ms', 'nb', 'nl', 'pl', 'pr', 'pt', 'pt-br', 'pt-pt', 'ro', 'ru', 'sk', 'sl-si', 'sq', 'sv', 'ta', 'th', 'tr', 'uk', 'ur_pk', 'vi', 'zh-cn', 'zh-hk', 'zh-tw'];
|
2020-10-18 20:00:39 +01:00
|
|
|
const translations = languages.map(function (language) {
|
|
|
|
return {
|
|
|
|
lang: language,
|
|
|
|
path: language + '.json'
|
|
|
|
};
|
2019-02-23 16:38:53 +00:00
|
|
|
});
|
2020-10-18 20:00:39 +01:00
|
|
|
globalize.defaultModule('core');
|
|
|
|
return globalize.loadStrings({
|
|
|
|
name: 'core',
|
|
|
|
translations: translations
|
2019-02-23 16:38:53 +00:00
|
|
|
});
|
2020-10-18 20:00:39 +01:00
|
|
|
}
|
2019-02-23 16:38:53 +00:00
|
|
|
|
2020-10-18 20:00:39 +01:00
|
|
|
function init() {
|
2020-11-21 21:03:18 +03:00
|
|
|
serverAddress().then(server => {
|
2020-11-26 01:45:23 -05:00
|
|
|
if (server) {
|
|
|
|
ServerConnections.initApiClient(server);
|
2020-11-21 21:03:18 +03:00
|
|
|
}
|
|
|
|
}).then(() => {
|
|
|
|
console.debug('initAfterDependencies promises resolved');
|
2019-02-23 16:38:53 +00:00
|
|
|
|
2020-11-21 21:03:18 +03:00
|
|
|
loadCoreDictionary().then(function () {
|
|
|
|
onGlobalizeInit();
|
2019-02-23 16:38:53 +00:00
|
|
|
});
|
2019-02-23 17:12:14 +00:00
|
|
|
|
2020-11-21 21:03:18 +03:00
|
|
|
keyboardNavigation.enable();
|
|
|
|
autoFocuser.enable();
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-11-21 21:03:18 +03:00
|
|
|
Events.on(ServerConnections, 'localusersignedin', globalize.updateCurrentCulture);
|
|
|
|
});
|
2020-10-18 20:00:39 +01:00
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-10-18 20:00:39 +01:00
|
|
|
function onGlobalizeInit() {
|
|
|
|
if (window.appMode === 'android') {
|
|
|
|
if (window.location.href.toString().toLowerCase().indexOf('start=backgroundsync') !== -1) {
|
2020-10-22 00:36:38 +01:00
|
|
|
return onAppReady();
|
2020-04-03 18:49:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-18 20:00:39 +01:00
|
|
|
document.title = globalize.translateHtml(document.title, 'core');
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-10-18 20:00:39 +01:00
|
|
|
if (browser.tv && !browser.android) {
|
|
|
|
console.debug('using system fonts with explicit sizes');
|
2020-11-06 00:00:34 +00:00
|
|
|
import('../assets/css/fonts.sized.scss');
|
2020-10-18 20:00:39 +01:00
|
|
|
} else {
|
|
|
|
console.debug('using default fonts');
|
2020-11-06 00:00:34 +00:00
|
|
|
import('../assets/css/fonts.scss');
|
2019-10-01 00:51:56 +09:00
|
|
|
}
|
|
|
|
|
2021-01-26 15:31:58 -05:00
|
|
|
import('../assets/css/librarybrowser.scss');
|
2020-01-24 02:57:29 +09:00
|
|
|
|
2020-10-22 00:36:38 +01:00
|
|
|
loadPlugins().then(function () {
|
2020-09-25 09:44:30 +02:00
|
|
|
initSyncPlay();
|
2020-10-22 00:36:38 +01:00
|
|
|
onAppReady();
|
2020-10-18 20:00:39 +01:00
|
|
|
});
|
|
|
|
}
|
2020-01-24 02:57:29 +09:00
|
|
|
|
2020-10-22 00:36:38 +01:00
|
|
|
function loadPlugins() {
|
2020-10-18 20:00:39 +01:00
|
|
|
console.groupCollapsed('loading installed plugins');
|
|
|
|
console.dir(pluginManager);
|
|
|
|
return getPlugins().then(function (list) {
|
|
|
|
if (!appHost.supports('remotecontrol')) {
|
2020-11-24 12:17:43 -05:00
|
|
|
// Disable remote player plugins if not supported
|
2020-10-18 20:00:39 +01:00
|
|
|
list.splice(list.indexOf('sessionPlayer'), 1);
|
2020-11-24 12:17:43 -05:00
|
|
|
list.splice(list.indexOf('chromecastPlayer'), 1);
|
|
|
|
} else if (!browser.chrome && !browser.edgeChromium && !browser.opera) {
|
|
|
|
// Disable chromecast player in unsupported browsers
|
|
|
|
list.splice(list.indexOf('chromecastPlayer'), 1);
|
2019-01-21 17:47:10 +09:00
|
|
|
}
|
2019-02-23 16:38:53 +00:00
|
|
|
|
2020-10-18 20:00:39 +01:00
|
|
|
// add any native plugins
|
|
|
|
if (window.NativeShell) {
|
|
|
|
list = list.concat(window.NativeShell.getPlugins());
|
2019-02-23 16:38:53 +00:00
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-12-02 15:43:31 -05:00
|
|
|
Promise.all(list.map(plugin => pluginManager.loadPlugin(plugin)))
|
|
|
|
.then(() => console.debug('finished loading plugins'))
|
|
|
|
.catch(e => console.warn('failed loading plugins', e))
|
2020-10-18 20:00:39 +01:00
|
|
|
.finally(() => {
|
|
|
|
console.groupEnd('loading installed plugins');
|
|
|
|
packageManager.init();
|
|
|
|
})
|
|
|
|
;
|
|
|
|
});
|
|
|
|
}
|
2019-02-23 16:38:53 +00:00
|
|
|
|
2020-09-25 09:44:30 +02:00
|
|
|
function initSyncPlay() {
|
|
|
|
// Register player wrappers.
|
|
|
|
SyncPlay.PlayerFactory.setDefaultWrapper(SyncPlayNoActivePlayer);
|
|
|
|
SyncPlay.PlayerFactory.registerWrapper(SyncPlayHtmlVideoPlayer);
|
|
|
|
SyncPlay.PlayerFactory.registerWrapper(SyncPlayHtmlAudioPlayer);
|
|
|
|
|
|
|
|
// Listen for player changes.
|
|
|
|
Events.on(playbackManager, 'playerchange', (event, newPlayer, newTarget, oldPlayer) => {
|
|
|
|
SyncPlay.Manager.onPlayerChange(newPlayer, newTarget, oldPlayer);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Start SyncPlay.
|
|
|
|
const apiClient = ServerConnections.currentApiClient();
|
2020-12-05 14:45:52 +03:00
|
|
|
if (apiClient) SyncPlay.Manager.init(apiClient);
|
|
|
|
|
|
|
|
// FIXME: Multiple apiClients?
|
|
|
|
Events.on(ServerConnections, 'apiclientcreated', (e, newApiClient) => SyncPlay.Manager.init(newApiClient));
|
2020-09-25 09:44:30 +02:00
|
|
|
}
|
|
|
|
|
2021-04-24 16:42:21 -04:00
|
|
|
async function onAppReady() {
|
2020-10-18 20:00:39 +01:00
|
|
|
console.debug('begin onAppReady');
|
2020-08-08 15:26:03 +02:00
|
|
|
|
2020-10-18 20:00:39 +01:00
|
|
|
console.debug('onAppReady: loading dependencies');
|
2019-05-05 23:55:42 +02:00
|
|
|
|
2020-10-18 20:00:39 +01:00
|
|
|
if (browser.iOS) {
|
2020-11-06 00:00:34 +00:00
|
|
|
import('../assets/css/ios.scss');
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-11-09 00:14:33 +00:00
|
|
|
appRouter.start({
|
|
|
|
click: false,
|
|
|
|
hashbang: true
|
|
|
|
});
|
2020-08-09 15:03:41 +02:00
|
|
|
|
2020-11-09 00:14:33 +00:00
|
|
|
if (!browser.tv && !browser.xboxOne && !browser.ps4) {
|
|
|
|
import('../components/nowPlayingBar/nowPlayingBar');
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-11-09 00:14:33 +00:00
|
|
|
if (appHost.supports('remotecontrol')) {
|
|
|
|
import('../components/playback/playerSelectionMenu');
|
|
|
|
import('../components/playback/remotecontrolautoplay');
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-11-09 00:14:33 +00:00
|
|
|
if (!appHost.supports('physicalvolumecontrol') || browser.touch) {
|
|
|
|
import('../components/playback/volumeosd');
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-11-09 00:14:33 +00:00
|
|
|
/* eslint-disable-next-line compat/compat */
|
|
|
|
if (navigator.mediaSession || window.NativeShell) {
|
|
|
|
import('../components/playback/mediasession');
|
|
|
|
}
|
2019-11-23 23:25:10 +03:00
|
|
|
|
2020-11-09 00:14:33 +00:00
|
|
|
if (!browser.tv && !browser.xboxOne) {
|
|
|
|
import('../components/playback/playbackorientation');
|
|
|
|
registerServiceWorker();
|
2019-02-23 16:38:53 +00:00
|
|
|
|
2020-11-09 00:14:33 +00:00
|
|
|
if (window.Notification) {
|
|
|
|
import('../components/notifications/notifications');
|
|
|
|
}
|
|
|
|
}
|
2019-02-23 16:38:53 +00:00
|
|
|
|
2020-11-09 00:14:33 +00:00
|
|
|
const apiClient = ServerConnections.currentApiClient();
|
|
|
|
if (apiClient) {
|
2021-04-24 16:42:21 -04:00
|
|
|
const updateStyle = (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;
|
|
|
|
};
|
|
|
|
|
|
|
|
const style = fetch(apiClient.getUrl('Branding/Css'))
|
2020-11-09 00:14:33 +00:00
|
|
|
.then(function(response) {
|
|
|
|
if (!response.ok) {
|
|
|
|
throw new Error(response.status + ' ' + response.statusText);
|
2019-10-01 00:51:56 +09:00
|
|
|
}
|
2020-11-09 00:14:33 +00:00
|
|
|
return response.text();
|
|
|
|
})
|
|
|
|
.catch(function(err) {
|
|
|
|
console.warn('Error applying custom css', err);
|
2019-10-01 00:51:56 +09:00
|
|
|
});
|
2021-04-24 15:49:49 -04:00
|
|
|
|
2021-04-24 16:42:21 -04:00
|
|
|
const handleStyleChange = async () => {
|
|
|
|
if (currentSettings.disableCustomCss()) {
|
|
|
|
updateStyle('');
|
|
|
|
} else {
|
|
|
|
updateStyle(await style);
|
|
|
|
}
|
2021-04-24 14:33:07 -04:00
|
|
|
|
2021-04-24 16:42:21 -04:00
|
|
|
const localCss = currentSettings.customCss();
|
|
|
|
let localStyle = document.querySelector('#localCssBranding');
|
|
|
|
if (localCss) {
|
|
|
|
if (!localStyle) {
|
|
|
|
// Inject the branding css as a dom element in body so it will take
|
|
|
|
// precedence over other stylesheets
|
|
|
|
localStyle = document.createElement('style');
|
|
|
|
localStyle.id = 'localCssBranding';
|
|
|
|
document.body.appendChild(localStyle);
|
|
|
|
}
|
|
|
|
localStyle.textContent = localCss;
|
|
|
|
} else {
|
|
|
|
if (localStyle) {
|
|
|
|
localStyle.textContent = '';
|
|
|
|
}
|
2021-04-24 14:33:07 -04:00
|
|
|
}
|
2021-04-24 16:42:21 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
Events.on(ServerConnections, 'localusersignedin', handleStyleChange);
|
|
|
|
Events.on(ServerConnections, 'localusersignedout', handleStyleChange);
|
|
|
|
Events.on(currentSettings, 'change', (e, prop) => {
|
|
|
|
if (prop == 'disableCustomCss' || prop == 'customCss') {
|
|
|
|
handleStyleChange();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
style.then(updateStyle);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2020-10-18 20:00:39 +01:00
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-10-18 20:00:39 +01:00
|
|
|
function registerServiceWorker() {
|
|
|
|
/* eslint-disable compat/compat */
|
|
|
|
if (navigator.serviceWorker && window.appMode !== 'cordova' && window.appMode !== 'android') {
|
2021-05-18 23:22:57 +03:00
|
|
|
navigator.serviceWorker.register('serviceworker.js').then(() =>
|
2020-12-16 13:57:07 -05:00
|
|
|
console.log('serviceWorker registered')
|
|
|
|
).catch(error =>
|
|
|
|
console.log('error registering serviceWorker: ' + error)
|
|
|
|
);
|
2020-10-18 20:00:39 +01:00
|
|
|
} else {
|
|
|
|
console.warn('serviceWorker unsupported');
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2020-10-18 20:00:39 +01:00
|
|
|
/* eslint-enable compat/compat */
|
2020-07-19 16:15:11 +02:00
|
|
|
}
|
|
|
|
|
2020-10-18 20:00:39 +01:00
|
|
|
init();
|
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
|
|
|
});
|