From 4aa0ef49368508805321aaf901830df65bed2b1f Mon Sep 17 00:00:00 2001 From: MrTimscampi Date: Thu, 30 Jul 2020 20:34:21 +0200 Subject: [PATCH 1/6] Migrate appRouter to ES6 --- .eslintrc.js | 1 + package.json | 1 + src/components/actionSheet/actionSheet.js | 14 +- src/components/appRouter.js | 893 +++++++++++------- src/components/cardbuilder/cardBuilder.js | 28 +- src/components/dialogHelper/dialogHelper.js | 9 +- src/components/filtermenu/filtermenu.js | 2 + src/components/images/imageLoader.js | 14 +- src/components/indicators/indicators.js | 2 +- src/components/itemContextMenu.js | 5 +- src/components/mediainfo/mediainfo.js | 1 - .../metadataEditor/metadataEditor.js | 2 +- src/components/nowPlayingBar/nowPlayingBar.js | 18 +- src/components/playback/mediasession.js | 8 +- src/components/remotecontrol/remotecontrol.js | 18 +- src/components/scrollManager.js | 2 +- src/components/viewSettings/viewSettings.js | 2 + .../dashboard/plugins/repositories/index.js | 2 +- src/controllers/playback/video/index.js | 8 +- src/plugins/bookPlayer/plugin.js | 22 +- src/plugins/bookPlayer/tableOfContents.js | 18 +- src/plugins/htmlVideoPlayer/plugin.js | 6 +- src/plugins/youtubePlayer/plugin.js | 2 +- src/scripts/deleteHelper.js | 4 +- src/scripts/inputManager.js | 2 +- src/scripts/libraryMenu.js | 1 + src/scripts/serverNotifications.js | 1 + src/scripts/site.js | 275 +----- 28 files changed, 652 insertions(+), 709 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index ff12e198c3..a4e972c83e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -44,6 +44,7 @@ module.exports = { 'no-unused-vars': ['error', { 'vars': 'all', 'args': 'none', 'ignoreRestSiblings': true }], 'one-var': ['error', 'never'], 'padded-blocks': ['error', 'never'], + //'prefer-const': ['error', {'destructuring': 'all'}], 'quotes': ['error', 'single', { 'avoidEscape': true, 'allowTemplateLiterals': false }], 'semi': ['error'], 'space-before-blocks': ['error'], diff --git a/package.json b/package.json index bf3ac42f97..744f080124 100644 --- a/package.json +++ b/package.json @@ -95,6 +95,7 @@ "src/components/alert.js", "src/components/alphaPicker/alphaPicker.js", "src/components/appFooter/appFooter.js", + "src/components/appRouter.js", "src/components/autoFocuser.js", "src/components/backdrop/backdrop.js", "src/components/cardbuilder/cardBuilder.js", diff --git a/src/components/actionSheet/actionSheet.js b/src/components/actionSheet/actionSheet.js index 937cd2afe5..be84cf0a06 100644 --- a/src/components/actionSheet/actionSheet.js +++ b/src/components/actionSheet/actionSheet.js @@ -9,14 +9,14 @@ import 'scrollStyles'; import 'listViewStyle'; function getOffsets(elems) { - let results = []; + const results = []; if (!document) { return results; } for (const elem of elems) { - let box = elem.getBoundingClientRect(); + const box = elem.getBoundingClientRect(); results.push({ top: box.top, @@ -34,7 +34,7 @@ function getPosition(options, dlg) { const windowHeight = windowSize.innerHeight; const windowWidth = windowSize.innerWidth; - let pos = getOffsets([options.positionTo])[0]; + const pos = getOffsets([options.positionTo])[0]; if (options.positionY !== 'top') { pos.top += (pos.height || 0) / 2; @@ -82,7 +82,7 @@ export function show(options) { // positionTo // showCancel // title - let dialogOptions = { + const dialogOptions = { removeOnClose: true, enableHistory: options.enableHistory, scrollY: false @@ -103,7 +103,7 @@ export function show(options) { dialogOptions.autoFocus = false; } - let dlg = dialogHelper.createDialog(dialogOptions); + const dlg = dialogHelper.createDialog(dialogOptions); if (isFullscreen) { dlg.classList.add('actionsheet-fullscreen'); @@ -129,7 +129,7 @@ export function show(options) { } let renderIcon = false; - let icons = []; + const icons = []; let itemIcon; for (const item of options.items) { itemIcon = item.icon || (item.selected ? 'check' : null); @@ -241,7 +241,7 @@ export function show(options) { centerFocus(dlg.querySelector('.actionSheetScroller'), false, true); } - let btnCloseActionSheet = dlg.querySelector('.btnCloseActionSheet'); + const btnCloseActionSheet = dlg.querySelector('.btnCloseActionSheet'); if (btnCloseActionSheet) { btnCloseActionSheet.addEventListener('click', function () { dialogHelper.close(dlg); diff --git a/src/components/appRouter.js b/src/components/appRouter.js index da3b08317c..c7495d6460 100644 --- a/src/components/appRouter.js +++ b/src/components/appRouter.js @@ -1,66 +1,294 @@ -define(['loading', 'globalize', 'events', 'viewManager', 'skinManager', 'backdrop', 'browser', 'page', 'appSettings', 'apphost', 'connectionManager'], function (loading, globalize, events, viewManager, skinManager, backdrop, browser, page, appSettings, appHost, connectionManager) { - 'use strict'; +import appHost from 'apphost'; +import appSettings from 'appSettings'; +import backdrop from 'backdrop'; +import browser from 'browser'; +import connectionManager from 'connectionManager'; +import events from 'events'; +import globalize from 'globalize'; +import itemHelper from 'itemHelper'; +import loading from 'loading'; +import page from 'page'; +import viewManager from 'viewManager'; - browser = browser.default || browser; - loading = loading.default || loading; +class AppRouter { + allRoutes = []; + backdropContainer; + backgroundContainer; + currentRouteInfo; + currentViewLoadRequest; + firstConnectionResult; + forcedLogoutMsg; + handleAnchorClick = page.clickHandler; + isDummyBackToHome; + msgTimeout; + popstateOccurred = false; + resolveOnNextShow; + /** + * Pages of "no return" (when "Go back" should behave differently, probably quitting the application). + */ + startPages = ['home', 'login', 'selectserver']; - var appRouter = { - showLocalLogin: function (serverId, manualLogin) { - var pageName = manualLogin ? 'manuallogin' : 'login'; - show('/startup/' + pageName + '.html?serverid=' + serverId); - }, - showSelectServer: function () { - show('/startup/selectserver.html'); - }, - showWelcome: function () { - show('/startup/welcome.html'); - }, - showSettings: function () { - show('/settings/settings.html'); - }, - showNowPlaying: function () { - show('queue'); + constructor() { + window.addEventListener('popstate', () => { + this.popstateOccurred = true; + }); + + document.addEventListener('viewshow', () => { + const resolve = this.resolveOnNextShow; + if (resolve) { + this.resolveOnNextShow = null; + resolve(); + } + }); + + this.baseRoute = self.location.href.split('?')[0].replace(this.getRequestFile(), ''); + // support hashbang + this.baseRoute = this.baseRoute.split('#')[0]; + if (this.baseRoute.endsWith('/') && !this.baseRoute.endsWith('://')) { + this.baseRoute = this.baseRoute.substring(0, this.baseRoute.length - 1); } - }; - function beginConnectionWizard() { - backdrop.clearBackdrop(); + this.setBaseRoute(); + } + + /** + * @private + */ + setBaseRoute() { + let baseRoute = self.location.pathname.replace(this.getRequestFile(), ''); + if (baseRoute.lastIndexOf('/') === baseRoute.length - 1) { + baseRoute = baseRoute.substring(0, baseRoute.length - 1); + } + console.debug('setting page base to ' + baseRoute); + page.base(baseRoute); + } + + addRoute(path, newRoute) { + page(path, this.getHandler(newRoute)); + this.allRoutes.push(newRoute); + } + + showLocalLogin(serverId) { + this.show('login.html?serverid=' + serverId); + } + + showSelectServer() { + this.show(AppInfo.isNativeApp ? 'selectserver.html' : 'login.html'); + } + + showWelcome() { + this.show(AppInfo.isNativeApp ? 'selectserver.html' : 'login.html'); + } + + showSettings() { + this.show('mypreferencesmenu.html'); + } + + showNowPlaying() { + this.show('/nowplaying.html'); + } + + beginConnectionWizard() { + backdrop.clear(); loading.show(); connectionManager.connect({ enableAutoLogin: appSettings.enableAutoLogin() - }).then(function (result) { - handleConnectionResult(result); + }).then((result) => { + this.handleConnectionResult(result); }); } - function handleConnectionResult(result) { + param(name, url) { + name = name.replace(/[[]/, '\\[').replace(/[\]]/, '\\]'); + const regexS = '[\\?&]' + name + '=([^&#]*)'; + const regex = new RegExp(regexS, 'i'); + + const results = regex.exec(url || getWindowLocationSearch()); + if (results == null) { + return ''; + } else { + return decodeURIComponent(results[1].replace(/\+/g, ' ')); + } + } + + back() { + page.back(); + } + + show(path, options) { + if (path.indexOf('/') !== 0 && path.indexOf('://') === -1) { + path = '/' + path; + } + + path = path.replace(this.baseUrl(), ''); + + if (this.currentRouteInfo && this.currentRouteInfo.path === path) { + // can't use this with home right now due to the back menu + if (this.currentRouteInfo.route.type !== 'home') { + loading.hide(); + return Promise.resolve(); + } + } + + return new Promise((resolve) => { + this.resolveOnNextShow = resolve; + page.show(path, options); + }); + } + + showDirect(path) { + return new Promise(function(resolve) { + this.resolveOnNextShow = resolve; + page.show(this.baseUrl() + path); + }); + } + + start(options) { + loading.show(); + this.initApiClients(); + + events.on(appHost, 'beforeexit', this.onBeforeExit); + events.on(appHost, 'resume', this.onAppResume); + + connectionManager.connect({ + enableAutoLogin: appSettings.enableAutoLogin() + }).then((result) => { + this.firstConnectionResult = result; + options = options || {}; + page({ + click: options.click !== false, + hashbang: options.hashbang !== false + }); + }).catch().then(() => { + loading.hide(); + }); + } + + baseUrl() { + return this.baseRoute; + } + + canGoBack() { + const curr = this.current(); + if (!curr) { + return false; + } + + if (!document.querySelector('.dialogContainer') && this.startPages.indexOf(curr.type) !== -1) { + return false; + } + + return history.length > 1; + } + + current() { + return this.currentRouteInfo ? this.currentRouteInfo.route : null; + } + + invokeShortcut(id) { + if (id.indexOf('library-') === 0) { + id = id.replace('library-', ''); + id = id.split('_'); + + this.showItem(id[0], id[1]); + } else if (id.indexOf('item-') === 0) { + id = id.replace('item-', ''); + id = id.split('_'); + this.showItem(id[0], id[1]); + } else { + id = id.split('_'); + this.show(this.getRouteUrl(id[0], { + serverId: id[1] + })); + } + } + + showItem(item, serverId, options) { + // TODO: Refactor this so it only gets items, not strings. + if (typeof (item) === 'string') { + const apiClient = serverId ? connectionManager.getApiClient(serverId) : connectionManager.currentApiClient(); + apiClient.getItem(apiClient.getCurrentUserId(), item).then((itemObject) => { + this.showItem(itemObject, options); + }); + } else { + if (arguments.length === 2) { + options = arguments[1]; + } + + const url = this.getRouteUrl(item, options); + this.show(url, { + item: item + }); + } + } + + setTransparency(level) { + if (!this.backdropContainer) { + this.backdropContainer = document.querySelector('.backdropContainer'); + } + if (!this.backgroundContainer) { + this.backgroundContainer = document.querySelector('.backgroundContainer'); + } + + if (level === 'full' || level === 2) { + backdrop.clear(true); + document.documentElement.classList.add('transparentDocument'); + this.backgroundContainer.classList.add('backgroundContainer-transparent'); + this.backdropContainer.classList.add('hide'); + } else if (level === 'backdrop' || level === 1) { + backdrop.externalBackdrop(true); + document.documentElement.classList.add('transparentDocument'); + this.backgroundContainer.classList.add('backgroundContainer-transparent'); + this.backdropContainer.classList.add('hide'); + } else { + backdrop.externalBackdrop(false); + document.documentElement.classList.remove('transparentDocument'); + this.backgroundContainer.classList.remove('backgroundContainer-transparent'); + this.backdropContainer.classList.remove('hide'); + } + } + + getRoutes() { + return this.allRoutes; + } + + pushState(state, title, url) { + state.navigate = false; + history.pushState(state, title, url); + } + + enableNativeHistory() { + return false; + } + + handleConnectionResult(result) { switch (result.State) { case 'SignedIn': loading.hide(); Emby.Page.goHome(); break; case 'ServerSignIn': - result.ApiClient.getPublicUsers().then(function (users) { + result.ApiClient.getPublicUsers().then((users) => { if (users.length) { - appRouter.showLocalLogin(result.Servers[0].Id); + this.showLocalLogin(result.Servers[0].Id); } else { - appRouter.showLocalLogin(result.Servers[0].Id, true); + this.showLocalLogin(result.Servers[0].Id, true); } }); break; case 'ServerSelection': - appRouter.showSelectServer(); + this.showSelectServer(); break; case 'ConnectSignIn': - appRouter.showWelcome(); + this.showWelcome(); break; case 'ServerUpdateNeeded': - require(['alert'], function (alert) { - alert.default({ + require(['alert'], (alert) => { + alert({ text: globalize.translate('ServerUpdateNeeded', 'https://github.com/jellyfin/jellyfin'), html: globalize.translate('ServerUpdateNeeded', 'https://github.com/jellyfin/jellyfin') - }).then(function () { - appRouter.showSelectServer(); + }).then(() => { + this.showSelectServer(); }); }); break; @@ -69,8 +297,8 @@ define(['loading', 'globalize', 'events', 'viewManager', 'skinManager', 'backdro } } - function loadContentUrl(ctx, next, route, request) { - var url; + loadContentUrl(ctx, next, route, request) { + let url; if (route.contentPath && typeof (route.contentPath) === 'function') { url = route.contentPath(ctx.querystring); } else { @@ -83,27 +311,27 @@ define(['loading', 'globalize', 'events', 'viewManager', 'skinManager', 'backdro url = '/' + url; } - url = baseUrl() + url; + url = this.baseUrl() + url; } if (ctx.querystring && route.enableContentQueryString) { url += '?' + ctx.querystring; } - require(['text!' + url], function (html) { - loadContent(ctx, route, html, request); + require(['text!' + url], (html) => { + this.loadContent(ctx, route, html, request); }); } - function handleRoute(ctx, next, route) { - authenticate(ctx, route, function () { - initRoute(ctx, next, route); + handleRoute(ctx, next, route) { + this.authenticate(ctx, route, () => { + this.initRoute(ctx, next, route); }); } - function initRoute(ctx, next, route) { - var onInitComplete = function (controllerFactory) { - sendRouteToViewManager(ctx, next, route, controllerFactory); + initRoute(ctx, next, route) { + const onInitComplete = (controllerFactory) => { + this.sendRouteToViewManager(ctx, next, route, controllerFactory); }; if (route.controller) { @@ -113,25 +341,24 @@ define(['loading', 'globalize', 'events', 'viewManager', 'skinManager', 'backdro } } - function cancelCurrentLoadRequest() { - var currentRequest = currentViewLoadRequest; + cancelCurrentLoadRequest() { + const currentRequest = this.currentViewLoadRequest; if (currentRequest) { currentRequest.cancel = true; } } - var currentViewLoadRequest; - function sendRouteToViewManager(ctx, next, route, controllerFactory) { - if (isDummyBackToHome && route.type === 'home') { - isDummyBackToHome = false; + sendRouteToViewManager(ctx, next, route, controllerFactory) { + if (this.isDummyBackToHome && route.type === 'home') { + this.isDummyBackToHome = false; return; } - cancelCurrentLoadRequest(); - var isBackNav = ctx.isBack; + this.cancelCurrentLoadRequest(); + const isBackNav = ctx.isBack; - var currentRequest = { - url: baseUrl() + ctx.path, + const currentRequest = { + url: this.baseUrl() + ctx.path, transition: route.transition, isBack: isBackNav, state: ctx.state, @@ -144,11 +371,11 @@ define(['loading', 'globalize', 'events', 'viewManager', 'skinManager', 'backdro }, autoFocus: route.autoFocus }; - currentViewLoadRequest = currentRequest; + this.currentViewLoadRequest = currentRequest; - var onNewViewNeeded = function () { + const onNewViewNeeded = () => { if (typeof route.path === 'string') { - loadContentUrl(ctx, next, route, currentRequest); + this.loadContentUrl(ctx, next, route, currentRequest); } else { next(); } @@ -158,64 +385,62 @@ define(['loading', 'globalize', 'events', 'viewManager', 'skinManager', 'backdro onNewViewNeeded(); return; } - viewManager.tryRestoreView(currentRequest, function () { - currentRouteInfo = { + viewManager.tryRestoreView(currentRequest, () => { + this.currentRouteInfo = { route: route, path: ctx.path }; - }).catch(function (result) { + }).catch((result) => { if (!result || !result.cancelled) { onNewViewNeeded(); } }); } - var msgTimeout; - var forcedLogoutMsg; - function onForcedLogoutMessageTimeout() { - var msg = forcedLogoutMsg; - forcedLogoutMsg = null; + onForcedLogoutMessageTimeout() { + const msg = this.forcedLogoutMsg; + this.forcedLogoutMsg = null; if (msg) { - require(['alert'], function (alert) { + require(['alert'], (alert) => { alert(msg); }); } } - function showForcedLogoutMessage(msg) { - forcedLogoutMsg = msg; - if (msgTimeout) { - clearTimeout(msgTimeout); + showForcedLogoutMessage(msg) { + this.forcedLogoutMsg = msg; + if (this.msgTimeout) { + clearTimeout(this.msgTimeout); } - msgTimeout = setTimeout(onForcedLogoutMessageTimeout, 100); + this.msgTimeout = setTimeout(this.onForcedLogoutMessageTimeout, 100); } - function onRequestFail(e, data) { - var apiClient = this; + onRequestFail(e, data) { + const apiClient = this; if (data.status === 403) { if (data.errorCode === 'ParentalControl') { - var isCurrentAllowed = currentRouteInfo ? (currentRouteInfo.route.anonymous || currentRouteInfo.route.startup) : true; + const isCurrentAllowed = this.currentRouteInfo ? (this.currentRouteInfo.route.anonymous || this.currentRouteInfo.route.startup) : true; // Bounce to the login screen, but not if a password entry fails, obviously if (!isCurrentAllowed) { - showForcedLogoutMessage(globalize.translate('AccessRestrictedTryAgainLater')); - appRouter.showLocalLogin(apiClient.serverId()); + this.showForcedLogoutMessage(globalize.translate('AccessRestrictedTryAgainLater')); + this.showLocalLogin(apiClient.serverId()); } } } } - function onBeforeExit(e) { + onBeforeExit() { if (browser.web0s) { page.restorePreviousState(); } } - function normalizeImageOptions(options) { - var setQuality; + normalizeImageOptions(options) { + let setQuality; if (options.maxWidth || options.width || options.maxHeight || options.height) { setQuality = true; } @@ -225,10 +450,10 @@ define(['loading', 'globalize', 'events', 'viewManager', 'skinManager', 'backdro } } - function getMaxBandwidth() { + getMaxBandwidth() { /* eslint-disable compat/compat */ if (navigator.connection) { - var max = navigator.connection.downlinkMax; + let max = navigator.connection.downlinkMax; if (max && max > 0 && max < Number.POSITIVE_INFINITY) { max /= 8; max *= 1000000; @@ -241,90 +466,65 @@ define(['loading', 'globalize', 'events', 'viewManager', 'skinManager', 'backdro return null; } - function getMaxBandwidthIOS() { + getMaxBandwidthIOS() { return 800000; } - function onApiClientCreated(e, newApiClient) { - newApiClient.normalizeImageOptions = normalizeImageOptions; + onApiClientCreated(e, newApiClient) { + newApiClient.normalizeImageOptions = this.normalizeImageOptions; if (browser.iOS) { - newApiClient.getMaxBandwidth = getMaxBandwidthIOS; + newApiClient.getMaxBandwidth = this.getMaxBandwidthIOS; } else { - newApiClient.getMaxBandwidth = getMaxBandwidth; + newApiClient.getMaxBandwidth = this.getMaxBandwidth; } - events.off(newApiClient, 'requestfail', onRequestFail); - events.on(newApiClient, 'requestfail', onRequestFail); + events.off(newApiClient, 'requestfail', this.onRequestFail); + events.on(newApiClient, 'requestfail', this.onRequestFail); } - function initApiClient(apiClient) { - onApiClientCreated({}, apiClient); + initApiClient(apiClient, instance) { + instance.onApiClientCreated({}, apiClient); } - function initApiClients() { - connectionManager.getApiClients().forEach(initApiClient); + initApiClients() { + connectionManager.getApiClients().forEach((apiClient) => { + this.initApiClient(apiClient, this); + }); - events.on(connectionManager, 'apiclientcreated', onApiClientCreated); + events.on(connectionManager, 'apiclientcreated', this.onApiClientCreated); } - function onAppResume() { - var apiClient = connectionManager.currentApiClient(); + onAppResume() { + const apiClient = connectionManager.currentApiClient(); if (apiClient) { apiClient.ensureWebSocket(); } } - var firstConnectionResult; - function start(options) { - loading.show(); - - initApiClients(); - - events.on(appHost, 'beforeexit', onBeforeExit); - events.on(appHost, 'resume', onAppResume); - - connectionManager.connect({ - enableAutoLogin: appSettings.enableAutoLogin() - }).then(function (result) { - firstConnectionResult = result; - options = options || {}; - page({ - click: options.click !== false, - hashbang: options.hashbang !== false - }); - }).catch().then(function() { - loading.hide(); - }); - } - - function enableNativeHistory() { - return false; - } - - function authenticate(ctx, route, callback) { - var firstResult = firstConnectionResult; + authenticate(ctx, route, callback) { + const firstResult = this.firstConnectionResult; if (firstResult) { - firstConnectionResult = null; + this.firstConnectionResult = null; if (firstResult.State !== 'SignedIn' && !route.anonymous) { - handleConnectionResult(firstResult); + this.handleConnectionResult(firstResult); return; } } - var apiClient = connectionManager.currentApiClient(); - var pathname = ctx.pathname.toLowerCase(); + const apiClient = connectionManager.currentApiClient(); + const pathname = ctx.pathname.toLowerCase(); console.debug('appRouter - processing path request ' + pathname); - var isCurrentRouteStartup = currentRouteInfo ? currentRouteInfo.route.startup : true; - var shouldExitApp = ctx.isBack && route.isDefaultRoute && isCurrentRouteStartup; + const isCurrentRouteStartup = this.currentRouteInfo ? this.currentRouteInfo.route.startup : true; + const shouldExitApp = ctx.isBack && route.isDefaultRoute && isCurrentRouteStartup; if (!shouldExitApp && (!apiClient || !apiClient.isLoggedIn()) && !route.anonymous) { console.debug('appRouter - route does not allow anonymous access, redirecting to login'); - beginConnectionWizard(); + this.beginConnectionWizard(); return; } @@ -344,9 +544,9 @@ define(['loading', 'globalize', 'events', 'viewManager', 'skinManager', 'backdro Emby.Page.goHome(); return; } else if (route.roles) { - validateRoles(apiClient, route.roles).then(function () { + this.validateRoles(apiClient, route.roles).then(() => { callback(); - }, beginConnectionWizard); + }, this.beginConnectionWizard); return; } } @@ -355,15 +555,15 @@ define(['loading', 'globalize', 'events', 'viewManager', 'skinManager', 'backdro callback(); } - function validateRoles(apiClient, roles) { - return Promise.all(roles.split(',').map(function (role) { - return validateRole(apiClient, role); + validateRoles(apiClient, roles) { + return Promise.all(roles.split(',').map((role) => { + return this.validateRole(apiClient, role); })); } - function validateRole(apiClient, role) { + validateRole(apiClient, role) { if (role === 'admin') { - return apiClient.getCurrentUser().then(function (user) { + return apiClient.getCurrentUser().then((user) => { if (user.Policy.IsAdministrator) { return Promise.resolve(); } @@ -375,15 +575,13 @@ define(['loading', 'globalize', 'events', 'viewManager', 'skinManager', 'backdro return Promise.resolve(); } - var isDummyBackToHome; - - function loadContent(ctx, route, html, request) { + loadContent(ctx, route, html, request) { html = globalize.translateHtml(html, route.dictionary); request.view = html; viewManager.loadView(request); - currentRouteInfo = { + this.currentRouteInfo = { route: route, path: ctx.path }; @@ -391,10 +589,10 @@ define(['loading', 'globalize', 'events', 'viewManager', 'skinManager', 'backdro ctx.handled = true; } - function getRequestFile() { - var path = self.location.pathname || ''; + getRequestFile() { + let path = self.location.pathname || ''; - var index = path.lastIndexOf('/'); + const index = path.lastIndexOf('/'); if (index !== -1) { path = path.substring(index); } else { @@ -408,39 +606,19 @@ define(['loading', 'globalize', 'events', 'viewManager', 'skinManager', 'backdro return path; } - function endsWith(str, srch) { - return str.lastIndexOf(srch) === srch.length - 1; - } - - var baseRoute = self.location.href.split('?')[0].replace(getRequestFile(), ''); - // support hashbang - baseRoute = baseRoute.split('#')[0]; - if (endsWith(baseRoute, '/') && !endsWith(baseRoute, '://')) { - baseRoute = baseRoute.substring(0, baseRoute.length - 1); - } - - function baseUrl() { - return baseRoute; - } - - var popstateOccurred = false; - window.addEventListener('popstate', function () { - popstateOccurred = true; - }); - - function getHandler(route) { - return function (ctx, next) { - ctx.isBack = popstateOccurred; - handleRoute(ctx, next, route); - popstateOccurred = false; + getHandler(route) { + return (ctx, next) => { + ctx.isBack = this.popstateOccurred; + this.handleRoute(ctx, next, route); + this.popstateOccurred = false; }; } - function getWindowLocationSearch(win) { - var currentPath = currentRouteInfo ? (currentRouteInfo.path || '') : ''; + getWindowLocationSearch() { + const currentPath = this.currentRouteInfo ? (this.currentRouteInfo.path || '') : ''; - var index = currentPath.indexOf('?'); - var search = ''; + const index = currentPath.indexOf('?'); + let search = ''; if (index !== -1) { search = currentPath.substring(index); @@ -449,199 +627,218 @@ define(['loading', 'globalize', 'events', 'viewManager', 'skinManager', 'backdro return search || ''; } - function param(name, url) { - name = name.replace(/[\[]/, '\\\[').replace(/[\]]/, '\\\]'); - var regexS = '[\\?&]' + name + '=([^&#]*)'; - var regex = new RegExp(regexS, 'i'); - - var results = regex.exec(url || getWindowLocationSearch()); - if (results == null) { - return ''; - } else { - return decodeURIComponent(results[1].replace(/\+/g, ' ')); - } + showGuide() { + this.show('livetv.html?tab=1'); } - function back() { - page.back(); + goHome() { + this.show('home.html'); } - /** - * Pages of "no return" (when "Go back" should behave differently, probably quitting the application). - */ - var startPages = ['home', 'login', 'selectserver']; - - function canGoBack() { - var curr = current(); - if (!curr) { - return false; - } - - if (!document.querySelector('.dialogContainer') && startPages.indexOf(curr.type) !== -1) { - return false; - } - - return (page.len || 0) > 0; + showSearch() { + this.show('search.html'); } - function showDirect(path) { - return new Promise(function(resolve, reject) { - resolveOnNextShow = resolve; - page.show(baseUrl() + path); - }); + showLiveTV() { + this.show('livetv.html'); } - function show(path, options) { - if (path.indexOf('/') !== 0 && path.indexOf('://') === -1) { - path = '/' + path; + showRecordedTV() { + this.show('livetv.html?tab=3'); + } + + showFavorites() { + this.show('home.html?tab=1'); + } + + setTitle(title) { + LibraryMenu.setTitle(title); + } + + getRouteUrl(item, options) { + if (!item) { + throw new Error('item cannot be null'); } - path = path.replace(baseUrl(), ''); + if (item.url) { + return item.url; + } - if (currentRouteInfo && currentRouteInfo.path === path) { - // can't use this with home right now due to the back menu - if (currentRouteInfo.route.type !== 'home') { - loading.hide(); - return Promise.resolve(); + const context = options ? options.context : null; + const id = item.Id || item.ItemId; + + if (!options) { + options = {}; + } + + let url; + // TODO: options will never be false. Replace condition with lodash's isEmpty() + const itemType = item.Type || (options ? options.itemType : null); + const serverId = item.ServerId || options.serverId; + + if (item === 'settings') { + return 'mypreferencesmenu.html'; + } + + if (item === 'wizard') { + return 'wizardstart.html'; + } + + if (item === 'manageserver') { + return 'dashboard.html'; + } + + if (item === 'recordedtv') { + return 'livetv.html?tab=3&serverId=' + options.serverId; + } + + if (item === 'nextup') { + return 'list.html?type=nextup&serverId=' + options.serverId; + } + + if (item === 'list') { + let url = 'list.html?serverId=' + options.serverId + '&type=' + options.itemTypes; + + if (options.isFavorite) { + url += '&IsFavorite=true'; + } + + return url; + } + + if (item === 'livetv') { + if (options.section === 'programs') { + return 'livetv.html?tab=0&serverId=' + options.serverId; + } + if (options.section === 'guide') { + return 'livetv.html?tab=1&serverId=' + options.serverId; + } + + if (options.section === 'movies') { + return 'list.html?type=Programs&IsMovie=true&serverId=' + options.serverId; + } + + if (options.section === 'shows') { + return 'list.html?type=Programs&IsSeries=true&IsMovie=false&IsNews=false&serverId=' + options.serverId; + } + + if (options.section === 'sports') { + return 'list.html?type=Programs&IsSports=true&serverId=' + options.serverId; + } + + if (options.section === 'kids') { + return 'list.html?type=Programs&IsKids=true&serverId=' + options.serverId; + } + + if (options.section === 'news') { + return 'list.html?type=Programs&IsNews=true&serverId=' + options.serverId; + } + + if (options.section === 'onnow') { + return 'list.html?type=Programs&IsAiring=true&serverId=' + options.serverId; + } + + if (options.section === 'dvrschedule') { + return 'livetv.html?tab=4&serverId=' + options.serverId; + } + + if (options.section === 'seriesrecording') { + return 'livetv.html?tab=5&serverId=' + options.serverId; + } + + return 'livetv.html?serverId=' + options.serverId; + } + + if (itemType == 'SeriesTimer') { + return 'details?seriesTimerId=' + id + '&serverId=' + serverId; + } + + if (item.CollectionType == 'livetv') { + return 'livetv.html'; + } + + if (item.Type === 'Genre') { + url = 'list.html?genreId=' + item.Id + '&serverId=' + serverId; + + if (context === 'livetv') { + url += '&type=Programs'; + } + + if (options.parentId) { + url += '&parentId=' + options.parentId; + } + + return url; + } + + if (item.Type === 'MusicGenre') { + url = 'list.html?musicGenreId=' + item.Id + '&serverId=' + serverId; + + if (options.parentId) { + url += '&parentId=' + options.parentId; + } + + return url; + } + + if (item.Type === 'Studio') { + url = 'list.html?studioId=' + item.Id + '&serverId=' + serverId; + + if (options.parentId) { + url += '&parentId=' + options.parentId; + } + + return url; + } + + if (context !== 'folders' && !itemHelper.isLocalItem(item)) { + if (item.CollectionType == 'movies') { + url = 'movies.html?topParentId=' + item.Id; + + if (options && options.section === 'latest') { + url += '&tab=1'; + } + + return url; + } + + if (item.CollectionType == 'tvshows') { + url = 'tv.html?topParentId=' + item.Id; + + if (options && options.section === 'latest') { + url += '&tab=2'; + } + + return url; + } + + if (item.CollectionType == 'music') { + return 'music.html?topParentId=' + item.Id; } } - return new Promise(function (resolve, reject) { - resolveOnNextShow = resolve; - page.show(path, options); - }); - } + const itemTypes = ['Playlist', 'TvChannel', 'Program', 'BoxSet', 'MusicAlbum', 'MusicGenre', 'Person', 'Recording', 'MusicArtist']; - var resolveOnNextShow; - document.addEventListener('viewshow', function () { - var resolve = resolveOnNextShow; - if (resolve) { - resolveOnNextShow = null; - resolve(); + if (itemTypes.indexOf(itemType) >= 0) { + return 'details?id=' + id + '&serverId=' + serverId; } - }); - var currentRouteInfo; - function current() { - return currentRouteInfo ? currentRouteInfo.route : null; - } + const contextSuffix = context ? '&context=' + context : ''; - function showItem(item, serverId, options) { - // TODO: Refactor this so it only gets items, not strings. - if (typeof (item) === 'string') { - var apiClient = serverId ? connectionManager.getApiClient(serverId) : connectionManager.currentApiClient(); - apiClient.getItem(apiClient.getCurrentUserId(), item).then(function (itemObject) { - appRouter.showItem(itemObject, options); - }); - } else { - if (arguments.length === 2) { - options = arguments[1]; + if (itemType == 'Series' || itemType == 'Season' || itemType == 'Episode') { + return 'details?id=' + id + contextSuffix + '&serverId=' + serverId; + } + + if (item.IsFolder) { + if (id) { + return 'list.html?parentId=' + id + '&serverId=' + serverId; } - var url = appRouter.getRouteUrl(item, options); - appRouter.show(url, { - item: item - }); - } - } - - var allRoutes = []; - - function addRoute(path, newRoute) { - page(path, getHandler(newRoute)); - allRoutes.push(newRoute); - } - - function getRoutes() { - return allRoutes; - } - - var backdropContainer; - var backgroundContainer; - function setTransparency(level) { - if (!backdropContainer) { - backdropContainer = document.querySelector('.backdropContainer'); - } - if (!backgroundContainer) { - backgroundContainer = document.querySelector('.backgroundContainer'); + return '#'; } - if (level === 'full' || level === 2) { - backdrop.clearBackdrop(true); - document.documentElement.classList.add('transparentDocument'); - backgroundContainer.classList.add('backgroundContainer-transparent'); - backdropContainer.classList.add('hide'); - } else if (level === 'backdrop' || level === 1) { - backdrop.externalBackdrop(true); - document.documentElement.classList.add('transparentDocument'); - backgroundContainer.classList.add('backgroundContainer-transparent'); - backdropContainer.classList.add('hide'); - } else { - backdrop.externalBackdrop(false); - document.documentElement.classList.remove('transparentDocument'); - backgroundContainer.classList.remove('backgroundContainer-transparent'); - backdropContainer.classList.remove('hide'); - } + return 'details?id=' + id + '&serverId=' + serverId; } +} - function pushState(state, title, url) { - state.navigate = false; - history.pushState(state, title, url); - } - - function setBaseRoute() { - var baseRoute = self.location.pathname.replace(getRequestFile(), ''); - if (baseRoute.lastIndexOf('/') === baseRoute.length - 1) { - baseRoute = baseRoute.substring(0, baseRoute.length - 1); - } - - console.debug('setting page base to ' + baseRoute); - page.base(baseRoute); - } - - setBaseRoute(); - - function invokeShortcut(id) { - if (id.indexOf('library-') === 0) { - id = id.replace('library-', ''); - id = id.split('_'); - - appRouter.showItem(id[0], id[1]); - } else if (id.indexOf('item-') === 0) { - id = id.replace('item-', ''); - id = id.split('_'); - - appRouter.showItem(id[0], id[1]); - } else { - id = id.split('_'); - appRouter.show(appRouter.getRouteUrl(id[0], { - serverId: id[1] - })); - } - } - - appRouter.addRoute = addRoute; - appRouter.param = param; - appRouter.back = back; - appRouter.show = show; - appRouter.showDirect = showDirect; - appRouter.start = start; - appRouter.baseUrl = baseUrl; - appRouter.canGoBack = canGoBack; - appRouter.current = current; - appRouter.beginConnectionWizard = beginConnectionWizard; - appRouter.invokeShortcut = invokeShortcut; - appRouter.showItem = showItem; - appRouter.setTransparency = setTransparency; - appRouter.getRoutes = getRoutes; - appRouter.pushState = pushState; - appRouter.enableNativeHistory = enableNativeHistory; - appRouter.handleAnchorClick = page.clickHandler; - appRouter.TransparencyLevel = { - None: 0, - Backdrop: 1, - Full: 2 - }; - - return appRouter; -}); +export default new AppRouter(); diff --git a/src/components/cardbuilder/cardBuilder.js b/src/components/cardbuilder/cardBuilder.js index 4a37331ef4..e644365906 100644 --- a/src/components/cardbuilder/cardBuilder.js +++ b/src/components/cardbuilder/cardBuilder.js @@ -362,12 +362,12 @@ import 'programStyles'; let hasOpenRow; let hasOpenSection; - let sectionTitleTagName = options.sectionTitleTagName || 'div'; + const sectionTitleTagName = options.sectionTitleTagName || 'div'; let apiClient; let lastServerId; for (const [i, item] of items.entries()) { - let serverId = item.ServerId || options.serverId; + const serverId = item.ServerId || options.serverId; if (serverId !== lastServerId) { lastServerId = serverId; @@ -621,7 +621,7 @@ import 'programStyles'; }); } - let blurHashes = options.imageBlurhashes || item.ImageBlurHashes || {}; + const blurHashes = options.imageBlurhashes || item.ImageBlurHashes || {}; return { imgUrl: imgUrl, @@ -656,7 +656,7 @@ import 'programStyles'; for (let i = 0; i < character.length; i++) { sum += parseInt(character.charAt(i)); } - let index = String(sum).substr(-1); + const index = String(sum).substr(-1); return (index % numRandomColors) + 1; } else { @@ -682,7 +682,7 @@ import 'programStyles'; for (let i = 0; i < lines.length; i++) { let currentCssClass = cssClass; - let text = lines[i]; + const text = lines[i]; if (valid > 0 && isOuterFooter) { currentCssClass += ' cardText-secondary'; @@ -707,7 +707,7 @@ import 'programStyles'; } if (forceLines) { - let linesLength = maxLines || Math.min(lines.length, maxLines || lines.length); + const linesLength = maxLines || Math.min(lines.length, maxLines || lines.length); while (valid < linesLength) { html += "
 
"; @@ -1036,7 +1036,7 @@ import 'programStyles'; * @returns {string} HTML markup for the item count indicator. */ function getItemCountsHtml(options, item) { - let counts = []; + const counts = []; let childText; if (item.Type === 'Playlist') { @@ -1318,7 +1318,7 @@ import 'programStyles'; let cardBoxClose = ''; let cardScalableClose = ''; - let cardContentClass = 'cardContent'; + const cardContentClass = 'cardContent'; let blurhashAttrib = ''; if (blurhash && blurhash.length > 0) { @@ -1337,7 +1337,7 @@ import 'programStyles'; cardImageContainerClose = ''; } - let cardScalableClass = 'cardScalable'; + const cardScalableClass = 'cardScalable'; cardImageContainerOpen = '
' + cardImageContainerOpen; cardBoxClose = '
'; @@ -1681,7 +1681,7 @@ import 'programStyles'; const cells = itemsContainer.querySelectorAll('.card[data-id="' + programId + '"]'); for (let i = 0, length = cells.length; i < length; i++) { - let cell = cells[i]; + const cell = cells[i]; const icon = cell.querySelector('.timerIndicator'); if (!icon) { const indicatorsElem = ensureIndicators(cell); @@ -1700,8 +1700,8 @@ import 'programStyles'; const cells = itemsContainer.querySelectorAll('.card[data-timerid="' + timerId + '"]'); for (let i = 0; i < cells.length; i++) { - let cell = cells[i]; - let icon = cell.querySelector('.timerIndicator'); + const cell = cells[i]; + const icon = cell.querySelector('.timerIndicator'); if (icon) { icon.parentNode.removeChild(icon); } @@ -1718,8 +1718,8 @@ import 'programStyles'; const cells = itemsContainer.querySelectorAll('.card[data-seriestimerid="' + cancelledTimerId + '"]'); for (let i = 0; i < cells.length; i++) { - let cell = cells[i]; - let icon = cell.querySelector('.timerIndicator'); + const cell = cells[i]; + const icon = cell.querySelector('.timerIndicator'); if (icon) { icon.parentNode.removeChild(icon); } diff --git a/src/components/dialogHelper/dialogHelper.js b/src/components/dialogHelper/dialogHelper.js index 1f11d8a195..a9ca595c30 100644 --- a/src/components/dialogHelper/dialogHelper.js +++ b/src/components/dialogHelper/dialogHelper.js @@ -375,7 +375,7 @@ import 'scrollStyles'; dlg.setAttribute('data-lockscroll', 'true'); } - if (options.enableHistory !== false && appRouter.enableNativeHistory()) { + if (options.enableHistory !== false) { dlg.setAttribute('data-history', 'true'); } @@ -391,11 +391,8 @@ import 'scrollStyles'; dlg.setAttribute('data-autofocus', 'true'); } - let defaultEntryAnimation; - let defaultExitAnimation; - - defaultEntryAnimation = 'scaleup'; - defaultExitAnimation = 'scaledown'; + const defaultEntryAnimation = 'scaleup'; + const defaultExitAnimation = 'scaledown'; const entryAnimation = options.entryAnimation || defaultEntryAnimation; const exitAnimation = options.exitAnimation || defaultExitAnimation; diff --git a/src/components/filtermenu/filtermenu.js b/src/components/filtermenu/filtermenu.js index b02b5fb9f8..b976ea3f90 100644 --- a/src/components/filtermenu/filtermenu.js +++ b/src/components/filtermenu/filtermenu.js @@ -2,6 +2,8 @@ define(['require', 'dom', 'focusManager', 'dialogHelper', 'loading', 'apphost', 'use strict'; focusManager = focusManager.default || focusManager; + appRouter = appRouter.default || appRouter; + function onSubmit(e) { e.preventDefault(); return false; diff --git a/src/components/images/imageLoader.js b/src/components/images/imageLoader.js index 0effcc7a57..39dc6c2622 100644 --- a/src/components/images/imageLoader.js +++ b/src/components/images/imageLoader.js @@ -17,8 +17,8 @@ import 'css!./style'; // Although the default values recommended by Blurhash developers is 32x32, a size of 18x18 seems to be the sweet spot for us, // improving the performance and reducing the memory usage, while retaining almost full blur quality. // Lower values had more visible pixelation - let width = 18; - let height = 18; + const width = 18; + const height = 18; let pixels; try { pixels = blurhash.decode(blurhashstr, width, height); @@ -27,11 +27,11 @@ import 'css!./style'; target.classList.add('non-blurhashable'); return; } - let canvas = document.createElement('canvas'); + const canvas = document.createElement('canvas'); canvas.width = width; canvas.height = height; - let ctx = canvas.getContext('2d'); - let imgData = ctx.createImageData(width, height); + const ctx = canvas.getContext('2d'); + const imgData = ctx.createImageData(width, height); imgData.data.set(pixels); ctx.putImageData(imgData, 0, 0); @@ -55,7 +55,7 @@ import 'css!./style'; if (!entry) { throw new Error('entry cannot be null'); } - let target = entry.target; + const target = entry.target; var source = undefined; if (target) { @@ -78,7 +78,7 @@ import 'css!./style'; throw new TypeError('url cannot be undefined'); } - let preloaderImg = new Image(); + const preloaderImg = new Image(); preloaderImg.src = url; elem.classList.add('lazy-hidden'); diff --git a/src/components/indicators/indicators.js b/src/components/indicators/indicators.js index 604f480f1d..bbd672ef72 100644 --- a/src/components/indicators/indicators.js +++ b/src/components/indicators/indicators.js @@ -82,7 +82,7 @@ export function enablePlayedIndicator(item) { export function getPlayedIndicatorHtml(item) { if (enablePlayedIndicator(item)) { - let userData = item.UserData || {}; + const userData = item.UserData || {}; if (userData.UnplayedItemCount) { return '
' + userData.UnplayedItemCount + '
'; } diff --git a/src/components/itemContextMenu.js b/src/components/itemContextMenu.js index 173383d064..a42a7537a1 100644 --- a/src/components/itemContextMenu.js +++ b/src/components/itemContextMenu.js @@ -8,7 +8,6 @@ import browser from 'browser'; import actionsheet from 'actionsheet'; /* eslint-disable indent */ - export function getCommands(options) { const item = options.item; const user = options.user; @@ -16,7 +15,7 @@ import actionsheet from 'actionsheet'; const canPlay = playbackManager.canPlay(item); const restrictOptions = (browser.operaTv || browser.web0s) && !user.Policy.IsAdministrator; - let commands = []; + const commands = []; if (canPlay && item.MediaType !== 'Photo') { if (options.play !== false) { @@ -367,7 +366,7 @@ import actionsheet from 'actionsheet'; case 'copy-stream': { const downloadHref = apiClient.getItemDownloadUrl(itemId); const textAreaCopy = function () { - let textArea = document.createElement('textarea'); + const textArea = document.createElement('textarea'); textArea.value = downloadHref; document.body.appendChild(textArea); textArea.focus(); diff --git a/src/components/mediainfo/mediainfo.js b/src/components/mediainfo/mediainfo.js index 53982040b8..4ead1c4dd8 100644 --- a/src/components/mediainfo/mediainfo.js +++ b/src/components/mediainfo/mediainfo.js @@ -9,7 +9,6 @@ import 'programStyles'; import 'emby-button'; /* eslint-disable indent */ - function getTimerIndicator(item) { let status; diff --git a/src/components/metadataEditor/metadataEditor.js b/src/components/metadataEditor/metadataEditor.js index be44e86b44..3dbf5c4264 100644 --- a/src/components/metadataEditor/metadataEditor.js +++ b/src/components/metadataEditor/metadataEditor.js @@ -247,7 +247,7 @@ import 'flexStyles'; reload(context, parentId, item.ServerId); } else { require(['appRouter'], function (appRouter) { - appRouter.goHome(); + appRouter.default.goHome(); }); } } diff --git a/src/components/nowPlayingBar/nowPlayingBar.js b/src/components/nowPlayingBar/nowPlayingBar.js index d411dcc620..7aa8c623b3 100644 --- a/src/components/nowPlayingBar/nowPlayingBar.js +++ b/src/components/nowPlayingBar/nowPlayingBar.js @@ -500,20 +500,20 @@ import 'emby-ratingbutton'; const textLines = nowPlayingItem ? nowPlayingHelper.getNowPlayingNames(nowPlayingItem) : []; nowPlayingTextElement.innerHTML = ''; if (textLines) { - let itemText = document.createElement('div'); - let secondaryText = document.createElement('div'); + const itemText = document.createElement('div'); + const secondaryText = document.createElement('div'); secondaryText.classList.add('nowPlayingBarSecondaryText'); if (textLines.length > 1) { textLines[1].secondary = true; if (textLines[1].text) { - let text = document.createElement('a'); + const text = document.createElement('a'); text.innerHTML = textLines[1].text; secondaryText.appendChild(text); } } if (textLines[0].text) { - let text = document.createElement('a'); + const text = document.createElement('a'); text.innerHTML = textLines[0].text; itemText.appendChild(text); } @@ -555,10 +555,10 @@ import 'emby-ratingbutton'; if (!layoutManager.mobile) { let contextButton = nowPlayingBarElement.querySelector('.btnToggleContextMenu'); // We remove the previous event listener by replacing the item in each update event - let contextButtonClone = contextButton.cloneNode(true); + const contextButtonClone = contextButton.cloneNode(true); contextButton.parentNode.replaceChild(contextButtonClone, contextButton); contextButton = nowPlayingBarElement.querySelector('.btnToggleContextMenu'); - let options = { + const options = { play: false, queue: false, clearQueue: true, @@ -600,10 +600,10 @@ import 'emby-ratingbutton'; return; } - let shuffleMode = playbackManager.getQueueShuffleMode(); - let context = nowPlayingBarElement; + const shuffleMode = playbackManager.getQueueShuffleMode(); + const context = nowPlayingBarElement; const cssClass = 'buttonActive'; - let toggleShuffleButton = context.querySelector('.btnShuffleQueue'); + const toggleShuffleButton = context.querySelector('.btnShuffleQueue'); switch (shuffleMode) { case 'Shuffle': toggleShuffleButton.classList.add(cssClass); diff --git a/src/components/playback/mediasession.js b/src/components/playback/mediasession.js index 0f275c88f7..5c7ddf45dd 100644 --- a/src/components/playback/mediasession.js +++ b/src/components/playback/mediasession.js @@ -127,7 +127,7 @@ import connectionManager from 'connectionManager'; artwork: getImageUrls(item) }); } else { - let itemImageUrl = seriesImageUrl(item, { maxHeight: 3000 }) || imageUrl(item, { maxHeight: 3000 }); + const itemImageUrl = seriesImageUrl(item, { maxHeight: 3000 }) || imageUrl(item, { maxHeight: 3000 }); window.NativeShell.updateMediaSession({ action: eventName, @@ -244,10 +244,10 @@ import connectionManager from 'connectionManager'; /* eslint-disable-next-line compat/compat */ navigator.mediaSession.setActionHandler('seekto', function (object) { - let item = playbackManager.getPlayerState(currentPlayer).NowPlayingItem; + const item = playbackManager.getPlayerState(currentPlayer).NowPlayingItem; // Convert to ms - let duration = parseInt(item.RunTimeTicks ? (item.RunTimeTicks / 10000) : 0); - let wantedTime = object.seekTime * 1000; + const duration = parseInt(item.RunTimeTicks ? (item.RunTimeTicks / 10000) : 0); + const wantedTime = object.seekTime * 1000; playbackManager.seekPercent(wantedTime / duration * 100, currentPlayer); }); } diff --git a/src/components/remotecontrol/remotecontrol.js b/src/components/remotecontrol/remotecontrol.js index b5ac4c9a8b..363eb5ab00 100644 --- a/src/components/remotecontrol/remotecontrol.js +++ b/src/components/remotecontrol/remotecontrol.js @@ -127,8 +127,8 @@ define(['browser', 'datetime', 'backdrop', 'libraryBrowser', 'listView', 'imageL if (item.Artists != null) { if (item.ArtistItems != null) { for (const artist of item.ArtistItems) { - let artistName = artist.Name; - let artistId = artist.Id; + const artistName = artist.Name; + const artistId = artist.Id; artistsSeries += `${artistName}`; if (artist !== item.ArtistItems.slice(-1)[0]) { artistsSeries += ', '; @@ -185,7 +185,7 @@ define(['browser', 'datetime', 'backdrop', 'libraryBrowser', 'listView', 'imageL let contextButton = context.querySelector('.btnToggleContextMenu'); // We remove the previous event listener by replacing the item in each update event const autoFocusContextButton = document.activeElement === contextButton; - let contextButtonClone = contextButton.cloneNode(true); + const contextButtonClone = contextButton.cloneNode(true); contextButton.parentNode.replaceChild(contextButtonClone, contextButton); contextButton = context.querySelector('.btnToggleContextMenu'); if (autoFocusContextButton) { @@ -362,7 +362,7 @@ define(['browser', 'datetime', 'backdrop', 'libraryBrowser', 'listView', 'imageL function updateRepeatModeDisplay(repeatMode) { var context = dlg; - let toggleRepeatButtons = context.querySelectorAll('.repeatToggleButton'); + const toggleRepeatButtons = context.querySelectorAll('.repeatToggleButton'); const cssClass = 'buttonActive'; let innHtml = ''; let repeatOn = true; @@ -529,12 +529,12 @@ define(['browser', 'datetime', 'backdrop', 'libraryBrowser', 'listView', 'imageL } function onShuffleQueueModeChange(updateView = true) { - let shuffleMode = playbackManager.getQueueShuffleMode(this); - let context = dlg; + const shuffleMode = playbackManager.getQueueShuffleMode(this); + const context = dlg; const cssClass = 'buttonActive'; - let shuffleButtons = context.querySelectorAll('.btnShuffleQueue'); + const shuffleButtons = context.querySelectorAll('.btnShuffleQueue'); - for (let shuffleButton of shuffleButtons) { + for (const shuffleButton of shuffleButtons) { switch (shuffleMode) { case 'Shuffle': shuffleButton.classList.add(cssClass); @@ -877,7 +877,7 @@ define(['browser', 'datetime', 'backdrop', 'libraryBrowser', 'listView', 'imageL volumecontrolHtml += ``; volumecontrolHtml += '
'; volumecontrolHtml += '
'; - let optionsSection = context.querySelector('.playlistSectionButton'); + const optionsSection = context.querySelector('.playlistSectionButton'); if (!layoutManager.mobile) { context.querySelector('.nowPlayingSecondaryButtons').insertAdjacentHTML('beforeend', volumecontrolHtml); optionsSection.classList.remove('align-items-center', 'justify-content-center'); diff --git a/src/components/scrollManager.js b/src/components/scrollManager.js index 4ee31a6275..549cb9445c 100644 --- a/src/components/scrollManager.js +++ b/src/components/scrollManager.js @@ -251,7 +251,7 @@ import layoutManager from 'layoutManager'; * @return {ScrollerData} Scroller data. */ function getScrollerData(scroller, vertical) { - let data = {}; + const data = {}; if (!vertical) { data.scrollPos = scroller.scrollLeft; diff --git a/src/components/viewSettings/viewSettings.js b/src/components/viewSettings/viewSettings.js index 67abc25a9c..0427618f26 100644 --- a/src/components/viewSettings/viewSettings.js +++ b/src/components/viewSettings/viewSettings.js @@ -1,6 +1,8 @@ define(['require', 'dialogHelper', 'loading', 'apphost', 'layoutManager', 'connectionManager', 'appRouter', 'globalize', 'userSettings', 'emby-checkbox', 'emby-input', 'paper-icon-button-light', 'emby-select', 'material-icons', 'css!./../formdialog', 'emby-button', 'flexStyles'], function (require, dialogHelper, loading, appHost, layoutManager, connectionManager, appRouter, globalize, userSettings) { 'use strict'; + appRouter = appRouter.default || appRouter; + function onSubmit(e) { e.preventDefault(); return false; diff --git a/src/controllers/dashboard/plugins/repositories/index.js b/src/controllers/dashboard/plugins/repositories/index.js index 3087cdd927..25cbbac38a 100644 --- a/src/controllers/dashboard/plugins/repositories/index.js +++ b/src/controllers/dashboard/plugins/repositories/index.js @@ -105,7 +105,7 @@ export default function(view, params) { }); view.querySelector('.btnNewRepository').addEventListener('click', () => { - let dialog = dialogHelper.createDialog({ + const dialog = dialogHelper.createDialog({ scrollY: false, size: 'large', modal: false, diff --git a/src/controllers/playback/video/index.js b/src/controllers/playback/video/index.js index a8bd0e01f3..8f46d24f0e 100644 --- a/src/controllers/playback/video/index.js +++ b/src/controllers/playback/video/index.js @@ -172,9 +172,7 @@ import 'css!assets/css/videoosd'; } setTitle(displayItem, parentName); - let titleElement; - const osdTitle = view.querySelector('.osdTitle'); - titleElement = osdTitle; + const titleElement = view.querySelector('.osdTitle'); let displayName = itemHelper.getDisplayName(displayItem, { includeParentInfo: displayItem.Type !== 'Program', includeIndexNumber: displayItem.Type !== 'Program' @@ -1442,7 +1440,7 @@ import 'css!assets/css/videoosd'; }); } catch (e) { import('appRouter').then(({default: appRouter}) => { - appRouter.goHome(); + appRouter.default.goHome(); }); } }); @@ -1619,7 +1617,7 @@ import 'css!assets/css/videoosd'; const item = currentItem; if (item && item.Chapters && item.Chapters.length && item.Chapters[0].ImageTag) { - let html = getChapterBubbleHtml(connectionManager.getApiClient(item.ServerId), item, item.Chapters, ticks); + const html = getChapterBubbleHtml(connectionManager.getApiClient(item.ServerId), item, item.Chapters, ticks); if (html) { return html; diff --git a/src/plugins/bookPlayer/plugin.js b/src/plugins/bookPlayer/plugin.js index c167046cb9..9563173536 100644 --- a/src/plugins/bookPlayer/plugin.js +++ b/src/plugins/bookPlayer/plugin.js @@ -27,16 +27,16 @@ export class BookPlayer { this._loaded = false; loading.show(); - let elem = this.createMediaElement(); + const elem = this.createMediaElement(); return this.setCurrentSrc(elem, options); } stop() { this.unbindEvents(); - let elem = this._mediaElement; - let tocElement = this._tocElement; - let rendition = this._rendition; + const elem = this._mediaElement; + const tocElement = this._tocElement; + const rendition = this._rendition; if (elem) { dialogHelper.close(elem); @@ -147,7 +147,7 @@ export class BookPlayer { } bindMediaElementEvents() { - let elem = this._mediaElement; + const elem = this._mediaElement; elem.addEventListener('close', this.onDialogClosed, {once: true}); elem.querySelector('.btnBookplayerExit').addEventListener('click', this.onDialogClosed, {once: true}); @@ -166,7 +166,7 @@ export class BookPlayer { } unbindMediaElementEvents() { - let elem = this._mediaElement; + const elem = this._mediaElement; elem.removeEventListener('close', this.onDialogClosed); elem.querySelector('.btnBookplayerExit').removeEventListener('click', this.onDialogClosed); @@ -231,7 +231,7 @@ export class BookPlayer { } setCurrentSrc(elem, options) { - let item = options.items[0]; + const item = options.items[0]; this._currentItem = item; this.streamInfo = { started: true, @@ -241,8 +241,8 @@ export class BookPlayer { } }; - let serverId = item.ServerId; - let apiClient = connectionManager.getApiClient(serverId); + const serverId = item.ServerId; + const apiClient = connectionManager.getApiClient(serverId); return new Promise((resolve, reject) => { import('epubjs').then(({default: epubjs}) => { @@ -252,14 +252,14 @@ export class BookPlayer { this._currentSrc = downloadHref; this._rendition = rendition; - let cancellationToken = { + const cancellationToken = { shouldCancel: false }; this._cancellationToken = cancellationToken; return rendition.display().then(() => { - let epubElem = document.querySelector('.epub-container'); + const epubElem = document.querySelector('.epub-container'); epubElem.style.display = 'none'; this.bindEvents(); diff --git a/src/plugins/bookPlayer/tableOfContents.js b/src/plugins/bookPlayer/tableOfContents.js index 23e288aff5..a1c5d8f220 100644 --- a/src/plugins/bookPlayer/tableOfContents.js +++ b/src/plugins/bookPlayer/tableOfContents.js @@ -11,7 +11,7 @@ export default class TableOfContents { } destroy() { - let elem = this._elem; + const elem = this._elem; if (elem) { this.unbindEvents(); dialogHelper.close(elem); @@ -21,14 +21,14 @@ export default class TableOfContents { } bindEvents() { - let elem = this._elem; + const elem = this._elem; elem.addEventListener('close', this.onDialogClosed, {once: true}); elem.querySelector('.btnBookplayerTocClose').addEventListener('click', this.onDialogClosed, {once: true}); } unbindEvents() { - let elem = this._elem; + const elem = this._elem; elem.removeEventListener('close', this.onDialogClosed); elem.querySelector('.btnBookplayerTocClose').removeEventListener('click', this.onDialogClosed); @@ -39,10 +39,10 @@ export default class TableOfContents { } replaceLinks(contents, f) { - let links = contents.querySelectorAll('a[href]'); + const links = contents.querySelectorAll('a[href]'); links.forEach((link) => { - let href = link.getAttribute('href'); + const href = link.getAttribute('href'); link.onclick = () => { f(href); @@ -52,9 +52,9 @@ export default class TableOfContents { } createMediaElement() { - let rendition = this._rendition; + const rendition = this._rendition; - let elem = dialogHelper.createDialog({ + const elem = dialogHelper.createDialog({ size: 'small', autoFocus: false, removeOnClose: true @@ -69,7 +69,7 @@ export default class TableOfContents { rendition.book.navigation.forEach((chapter) => { tocHtml += '
  • '; // Remove '../' from href - let link = chapter.href.startsWith('../') ? chapter.href.substr(3) : chapter.href; + const link = chapter.href.startsWith('../') ? chapter.href.substr(3) : chapter.href; tocHtml += `${chapter.label}`; tocHtml += '
  • '; }); @@ -78,7 +78,7 @@ export default class TableOfContents { elem.innerHTML = tocHtml; this.replaceLinks(elem, (href) => { - let relative = rendition.book.path.relative(href); + const relative = rendition.book.path.relative(href); rendition.display(relative); this.destroy(); }); diff --git a/src/plugins/htmlVideoPlayer/plugin.js b/src/plugins/htmlVideoPlayer/plugin.js index 525372ac88..40fa98c650 100644 --- a/src/plugins/htmlVideoPlayer/plugin.js +++ b/src/plugins/htmlVideoPlayer/plugin.js @@ -105,7 +105,7 @@ function tryRemoveElement(elem) { } function hidePrePlaybackPage() { - let animatedPage = document.querySelector('.page:not(.hide)'); + const animatedPage = document.querySelector('.page:not(.hide)'); animatedPage.classList.add('hide'); // At this point, we must hide the scrollbar placeholder, so it's not being displayed while the item is being loaded document.body.classList.remove('force-scroll'); @@ -822,8 +822,8 @@ function tryRemoveElement(elem) { } }); - if (this._currentPlayOptions.fullscreen) { - appRouter.showVideoOsd().then(this.onNavigatedToOsd); + if (self._currentPlayOptions.fullscreen) { + appRouter.show('videoosd.html').then(this.onNavigatedToOsd); } else { appRouter.setTransparency('backdrop'); this.#videoDialog.classList.remove('videoPlayerContainer-onTop'); diff --git a/src/plugins/youtubePlayer/plugin.js b/src/plugins/youtubePlayer/plugin.js index eed75a8116..f7b6a04a97 100644 --- a/src/plugins/youtubePlayer/plugin.js +++ b/src/plugins/youtubePlayer/plugin.js @@ -106,7 +106,7 @@ function onPlaying(instance, playOptions, resolve) { instance.timeUpdateInterval = setInterval(onTimeUpdate.bind(instance), 500); if (playOptions.fullscreen) { - appRouter.showVideoOsd().then(function () { + appRouter.show('videoosd.html').then(function () { instance.videoDialog.classList.remove('onTop'); }); } else { diff --git a/src/scripts/deleteHelper.js b/src/scripts/deleteHelper.js index e10a1568c7..44876c75b3 100644 --- a/src/scripts/deleteHelper.js +++ b/src/scripts/deleteHelper.js @@ -15,7 +15,7 @@ export function deleteItem(options) { const item = options.item; const parentId = item.SeasonId || item.SeriesId || item.ParentId; - let apiClient = connectionManager.getApiClient(item.ServerId); + const apiClient = connectionManager.getApiClient(item.ServerId); return confirm({ @@ -34,7 +34,7 @@ export function deleteItem(options) { } } }, function (err) { - let result = function () { + const result = function () { return Promise.reject(err); }; diff --git a/src/scripts/inputManager.js b/src/scripts/inputManager.js index 3432c9e351..077af39bf7 100644 --- a/src/scripts/inputManager.js +++ b/src/scripts/inputManager.js @@ -39,7 +39,7 @@ import appHost from 'apphost'; dom.removeEventListener(scope, 'command', fn, {}); } - let commandTimes = {}; + const commandTimes = {}; function checkCommandTime(command) { const last = commandTimes[command] || 0; diff --git a/src/scripts/libraryMenu.js b/src/scripts/libraryMenu.js index bbe01276ba..55b8e834e4 100644 --- a/src/scripts/libraryMenu.js +++ b/src/scripts/libraryMenu.js @@ -3,6 +3,7 @@ define(['dom', 'layoutManager', 'inputManager', 'connectionManager', 'events', ' playbackManager = playbackManager.default || playbackManager; browser = browser.default || browser; + appRouter = appRouter.default || appRouter; function renderHeader() { var html = ''; diff --git a/src/scripts/serverNotifications.js b/src/scripts/serverNotifications.js index 87db52402d..e432aee805 100644 --- a/src/scripts/serverNotifications.js +++ b/src/scripts/serverNotifications.js @@ -3,6 +3,7 @@ define(['connectionManager', 'playbackManager', 'syncPlayManager', 'events', 'in playbackManager = playbackManager.default || playbackManager; focusManager = focusManager.default || focusManager; + appRouter = appRouter.default || appRouter; var serverNotifications = {}; diff --git a/src/scripts/site.js b/src/scripts/site.js index cd85c35e83..7a9ca00590 100644 --- a/src/scripts/site.js +++ b/src/scripts/site.js @@ -138,14 +138,14 @@ var Dashboard = { return new Promise(function (resolve, reject) { require(['appRouter'], function (appRouter) { - return appRouter.show(url).then(resolve, reject); + return appRouter.default.show(url).then(resolve, reject); }); }); }, navigate_direct: function (path) { return new Promise(function (resolve, reject) { require(['appRouter'], function (appRouter) { - return appRouter.showDirect(path).then(resolve, reject); + return appRouter.default.showDirect(path).then(resolve, reject); }); }); }, @@ -517,6 +517,7 @@ function initClient() { // ensure that appHost is loaded in this point require(['apphost', 'appRouter'], function (appHost, appRouter) { + appRouter = appRouter.default || appRouter; window.Emby = {}; console.debug('onAppReady: loading dependencies'); @@ -614,10 +615,10 @@ function initClient() { init(); } + var promise; var localApiClient; - let promise; - (function () { + function initRequireJs() { var urlArgs = 'v=' + (window.dashboardVersion || new Date().getDate()); var bowerPath = getBowerPath(); @@ -648,7 +649,9 @@ function initClient() { nowPlayingHelper: componentsPath + '/playback/nowplayinghelper', pluginManager: componentsPath + '/pluginManager', packageManager: componentsPath + '/packageManager', - screensaverManager: componentsPath + '/screensavermanager' + screensaverManager: componentsPath + '/screensavermanager', + chromecastHelper: 'plugins/chromecastPlayer/chromecastHelpers', + appRouter: 'components/appRouter' }; requirejs.onError = onRequireJsError; @@ -847,267 +850,9 @@ function initClient() { return window.ApiClient; }; }); - define('appRouter', [componentsPath + '/appRouter', 'itemHelper'], function (appRouter, itemHelper) { - function showItem(item, serverId, options) { - if (typeof item == 'string') { - require(['connectionManager'], function (connectionManager) { - var apiClient = connectionManager.currentApiClient(); - apiClient.getItem(apiClient.getCurrentUserId(), item).then(function (item) { - appRouter.showItem(item, options); - }); - }); - } else { - if (arguments.length == 2) { - options = arguments[1]; - } - - appRouter.show('/' + appRouter.getRouteUrl(item, options), { - item: item - }); - } - } - - appRouter.showLocalLogin = function (serverId, manualLogin) { - Dashboard.navigate('login.html?serverid=' + serverId); - }; - - appRouter.showVideoOsd = function () { - return Dashboard.navigate('video'); - }; - - appRouter.showSelectServer = function () { - Dashboard.navigate(AppInfo.isNativeApp ? 'selectserver.html' : 'login.html'); - }; - - appRouter.showWelcome = function () { - Dashboard.navigate(AppInfo.isNativeApp ? 'selectserver.html' : 'login.html'); - }; - - appRouter.showSettings = function () { - Dashboard.navigate('mypreferencesmenu.html'); - }; - - appRouter.showGuide = function () { - Dashboard.navigate('livetv.html?tab=1'); - }; - - appRouter.goHome = function () { - Dashboard.navigate('home.html'); - }; - - appRouter.showSearch = function () { - Dashboard.navigate('search.html'); - }; - - appRouter.showLiveTV = function () { - Dashboard.navigate('livetv.html'); - }; - - appRouter.showRecordedTV = function () { - Dashboard.navigate('livetv.html?tab=3'); - }; - - appRouter.showFavorites = function () { - Dashboard.navigate('home.html?tab=1'); - }; - - appRouter.showSettings = function () { - Dashboard.navigate('mypreferencesmenu.html'); - }; - - appRouter.setTitle = function (title) { - LibraryMenu.setTitle(title); - }; - - appRouter.getRouteUrl = function (item, options) { - if (!item) { - throw new Error('item cannot be null'); - } - - if (item.url) { - return item.url; - } - - var context = options ? options.context : null; - var id = item.Id || item.ItemId; - - if (!options) { - options = {}; - } - - var url; - var itemType = item.Type || (options ? options.itemType : null); - var serverId = item.ServerId || options.serverId; - - if (item === 'settings') { - return 'mypreferencesmenu.html'; - } - - if (item === 'wizard') { - return 'wizardstart.html'; - } - - if (item === 'manageserver') { - return 'dashboard.html'; - } - - if (item === 'recordedtv') { - return 'livetv.html?tab=3&serverId=' + options.serverId; - } - - if (item === 'nextup') { - return 'list.html?type=nextup&serverId=' + options.serverId; - } - - if (item === 'list') { - var url = 'list.html?serverId=' + options.serverId + '&type=' + options.itemTypes; - - if (options.isFavorite) { - url += '&IsFavorite=true'; - } - - return url; - } - - if (item === 'livetv') { - if (options.section === 'programs') { - return 'livetv.html?tab=0&serverId=' + options.serverId; - } - if (options.section === 'guide') { - return 'livetv.html?tab=1&serverId=' + options.serverId; - } - - if (options.section === 'movies') { - return 'list.html?type=Programs&IsMovie=true&serverId=' + options.serverId; - } - - if (options.section === 'shows') { - return 'list.html?type=Programs&IsSeries=true&IsMovie=false&IsNews=false&serverId=' + options.serverId; - } - - if (options.section === 'sports') { - return 'list.html?type=Programs&IsSports=true&serverId=' + options.serverId; - } - - if (options.section === 'kids') { - return 'list.html?type=Programs&IsKids=true&serverId=' + options.serverId; - } - - if (options.section === 'news') { - return 'list.html?type=Programs&IsNews=true&serverId=' + options.serverId; - } - - if (options.section === 'onnow') { - return 'list.html?type=Programs&IsAiring=true&serverId=' + options.serverId; - } - - if (options.section === 'dvrschedule') { - return 'livetv.html?tab=4&serverId=' + options.serverId; - } - - if (options.section === 'seriesrecording') { - return 'livetv.html?tab=5&serverId=' + options.serverId; - } - - return 'livetv.html?serverId=' + options.serverId; - } - - if (itemType == 'SeriesTimer') { - return 'details?seriesTimerId=' + id + '&serverId=' + serverId; - } - - if (item.CollectionType == 'livetv') { - return 'livetv.html'; - } - - if (item.Type === 'Genre') { - url = 'list.html?genreId=' + item.Id + '&serverId=' + serverId; - - if (context === 'livetv') { - url += '&type=Programs'; - } - - if (options.parentId) { - url += '&parentId=' + options.parentId; - } - - return url; - } - - if (item.Type === 'MusicGenre') { - url = 'list.html?musicGenreId=' + item.Id + '&serverId=' + serverId; - - if (options.parentId) { - url += '&parentId=' + options.parentId; - } - - return url; - } - - if (item.Type === 'Studio') { - url = 'list.html?studioId=' + item.Id + '&serverId=' + serverId; - - if (options.parentId) { - url += '&parentId=' + options.parentId; - } - - return url; - } - - if (context !== 'folders' && !itemHelper.isLocalItem(item)) { - if (item.CollectionType == 'movies') { - url = 'movies.html?topParentId=' + item.Id; - - if (options && options.section === 'latest') { - url += '&tab=1'; - } - - return url; - } - - if (item.CollectionType == 'tvshows') { - url = 'tv.html?topParentId=' + item.Id; - - if (options && options.section === 'latest') { - url += '&tab=2'; - } - - return url; - } - - if (item.CollectionType == 'music') { - return 'music.html?topParentId=' + item.Id; - } - } - - var itemTypes = ['Playlist', 'TvChannel', 'Program', 'BoxSet', 'MusicAlbum', 'MusicGenre', 'Person', 'Recording', 'MusicArtist']; - - if (itemTypes.indexOf(itemType) >= 0) { - return 'details?id=' + id + '&serverId=' + serverId; - } - - var contextSuffix = context ? '&context=' + context : ''; - - if (itemType == 'Series' || itemType == 'Season' || itemType == 'Episode') { - return 'details?id=' + id + contextSuffix + '&serverId=' + serverId; - } - - if (item.IsFolder) { - if (id) { - return 'list.html?parentId=' + id + '&serverId=' + serverId; - } - - return '#'; - } - - return 'details?id=' + id + '&serverId=' + serverId; - }; - - appRouter.showItem = showItem; - return appRouter; - }); - })(); + } + initRequireJs(); promise.then(onWebComponentsReady); } From e9b97185b8ba7197d973fe4b61bb24944e43debd Mon Sep 17 00:00:00 2001 From: MrTimscampi Date: Thu, 6 Aug 2020 23:25:18 +0200 Subject: [PATCH 2/6] Fix broken pages --- src/components/appRouter.js | 30 +++++++++++++++------------ src/plugins/htmlVideoPlayer/plugin.js | 4 ++-- src/plugins/youtubePlayer/plugin.js | 2 +- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/components/appRouter.js b/src/components/appRouter.js index c7495d6460..dc05acc9fd 100644 --- a/src/components/appRouter.js +++ b/src/components/appRouter.js @@ -69,27 +69,31 @@ class AppRouter { } showLocalLogin(serverId) { - this.show('login.html?serverid=' + serverId); + Dashboard.navigate('login.html?serverid=' + serverId); + } + + showVideoOsd() { + return Dashboard.navigate('video'); } showSelectServer() { - this.show(AppInfo.isNativeApp ? 'selectserver.html' : 'login.html'); + Dashboard.navigate(AppInfo.isNativeApp ? 'selectserver.html' : 'login.html'); } showWelcome() { - this.show(AppInfo.isNativeApp ? 'selectserver.html' : 'login.html'); + Dashboard.navigate(AppInfo.isNativeApp ? 'selectserver.html' : 'login.html'); } showSettings() { - this.show('mypreferencesmenu.html'); + Dashboard.navigate('mypreferencesmenu.html'); } showNowPlaying() { - this.show('/nowplaying.html'); + this.show('queue'); } beginConnectionWizard() { - backdrop.clear(); + backdrop.clearBackdrop(); loading.show(); connectionManager.connect({ enableAutoLogin: appSettings.enableAutoLogin() @@ -231,7 +235,7 @@ class AppRouter { } if (level === 'full' || level === 2) { - backdrop.clear(true); + backdrop.clearBackdrop(true); document.documentElement.classList.add('transparentDocument'); this.backgroundContainer.classList.add('backgroundContainer-transparent'); this.backdropContainer.classList.add('hide'); @@ -628,27 +632,27 @@ class AppRouter { } showGuide() { - this.show('livetv.html?tab=1'); + Dashboard.navigate('livetv.html?tab=1'); } goHome() { - this.show('home.html'); + Dashboard.navigate('home.html'); } showSearch() { - this.show('search.html'); + Dashboard.navigate('search.html'); } showLiveTV() { - this.show('livetv.html'); + Dashboard.navigate('livetv.html'); } showRecordedTV() { - this.show('livetv.html?tab=3'); + Dashboard.navigate('livetv.html?tab=3'); } showFavorites() { - this.show('home.html?tab=1'); + Dashboard.navigate('home.html?tab=1'); } setTitle(title) { diff --git a/src/plugins/htmlVideoPlayer/plugin.js b/src/plugins/htmlVideoPlayer/plugin.js index 40fa98c650..dc59604de9 100644 --- a/src/plugins/htmlVideoPlayer/plugin.js +++ b/src/plugins/htmlVideoPlayer/plugin.js @@ -822,8 +822,8 @@ function tryRemoveElement(elem) { } }); - if (self._currentPlayOptions.fullscreen) { - appRouter.show('videoosd.html').then(this.onNavigatedToOsd); + if (this._currentPlayOptions.fullscreen) { + appRouter.showVideoOsd().then(this.onNavigatedToOsd); } else { appRouter.setTransparency('backdrop'); this.#videoDialog.classList.remove('videoPlayerContainer-onTop'); diff --git a/src/plugins/youtubePlayer/plugin.js b/src/plugins/youtubePlayer/plugin.js index f7b6a04a97..eed75a8116 100644 --- a/src/plugins/youtubePlayer/plugin.js +++ b/src/plugins/youtubePlayer/plugin.js @@ -106,7 +106,7 @@ function onPlaying(instance, playOptions, resolve) { instance.timeUpdateInterval = setInterval(onTimeUpdate.bind(instance), 500); if (playOptions.fullscreen) { - appRouter.show('videoosd.html').then(function () { + appRouter.showVideoOsd().then(function () { instance.videoDialog.classList.remove('onTop'); }); } else { From c11dc53e44fb40c0d0c7fb88de636738a60a4109 Mon Sep 17 00:00:00 2001 From: MrTimscampi Date: Wed, 12 Aug 2020 15:12:03 +0200 Subject: [PATCH 3/6] Fix require --- src/components/appRouter.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/components/appRouter.js b/src/components/appRouter.js index dc05acc9fd..83c93fdaf3 100644 --- a/src/components/appRouter.js +++ b/src/components/appRouter.js @@ -287,7 +287,7 @@ class AppRouter { this.showWelcome(); break; case 'ServerUpdateNeeded': - require(['alert'], (alert) => { + import('alert').then(({default: alert}) =>{ alert({ text: globalize.translate('ServerUpdateNeeded', 'https://github.com/jellyfin/jellyfin'), html: globalize.translate('ServerUpdateNeeded', 'https://github.com/jellyfin/jellyfin') @@ -322,7 +322,8 @@ class AppRouter { url += '?' + ctx.querystring; } - require(['text!' + url], (html) => { + import('text!' + url).then(({default: html}) => { + console.warn(html) this.loadContent(ctx, route, html, request); }); } @@ -339,7 +340,7 @@ class AppRouter { }; if (route.controller) { - require(['controllers/' + route.controller], onInitComplete); + import('controllers/' + route.controller).then(onInitComplete); } else { onInitComplete(); } @@ -406,7 +407,7 @@ class AppRouter { this.forcedLogoutMsg = null; if (msg) { - require(['alert'], (alert) => { + import('alert').then((alert) => { alert(msg); }); } From ed4e733a6499e866915fea54a3c9a014ba760917 Mon Sep 17 00:00:00 2001 From: MrTimscampi Date: Wed, 12 Aug 2020 15:18:13 +0200 Subject: [PATCH 4/6] Remove default --- src/controllers/playback/video/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/playback/video/index.js b/src/controllers/playback/video/index.js index 8f46d24f0e..73540cd636 100644 --- a/src/controllers/playback/video/index.js +++ b/src/controllers/playback/video/index.js @@ -1440,7 +1440,7 @@ import 'css!assets/css/videoosd'; }); } catch (e) { import('appRouter').then(({default: appRouter}) => { - appRouter.default.goHome(); + appRouter.goHome(); }); } }); From ce74cb0602132cfbb4cee40df130257230a47943 Mon Sep 17 00:00:00 2001 From: MrTimscampi Date: Thu, 13 Aug 2020 15:37:09 +0200 Subject: [PATCH 5/6] Fix lint --- src/components/appRouter.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/appRouter.js b/src/components/appRouter.js index 83c93fdaf3..28826c55cc 100644 --- a/src/components/appRouter.js +++ b/src/components/appRouter.js @@ -323,7 +323,6 @@ class AppRouter { } import('text!' + url).then(({default: html}) => { - console.warn(html) this.loadContent(ctx, route, html, request); }); } From e7a4cc28c7ff7c51c6cfaf41b71f67ce6e886430 Mon Sep 17 00:00:00 2001 From: MrTimscampi Date: Sun, 16 Aug 2020 15:07:47 +0200 Subject: [PATCH 6/6] Remove chromecastHelper definition --- src/scripts/site.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/scripts/site.js b/src/scripts/site.js index 14f9851adc..3f97826743 100644 --- a/src/scripts/site.js +++ b/src/scripts/site.js @@ -655,7 +655,6 @@ function initClient() { pluginManager: componentsPath + '/pluginManager', packageManager: componentsPath + '/packageManager', screensaverManager: componentsPath + '/screensavermanager', - chromecastHelper: 'plugins/chromecastPlayer/chromecastHelpers', appRouter: 'components/appRouter' };