From cb1d2887fa1d5d8fffafbbebb4636d58d97b6bf0 Mon Sep 17 00:00:00 2001 From: dkanada Date: Thu, 10 Sep 2020 23:20:55 +0900 Subject: [PATCH 01/14] fix startup wizard redirect and standalone mode --- gulpfile.js | 32 ++------------ src/components/appRouter.js | 46 ++++++++++---------- src/components/require/requiretext.js | 2 +- src/controllers/dashboard/general.js | 4 -- src/scripts/clientUtils.js | 61 +++++++++++++-------------- src/scripts/settings/userSettings.js | 2 +- src/scripts/site.js | 44 +++++++++---------- src/standalone.js | 4 -- 8 files changed, 78 insertions(+), 117 deletions(-) delete mode 100644 src/standalone.js diff --git a/gulpfile.js b/gulpfile.js index 8b407ec2a..7d1184dbd 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -2,7 +2,6 @@ const { src, dest, series, parallel, watch } = require('gulp'); const browserSync = require('browser-sync').create(); const del = require('del'); const babel = require('gulp-babel'); -const concat = require('gulp-concat'); const terser = require('gulp-terser'); const htmlmin = require('gulp-htmlmin'); const imagemin = require('gulp-imagemin'); @@ -16,7 +15,6 @@ const stream = require('webpack-stream'); const inject = require('gulp-inject'); const postcss = require('gulp-postcss'); const sass = require('gulp-sass'); -const gulpif = require('gulp-if'); const lazypipe = require('lazypipe'); sass.compiler = require('node-sass'); @@ -30,10 +28,7 @@ if (mode.production()) { const options = { javascript: { - query: ['src/**/*.js', '!src/bundle.js', '!src/standalone.js', '!src/scripts/apploader.js'] - }, - apploader: { - query: ['src/standalone.js', 'src/scripts/apploader.js'] + query: ['src/**/*.js', '!src/bundle.js'] }, css: { query: ['src/**/*.css', 'src/**/*.scss'] @@ -68,8 +63,6 @@ function serve() { } }); - watch(options.apploader.query, apploader(true)); - watch('src/bundle.js', webpack); watch(options.css.query).on('all', function (event, path) { @@ -131,20 +124,6 @@ function javascript(query) { .pipe(browserSync.stream()); } -function apploader(standalone) { - function task() { - return src(options.apploader.query, { base: './src/' }) - .pipe(gulpif(standalone, concat('scripts/apploader.js'))) - .pipe(pipelineJavascript()) - .pipe(dest('dist/')) - .pipe(browserSync.stream()); - } - - task.displayName = 'apploader'; - - return task; -} - function webpack() { return stream(config) .pipe(dest('dist/')) @@ -195,10 +174,5 @@ function injectBundle() { .pipe(browserSync.stream()); } -function build(standalone) { - return series(clean, parallel(javascript, apploader(standalone), webpack, css, html, images, copy)); -} - -exports.default = series(build(false), injectBundle); -exports.standalone = series(build(true), injectBundle); -exports.serve = series(exports.standalone, serve); +exports.default = series(clean, parallel(javascript, webpack, css, html, images, copy), injectBundle); +exports.serve = series(exports.default, serve); diff --git a/src/components/appRouter.js b/src/components/appRouter.js index a6bb6da61..e1c0467d3 100644 --- a/src/components/appRouter.js +++ b/src/components/appRouter.js @@ -8,6 +8,7 @@ import itemHelper from 'itemHelper'; import loading from 'loading'; import page from 'page'; import viewManager from 'viewManager'; +import * as webSettings from 'webSettings'; class AppRouter { allRoutes = []; @@ -72,15 +73,11 @@ class AppRouter { } showVideoOsd() { - return Dashboard.navigate('video'); + Dashboard.navigate('video'); } showSelectServer() { - Dashboard.navigate(AppInfo.isNativeApp ? 'selectserver.html' : 'login.html'); - } - - showWelcome() { - Dashboard.navigate(AppInfo.isNativeApp ? 'selectserver.html' : 'login.html'); + Dashboard.navigate('selectserver.html'); } showSettings() { @@ -282,9 +279,6 @@ class AppRouter { case 'ServerSelection': this.showSelectServer(); break; - case 'ConnectSignIn': - this.showWelcome(); - break; case 'ServerUpdateNeeded': import('alert').then(({default: alert}) =>{ alert({ @@ -510,25 +504,33 @@ class AppRouter { authenticate(ctx, route, callback) { const firstResult = this.firstConnectionResult; - if (firstResult) { - this.firstConnectionResult = null; - if (firstResult.State !== 'SignedIn' && !route.anonymous) { - this.handleConnectionResult(firstResult); - return; - } + this.firstConnectionResult = null; + if (firstResult && firstResult.State === 'ServerSignIn' && !route.anonymous) { + let url = ApiClient.serverAddress() + '/System/Info/Public'; + fetch(url).then(response => { + if (!response.ok) return; + response.json().then(data => { + if (data !== null && data.StartupWizardCompleted === false) { + Dashboard.navigate('wizardstart.html'); + } else { + this.handleConnectionResult(firstResult); + } + }); + }).catch(error => { + console.error(error); + }); } + console.debug('processing path request: ' + pathname); const apiClient = window.connectionManager.currentApiClient(); const pathname = ctx.pathname.toLowerCase(); - console.debug('appRouter - processing path request ' + pathname); - 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'); + console.debug('route does not allow anonymous access: redirecting to login'); this.beginConnectionWizard(); return; } @@ -536,16 +538,16 @@ class AppRouter { if (shouldExitApp) { if (appHost.supports('exit')) { appHost.exit(); - return; } + return; } if (apiClient && apiClient.isLoggedIn()) { - console.debug('appRouter - user is authenticated'); + console.debug('user is authenticated'); if (route.isDefaultRoute) { - console.debug('appRouter - loading skin home page'); + console.debug('loading home page'); Emby.Page.goHome(); return; } else if (route.roles) { @@ -556,7 +558,7 @@ class AppRouter { } } - console.debug('appRouter - proceeding to ' + pathname); + console.debug('proceeding to page: ' + pathname); callback(); } diff --git a/src/components/require/requiretext.js b/src/components/require/requiretext.js index 28ddeb21c..ae1edbfc2 100644 --- a/src/components/require/requiretext.js +++ b/src/components/require/requiretext.js @@ -2,7 +2,7 @@ define(function () { 'use strict'; // hack to work around the server's auto-redirection feature - var addRedirectPrevention = window.dashboardVersion != null && window.Dashboard && !window.AppInfo.isNativeApp; + var addRedirectPrevention = window.dashboardVersion != null && window.Dashboard; return { diff --git a/src/controllers/dashboard/general.js b/src/controllers/dashboard/general.js index eb819dc41..78fc8f838 100644 --- a/src/controllers/dashboard/general.js +++ b/src/controllers/dashboard/general.js @@ -44,10 +44,6 @@ import 'emby-button'; ApiClient.updateNamedConfiguration(brandingConfigKey, brandingConfig).then(function () { Dashboard.processServerConfigurationUpdateResult(); - - if (requiresReload && !AppInfo.isNativeApp) { - window.location.reload(true); - } }); }); }, function () { diff --git a/src/scripts/clientUtils.js b/src/scripts/clientUtils.js index 4d3c049e8..097abc4c9 100644 --- a/src/scripts/clientUtils.js +++ b/src/scripts/clientUtils.js @@ -1,35 +1,41 @@ +import * as webSettings from 'webSettings'; export function getCurrentUser() { return window.ApiClient.getCurrentUser(false); } -//TODO: investigate url prefix support for serverAddress function -export function serverAddress() { - if (AppInfo.isNativeApp) { - const apiClient = window.ApiClient; +// TODO: investigate url prefix support for serverAddress function +export async function serverAddress() { + const apiClient = window.ApiClient; - if (apiClient) { - return apiClient.serverAddress(); + if (apiClient) { + return Promise.resolve(apiClient.serverAddress()); + } + + let current = await window.connectionManager.getAvailableServers().then(servers => { + if (servers.length !== 0) { + return Promise.resolve(servers[0].ManualAddress); } + }); - return null; - } + if (current) return Promise.resolve(current); - const urlLower = window.location.href.toLowerCase(); - const index = urlLower.lastIndexOf('/web'); + let urls = []; + urls.push(`${window.location.origin}/System/Info/Public`); + urls.push(`${window.location.protocol}//${window.location.hostname}:8096/System/Info/Public`); - if (index != -1) { - return urlLower.substring(0, index); - } + let promises = urls.map(url => { + return fetch(url).catch(error => { + return Promise.resolve(); + }); + }); - const loc = window.location; - let address = loc.protocol + '//' + loc.hostname; - - if (loc.port) { - address += ':' + loc.port; - } - - return address; + return Promise.all(promises).then(responses => { + return responses.find(response => response && response.ok); + }).then(response => response.url).catch(error => { + console.log(error); + return Promise.resolve(); + }); } export function getCurrentUserId() { @@ -49,16 +55,9 @@ export function onServerChanged(userId, accessToken, apiClient) { export function logout() { window.connectionManager.logout().then(function () { - let loginPage; - - if (AppInfo.isNativeApp) { - loginPage = 'selectserver.html'; - window.ApiClient = null; - } else { - loginPage = 'login.html'; - } - - navigate(loginPage); + webSettings.getMultiServer().then(multi => { + multi ? navigate('selectserver.html') : navigate('login.html'); + }); }); } diff --git a/src/scripts/settings/userSettings.js b/src/scripts/settings/userSettings.js index 1235e0fa5..263d74ed3 100644 --- a/src/scripts/settings/userSettings.js +++ b/src/scripts/settings/userSettings.js @@ -209,7 +209,7 @@ export class UserSettings { } val = this.get('enableBackdrops', false); - return val !== 'false'; + return val === 'true'; } /** diff --git a/src/scripts/site.js b/src/scripts/site.js index f14670d82..adb0d6521 100644 --- a/src/scripts/site.js +++ b/src/scripts/site.js @@ -63,7 +63,7 @@ function initClient() { if (!localApiClient) { var server = window.connectionManager.getLastUsedServer(); - if (server) { + if (server && server.Id) { localApiClient = window.connectionManager.getApiClient(server.Id); } } @@ -83,40 +83,38 @@ function initClient() { } function createConnectionManager() { - return require(['connectionManagerFactory', 'apphost', 'credentialprovider', 'events', 'userSettings'], function (ConnectionManager, appHost, credentialProvider, events, userSettings) { + return require(['connectionManagerFactory', 'apphost', 'credentialprovider', 'events', 'userSettings', 'apiclient', 'clientUtils'], function (ConnectionManager, appHost, credentialProvider, events, userSettings, apiClientFactory, clientUtils) { appHost = appHost.default || appHost; var credentialProviderInstance = new credentialProvider(); var promises = [appHost.init()]; - return Promise.all(promises).then(function (responses) { + return Promise.all(promises).then(responses => { var capabilities = Dashboard.capabilities(appHost); window.connectionManager = new ConnectionManager(credentialProviderInstance, appHost.appName(), appHost.appVersion(), appHost.deviceName(), appHost.deviceId(), capabilities); bindConnectionManagerEvents(window.connectionManager, events, userSettings); + clientUtils.serverAddress().then(server => { + if (!server) { + Dashboard.navigate('selectserver.html'); + return; + } - if (!AppInfo.isNativeApp) { - console.debug('loading ApiClient singleton'); + console.debug('creating apiclient singleton'); + let parts = server.split('/'); + let url = parts[0] + '//' + parts[2]; + var apiClient = new apiClientFactory(url, appHost.appName(), appHost.appVersion(), appHost.deviceName(), appHost.deviceId()); - return require(['apiclient', 'clientUtils'], function (apiClientFactory, clientUtils) { - console.debug('creating ApiClient singleton'); + apiClient.enableAutomaticNetworking = false; + apiClient.manualAddressOnly = true; - var apiClient = new apiClientFactory(Dashboard.serverAddress(), appHost.appName(), appHost.appVersion(), appHost.deviceName(), appHost.deviceId()); + window.connectionManager.addApiClient(apiClient); + window.ApiClient = apiClient; + console.debug('loaded apiclient singleton'); - apiClient.enableAutomaticNetworking = false; - apiClient.manualAddressOnly = true; - - window.connectionManager.addApiClient(apiClient); - - window.ApiClient = apiClient; - localApiClient = apiClient; - - console.debug('loaded ApiClient singleton'); - }); - } - - return Promise.resolve(); + return Promise.resolve(); + }); }); }); } @@ -434,10 +432,6 @@ function initClient() { define('castSenderApiLoader', [componentsPath + '/castSenderApi'], returnFirstDependency); - if (window.appMode === 'cordova' || window.appMode === 'android' || window.appMode === 'standalone') { - AppInfo.isNativeApp = true; - } - init(); } diff --git a/src/standalone.js b/src/standalone.js deleted file mode 100644 index 237872703..000000000 --- a/src/standalone.js +++ /dev/null @@ -1,4 +0,0 @@ -(function() { - 'use strict'; - window.appMode = 'standalone'; -})(); From 5d8fdc311fd43a2ab7576c7ba63c207311f678e5 Mon Sep 17 00:00:00 2001 From: dkanada Date: Sat, 12 Sep 2020 08:34:08 +0900 Subject: [PATCH 02/14] remove standalone build from azure --- .ci/azure-pipelines-build.yml | 6 ------ README.md | 10 ++-------- package.json | 1 - 3 files changed, 2 insertions(+), 15 deletions(-) diff --git a/.ci/azure-pipelines-build.yml b/.ci/azure-pipelines-build.yml index 128fe5460..026afe76a 100644 --- a/.ci/azure-pipelines-build.yml +++ b/.ci/azure-pipelines-build.yml @@ -8,8 +8,6 @@ jobs: BuildConfiguration: development Production: BuildConfiguration: production - Standalone: - BuildConfiguration: standalone pool: vmImage: 'ubuntu-latest' @@ -39,10 +37,6 @@ jobs: displayName: 'Build Production' condition: eq(variables['BuildConfiguration'], 'production') - - script: 'yarn build:standalone' - displayName: 'Build Standalone' - condition: eq(variables['BuildConfiguration'], 'standalone') - - script: 'test -d dist' displayName: 'Check Build' diff --git a/README.md b/README.md index ca42965dd..1108ec9f2 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ Jellyfin Web is the frontend used for most of the clients available for end user ### Dependencies -- [Node.js](https://nodejs.org/en/download/) +- [Node.js](https://nodejs.org/en/download) - [Yarn 1.22.4](https://classic.yarnpkg.com/en/docs/install) - Gulp-cli @@ -69,14 +69,8 @@ Jellyfin Web is the frontend used for most of the clients available for end user yarn serve ``` -4. Build the client with sourcemaps. +4. Build the client with sourcemaps available. ```sh yarn build:development ``` - - You can build a nginx compatible version as well. - - ```sh - yarn build:standalone - ``` diff --git a/package.json b/package.json index 3a74cd9d6..df433ed9b 100644 --- a/package.json +++ b/package.json @@ -392,7 +392,6 @@ "prepare": "gulp --production", "build:development": "gulp --development", "build:production": "gulp --production", - "build:standalone": "gulp standalone --development", "lint": "eslint \".\"", "stylelint": "stylelint \"src/**/*.css\"" } From 4553215841936e2c2c089e4869004771007b0c9e Mon Sep 17 00:00:00 2001 From: dkanada Date: Sat, 12 Sep 2020 08:41:04 +0900 Subject: [PATCH 03/14] add code suggestions --- src/components/appRouter.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/components/appRouter.js b/src/components/appRouter.js index e1c0467d3..1d25543c3 100644 --- a/src/components/appRouter.js +++ b/src/components/appRouter.js @@ -509,23 +509,23 @@ class AppRouter { if (firstResult && firstResult.State === 'ServerSignIn' && !route.anonymous) { let url = ApiClient.serverAddress() + '/System/Info/Public'; fetch(url).then(response => { - if (!response.ok) return; - response.json().then(data => { - if (data !== null && data.StartupWizardCompleted === false) { - Dashboard.navigate('wizardstart.html'); - } else { - this.handleConnectionResult(firstResult); - } - }); + if (!response.ok) return Promise.reject('fetch failed'); + return response.json(); + }).then(data => { + if (data !== null && data.StartupWizardCompleted === false) { + Dashboard.navigate('wizardstart.html'); + } else { + this.handleConnectionResult(firstResult); + } }).catch(error => { console.error(error); }); } - console.debug('processing path request: ' + pathname); const apiClient = window.connectionManager.currentApiClient(); const pathname = ctx.pathname.toLowerCase(); + console.debug('processing path request: ' + pathname); const isCurrentRouteStartup = this.currentRouteInfo ? this.currentRouteInfo.route.startup : true; const shouldExitApp = ctx.isBack && route.isDefaultRoute && isCurrentRouteStartup; From 982ae411c59cb95421ea870b0dd1726662fe15d5 Mon Sep 17 00:00:00 2001 From: dkanada Date: Sat, 12 Sep 2020 09:12:40 +0900 Subject: [PATCH 04/14] fix linting issues and add servers to web config --- src/components/appRouter.js | 2 +- src/config.template.json | 1 + src/scripts/clientUtils.js | 15 ++++++++------- src/scripts/settings/webSettings.js | 9 +++++++++ src/scripts/site.js | 10 ++++------ 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/components/appRouter.js b/src/components/appRouter.js index 1d25543c3..0c3c1d453 100644 --- a/src/components/appRouter.js +++ b/src/components/appRouter.js @@ -507,7 +507,7 @@ class AppRouter { this.firstConnectionResult = null; if (firstResult && firstResult.State === 'ServerSignIn' && !route.anonymous) { - let url = ApiClient.serverAddress() + '/System/Info/Public'; + const url = ApiClient.serverAddress() + '/System/Info/Public'; fetch(url).then(response => { if (!response.ok) return Promise.reject('fetch failed'); return response.json(); diff --git a/src/config.template.json b/src/config.template.json index 0f308ccc1..2ea8f8945 100644 --- a/src/config.template.json +++ b/src/config.template.json @@ -1,5 +1,6 @@ { "multiserver": false, + "servers": [], "themes": [ { "name": "Apple TV", diff --git a/src/scripts/clientUtils.js b/src/scripts/clientUtils.js index 097abc4c9..d16566673 100644 --- a/src/scripts/clientUtils.js +++ b/src/scripts/clientUtils.js @@ -12,7 +12,7 @@ export async function serverAddress() { return Promise.resolve(apiClient.serverAddress()); } - let current = await window.connectionManager.getAvailableServers().then(servers => { + const current = await window.connectionManager.getAvailableServers().then(servers => { if (servers.length !== 0) { return Promise.resolve(servers[0].ManualAddress); } @@ -20,19 +20,20 @@ export async function serverAddress() { if (current) return Promise.resolve(current); - let urls = []; - urls.push(`${window.location.origin}/System/Info/Public`); - urls.push(`${window.location.protocol}//${window.location.hostname}:8096/System/Info/Public`); + const urls = []; + urls.push(window.location.origin); + urls.push(`${window.location.protocol}//${window.location.hostname}:8096`); + urls.push(await webSettings.getServers()); - let promises = urls.map(url => { - return fetch(url).catch(error => { + const promises = urls.map(url => { + return fetch(`${url}/System/Info/Public`).catch(error => { return Promise.resolve(); }); }); return Promise.all(promises).then(responses => { return responses.find(response => response && response.ok); - }).then(response => response.url).catch(error => { + }).then(response => response.url.replace('/System/Info/Public', '')).catch(error => { console.log(error); return Promise.resolve(); }); diff --git a/src/scripts/settings/webSettings.js b/src/scripts/settings/webSettings.js index 2ffe290d8..be28ae730 100644 --- a/src/scripts/settings/webSettings.js +++ b/src/scripts/settings/webSettings.js @@ -46,6 +46,15 @@ export function getMultiServer() { }); } +export function getServers() { + return getConfig().then(config => { + return config.servers; + }).catch(error => { + console.log('cannot get web config:', error); + return []; + }); +} + export function getThemes() { return getConfig().then(config => { return config.themes; diff --git a/src/scripts/site.js b/src/scripts/site.js index adb0d6521..0123eceed 100644 --- a/src/scripts/site.js +++ b/src/scripts/site.js @@ -86,11 +86,11 @@ function initClient() { return require(['connectionManagerFactory', 'apphost', 'credentialprovider', 'events', 'userSettings', 'apiclient', 'clientUtils'], function (ConnectionManager, appHost, credentialProvider, events, userSettings, apiClientFactory, clientUtils) { appHost = appHost.default || appHost; - var credentialProviderInstance = new credentialProvider(); - var promises = [appHost.init()]; + const credentialProviderInstance = new credentialProvider(); + const promises = [appHost.init()]; return Promise.all(promises).then(responses => { - var capabilities = Dashboard.capabilities(appHost); + const capabilities = Dashboard.capabilities(appHost); window.connectionManager = new ConnectionManager(credentialProviderInstance, appHost.appName(), appHost.appVersion(), appHost.deviceName(), appHost.deviceId(), capabilities); @@ -102,9 +102,7 @@ function initClient() { } console.debug('creating apiclient singleton'); - let parts = server.split('/'); - let url = parts[0] + '//' + parts[2]; - var apiClient = new apiClientFactory(url, appHost.appName(), appHost.appVersion(), appHost.deviceName(), appHost.deviceId()); + const apiClient = new apiClientFactory(server, appHost.appName(), appHost.appVersion(), appHost.deviceName(), appHost.deviceId()); apiClient.enableAutomaticNetworking = false; apiClient.manualAddressOnly = true; From b76f5a0a0fa62328f655705f669e2fc7a311b1f6 Mon Sep 17 00:00:00 2001 From: dkanada Date: Fri, 30 Oct 2020 22:13:56 +0900 Subject: [PATCH 05/14] return empty array when servers missing from config Co-authored-by: Dmitry Lyzo <56478732+dmitrylyzo@users.noreply.github.com> --- src/scripts/settings/webSettings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripts/settings/webSettings.js b/src/scripts/settings/webSettings.js index 45ac6b00e..461951f06 100644 --- a/src/scripts/settings/webSettings.js +++ b/src/scripts/settings/webSettings.js @@ -87,7 +87,7 @@ export function getMultiServer() { export function getServers() { return getConfig().then(config => { - return config.servers; + return config.servers || []; }).catch(error => { console.log('cannot get web config:', error); return []; From 69439bbff0d91a4162288fd3bf3beacf7ca8d397 Mon Sep 17 00:00:00 2001 From: dkanada Date: Fri, 30 Oct 2020 22:14:45 +0900 Subject: [PATCH 06/14] fix issue with multiple entries in server array Co-authored-by: Dmitry Lyzo <56478732+dmitrylyzo@users.noreply.github.com> --- src/scripts/clientUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripts/clientUtils.js b/src/scripts/clientUtils.js index 0b31727cc..986507171 100644 --- a/src/scripts/clientUtils.js +++ b/src/scripts/clientUtils.js @@ -23,7 +23,7 @@ export async function serverAddress() { const urls = []; urls.push(window.location.origin); urls.push(`${window.location.protocol}//${window.location.hostname}:8096`); - urls.push(await webSettings.getServers()); + urls.push(...await webSettings.getServers()); const promises = urls.map(url => { return fetch(`${url}/System/Info/Public`).catch(error => { From 1c1f5c09b75ce33f1427eec6a276884ba0a72051 Mon Sep 17 00:00:00 2001 From: dkanada Date: Sat, 7 Nov 2020 15:16:39 +0900 Subject: [PATCH 07/14] return after navigating to wizard --- src/components/appRouter.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/appRouter.js b/src/components/appRouter.js index 0c3c1d453..9c76e31ef 100644 --- a/src/components/appRouter.js +++ b/src/components/appRouter.js @@ -506,7 +506,7 @@ class AppRouter { const firstResult = this.firstConnectionResult; this.firstConnectionResult = null; - if (firstResult && firstResult.State === 'ServerSignIn' && !route.anonymous) { + if (firstResult && firstResult.State === 'ServerSignIn') { const url = ApiClient.serverAddress() + '/System/Info/Public'; fetch(url).then(response => { if (!response.ok) return Promise.reject('fetch failed'); @@ -520,6 +520,8 @@ class AppRouter { }).catch(error => { console.error(error); }); + + return; } const apiClient = window.connectionManager.currentApiClient(); From d4c8d1a334bfaae627b04abd5e3c8c4f7d203aff Mon Sep 17 00:00:00 2001 From: dkanada Date: Sat, 7 Nov 2020 16:02:28 +0900 Subject: [PATCH 08/14] wizard takes highest priority when selecting a server --- src/scripts/clientUtils.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/scripts/clientUtils.js b/src/scripts/clientUtils.js index 986507171..e9659346c 100644 --- a/src/scripts/clientUtils.js +++ b/src/scripts/clientUtils.js @@ -18,11 +18,13 @@ export async function serverAddress() { } }); - if (current) return Promise.resolve(current); + // TODO this makes things faster but it also blocks the wizard in some scenarios + // if (current) return Promise.resolve(current); const urls = []; urls.push(window.location.origin); - urls.push(`${window.location.protocol}//${window.location.hostname}:8096`); + urls.push(`https://${window.location.hostname}:8920`); + urls.push(`http://${window.location.hostname}:8096`); urls.push(...await webSettings.getServers()); const promises = urls.map(url => { @@ -32,8 +34,13 @@ export async function serverAddress() { }); return Promise.all(promises).then(responses => { - return responses.find(response => response && response.ok); - }).then(response => response.url.replace('/System/Info/Public', '')).catch(error => { + responses = responses.filter(response => response && response.ok); + return Promise.all(responses.map(response => response.json())); + }).then(configs => { + const selection = configs.find(config => !config.StartupWizardCompleted) + if (!selection) selection = configs[0]; + return Promise.resolve(selection.LocalAddress); + }).catch(error => { console.log(error); return Promise.resolve(); }); From 3b8e4c6330e685b884073f7f17f3aef173be66ac Mon Sep 17 00:00:00 2001 From: dkanada Date: Sat, 7 Nov 2020 16:10:02 +0900 Subject: [PATCH 09/14] fix errors reported by linter --- src/scripts/clientUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripts/clientUtils.js b/src/scripts/clientUtils.js index e9659346c..477632680 100644 --- a/src/scripts/clientUtils.js +++ b/src/scripts/clientUtils.js @@ -37,7 +37,7 @@ export async function serverAddress() { responses = responses.filter(response => response && response.ok); return Promise.all(responses.map(response => response.json())); }).then(configs => { - const selection = configs.find(config => !config.StartupWizardCompleted) + let selection = configs.find(config => !config.StartupWizardCompleted); if (!selection) selection = configs[0]; return Promise.resolve(selection.LocalAddress); }).catch(error => { From 862105968cb839eff4767e5dde95b1c7b9e0a7ed Mon Sep 17 00:00:00 2001 From: Dmitry Lyzo Date: Sat, 21 Nov 2020 21:10:13 +0300 Subject: [PATCH 10/14] Remove AppInfo Signed-off-by: Dmitry Lyzo --- src/components/AppInfo.js | 4 ---- src/components/ServerConnections.js | 1 - src/components/appRouter.js | 1 - src/controllers/dashboard/general.js | 1 - src/scripts/clientUtils.js | 1 - src/scripts/site.js | 3 --- 6 files changed, 11 deletions(-) delete mode 100644 src/components/AppInfo.js diff --git a/src/components/AppInfo.js b/src/components/AppInfo.js deleted file mode 100644 index a89c55d0b..000000000 --- a/src/components/AppInfo.js +++ /dev/null @@ -1,4 +0,0 @@ - -export default { - isNativeApp: false -}; diff --git a/src/components/ServerConnections.js b/src/components/ServerConnections.js index d3a12c020..0242e549c 100644 --- a/src/components/ServerConnections.js +++ b/src/components/ServerConnections.js @@ -1,7 +1,6 @@ import { ConnectionManager, Credentials, ApiClient, Events } from 'jellyfin-apiclient'; import { appHost } from './apphost'; import Dashboard from '../scripts/clientUtils'; -import AppInfo from './AppInfo'; import { setUserInfo } from '../scripts/settings/userSettings'; class ServerConnections extends ConnectionManager { diff --git a/src/components/appRouter.js b/src/components/appRouter.js index 64e713367..844c7a61f 100644 --- a/src/components/appRouter.js +++ b/src/components/appRouter.js @@ -8,7 +8,6 @@ import itemHelper from './itemHelper'; import loading from './loading/loading'; import page from 'page'; import viewManager from './viewManager/viewManager'; -import AppInfo from './AppInfo'; import Dashboard from '../scripts/clientUtils'; import ServerConnections from './ServerConnections'; import alert from './alert'; diff --git a/src/controllers/dashboard/general.js b/src/controllers/dashboard/general.js index cf48179f8..a780f35e1 100644 --- a/src/controllers/dashboard/general.js +++ b/src/controllers/dashboard/general.js @@ -6,7 +6,6 @@ import '../../elements/emby-textarea/emby-textarea'; import '../../elements/emby-input/emby-input'; import '../../elements/emby-select/emby-select'; import '../../elements/emby-button/emby-button'; -import AppInfo from '../../components/AppInfo'; import Dashboard from '../../scripts/clientUtils'; import alert from '../../components/alert'; diff --git a/src/scripts/clientUtils.js b/src/scripts/clientUtils.js index ec7246ca8..6e9814262 100644 --- a/src/scripts/clientUtils.js +++ b/src/scripts/clientUtils.js @@ -1,4 +1,3 @@ -import AppInfo from '../components/AppInfo'; import ServerConnections from '../components/ServerConnections'; import toast from '../components/toast/toast'; import loading from '../components/loading/loading'; diff --git a/src/scripts/site.js b/src/scripts/site.js index 10189d9d6..8722da5e2 100644 --- a/src/scripts/site.js +++ b/src/scripts/site.js @@ -7,7 +7,6 @@ import 'classlist.js'; import 'whatwg-fetch'; import 'resize-observer-polyfill'; import '../assets/css/site.scss'; -import AppInfo from '../components/AppInfo'; import { Events } from 'jellyfin-apiclient'; import ServerConnections from '../components/ServerConnections'; import globalize from './globalize'; @@ -60,8 +59,6 @@ window.getParameterByName = function(name, url) { return decodeURIComponent(results[1].replace(/\+/g, ' ')); }; -Object.freeze(AppInfo); - function loadCoreDictionary() { 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']; const translations = languages.map(function (language) { From d2263c761c1a1877baa06d1895ef1050819e3b3a Mon Sep 17 00:00:00 2001 From: Dmitry Lyzo Date: Sun, 22 Nov 2020 02:13:11 +0300 Subject: [PATCH 11/14] Fix video OSD Signed-off-by: Dmitry Lyzo --- src/components/appRouter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/appRouter.js b/src/components/appRouter.js index 844c7a61f..e04174668 100644 --- a/src/components/appRouter.js +++ b/src/components/appRouter.js @@ -76,7 +76,7 @@ class AppRouter { } showVideoOsd() { - Dashboard.navigate('video'); + return Dashboard.navigate('video'); } showSelectServer() { From 7080a75b18583d3ab5208466c5ffbd13138dfecf Mon Sep 17 00:00:00 2001 From: Dmitry Lyzo Date: Sun, 22 Nov 2020 02:31:35 +0300 Subject: [PATCH 12/14] lint --- src/scripts/site.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/scripts/site.js b/src/scripts/site.js index 8722da5e2..13efd5611 100644 --- a/src/scripts/site.js +++ b/src/scripts/site.js @@ -25,7 +25,7 @@ import './libraryMenu'; import './routes'; import '../components/themeMediaPlayer'; import './autoBackdrops'; -import { pageClassOn, serverAddress } from './clientUtils'; +import { navigate, pageClassOn, serverAddress } from './clientUtils'; import '../libraries/screensavermanager'; import './serverNotifications'; import '../components/playback/playerSelectionMenu'; @@ -77,7 +77,7 @@ function loadCoreDictionary() { function init() { serverAddress().then(server => { if (!server) { - Dashboard.navigate('selectserver.html'); + navigate('selectserver.html'); return; } From 15688910596bed58f367fe580ce17ed725ea6929 Mon Sep 17 00:00:00 2001 From: Dmitry Lyzo Date: Sun, 22 Nov 2020 02:51:57 +0300 Subject: [PATCH 13/14] SonarCloud --- src/components/appRouter.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/appRouter.js b/src/components/appRouter.js index e04174668..03000ebaf 100644 --- a/src/components/appRouter.js +++ b/src/components/appRouter.js @@ -11,7 +11,6 @@ import viewManager from './viewManager/viewManager'; import Dashboard from '../scripts/clientUtils'; import ServerConnections from './ServerConnections'; import alert from './alert'; -import * as webSettings from '../scripts/settings/webSettings'; class AppRouter { allRoutes = []; From 48e84d3c6f3d552f423f39318bbb1a2e29871ab4 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Sat, 21 Nov 2020 21:58:12 -0500 Subject: [PATCH 14/14] Apply hawken93's patch --- src/scripts/clientUtils.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/scripts/clientUtils.js b/src/scripts/clientUtils.js index 6e9814262..5b43cd469 100644 --- a/src/scripts/clientUtils.js +++ b/src/scripts/clientUtils.js @@ -35,18 +35,14 @@ export async function serverAddress() { urls.push(...await webSettings.getServers()); const promises = urls.map(url => { - return fetch(`${url}/System/Info/Public`).catch(error => { + return fetch(`${url}/System/Info/Public`).then(resp => url).catch(error => { return Promise.resolve(); }); }); return Promise.all(promises).then(responses => { - responses = responses.filter(response => response && response.ok); - return Promise.all(responses.map(response => response.json())); - }).then(configs => { - let selection = configs.find(config => !config.StartupWizardCompleted); - if (!selection) selection = configs[0]; - return Promise.resolve(selection.LocalAddress); + responses = responses.filter(response => response); + return responses[0]; }).catch(error => { console.log(error); return Promise.resolve();