fix startup wizard redirect and standalone mode
This commit is contained in:
parent
e06b9ec4d0
commit
cb1d2887fa
8 changed files with 78 additions and 117 deletions
32
gulpfile.js
32
gulpfile.js
|
@ -2,7 +2,6 @@ const { src, dest, series, parallel, watch } = require('gulp');
|
||||||
const browserSync = require('browser-sync').create();
|
const browserSync = require('browser-sync').create();
|
||||||
const del = require('del');
|
const del = require('del');
|
||||||
const babel = require('gulp-babel');
|
const babel = require('gulp-babel');
|
||||||
const concat = require('gulp-concat');
|
|
||||||
const terser = require('gulp-terser');
|
const terser = require('gulp-terser');
|
||||||
const htmlmin = require('gulp-htmlmin');
|
const htmlmin = require('gulp-htmlmin');
|
||||||
const imagemin = require('gulp-imagemin');
|
const imagemin = require('gulp-imagemin');
|
||||||
|
@ -16,7 +15,6 @@ const stream = require('webpack-stream');
|
||||||
const inject = require('gulp-inject');
|
const inject = require('gulp-inject');
|
||||||
const postcss = require('gulp-postcss');
|
const postcss = require('gulp-postcss');
|
||||||
const sass = require('gulp-sass');
|
const sass = require('gulp-sass');
|
||||||
const gulpif = require('gulp-if');
|
|
||||||
const lazypipe = require('lazypipe');
|
const lazypipe = require('lazypipe');
|
||||||
|
|
||||||
sass.compiler = require('node-sass');
|
sass.compiler = require('node-sass');
|
||||||
|
@ -30,10 +28,7 @@ if (mode.production()) {
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
javascript: {
|
javascript: {
|
||||||
query: ['src/**/*.js', '!src/bundle.js', '!src/standalone.js', '!src/scripts/apploader.js']
|
query: ['src/**/*.js', '!src/bundle.js']
|
||||||
},
|
|
||||||
apploader: {
|
|
||||||
query: ['src/standalone.js', 'src/scripts/apploader.js']
|
|
||||||
},
|
},
|
||||||
css: {
|
css: {
|
||||||
query: ['src/**/*.css', 'src/**/*.scss']
|
query: ['src/**/*.css', 'src/**/*.scss']
|
||||||
|
@ -68,8 +63,6 @@ function serve() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
watch(options.apploader.query, apploader(true));
|
|
||||||
|
|
||||||
watch('src/bundle.js', webpack);
|
watch('src/bundle.js', webpack);
|
||||||
|
|
||||||
watch(options.css.query).on('all', function (event, path) {
|
watch(options.css.query).on('all', function (event, path) {
|
||||||
|
@ -131,20 +124,6 @@ function javascript(query) {
|
||||||
.pipe(browserSync.stream());
|
.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() {
|
function webpack() {
|
||||||
return stream(config)
|
return stream(config)
|
||||||
.pipe(dest('dist/'))
|
.pipe(dest('dist/'))
|
||||||
|
@ -195,10 +174,5 @@ function injectBundle() {
|
||||||
.pipe(browserSync.stream());
|
.pipe(browserSync.stream());
|
||||||
}
|
}
|
||||||
|
|
||||||
function build(standalone) {
|
exports.default = series(clean, parallel(javascript, webpack, css, html, images, copy), injectBundle);
|
||||||
return series(clean, parallel(javascript, apploader(standalone), webpack, css, html, images, copy));
|
exports.serve = series(exports.default, serve);
|
||||||
}
|
|
||||||
|
|
||||||
exports.default = series(build(false), injectBundle);
|
|
||||||
exports.standalone = series(build(true), injectBundle);
|
|
||||||
exports.serve = series(exports.standalone, serve);
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import itemHelper from 'itemHelper';
|
||||||
import loading from 'loading';
|
import loading from 'loading';
|
||||||
import page from 'page';
|
import page from 'page';
|
||||||
import viewManager from 'viewManager';
|
import viewManager from 'viewManager';
|
||||||
|
import * as webSettings from 'webSettings';
|
||||||
|
|
||||||
class AppRouter {
|
class AppRouter {
|
||||||
allRoutes = [];
|
allRoutes = [];
|
||||||
|
@ -72,15 +73,11 @@ class AppRouter {
|
||||||
}
|
}
|
||||||
|
|
||||||
showVideoOsd() {
|
showVideoOsd() {
|
||||||
return Dashboard.navigate('video');
|
Dashboard.navigate('video');
|
||||||
}
|
}
|
||||||
|
|
||||||
showSelectServer() {
|
showSelectServer() {
|
||||||
Dashboard.navigate(AppInfo.isNativeApp ? 'selectserver.html' : 'login.html');
|
Dashboard.navigate('selectserver.html');
|
||||||
}
|
|
||||||
|
|
||||||
showWelcome() {
|
|
||||||
Dashboard.navigate(AppInfo.isNativeApp ? 'selectserver.html' : 'login.html');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
showSettings() {
|
showSettings() {
|
||||||
|
@ -282,9 +279,6 @@ class AppRouter {
|
||||||
case 'ServerSelection':
|
case 'ServerSelection':
|
||||||
this.showSelectServer();
|
this.showSelectServer();
|
||||||
break;
|
break;
|
||||||
case 'ConnectSignIn':
|
|
||||||
this.showWelcome();
|
|
||||||
break;
|
|
||||||
case 'ServerUpdateNeeded':
|
case 'ServerUpdateNeeded':
|
||||||
import('alert').then(({default: alert}) =>{
|
import('alert').then(({default: alert}) =>{
|
||||||
alert({
|
alert({
|
||||||
|
@ -510,25 +504,33 @@ class AppRouter {
|
||||||
|
|
||||||
authenticate(ctx, route, callback) {
|
authenticate(ctx, route, callback) {
|
||||||
const firstResult = this.firstConnectionResult;
|
const firstResult = this.firstConnectionResult;
|
||||||
if (firstResult) {
|
|
||||||
this.firstConnectionResult = null;
|
this.firstConnectionResult = null;
|
||||||
|
if (firstResult && firstResult.State === 'ServerSignIn' && !route.anonymous) {
|
||||||
if (firstResult.State !== 'SignedIn' && !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);
|
this.handleConnectionResult(firstResult);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}).catch(error => {
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.debug('processing path request: ' + pathname);
|
||||||
const apiClient = window.connectionManager.currentApiClient();
|
const apiClient = window.connectionManager.currentApiClient();
|
||||||
const pathname = ctx.pathname.toLowerCase();
|
const pathname = ctx.pathname.toLowerCase();
|
||||||
|
|
||||||
console.debug('appRouter - processing path request ' + pathname);
|
|
||||||
|
|
||||||
const isCurrentRouteStartup = this.currentRouteInfo ? this.currentRouteInfo.route.startup : true;
|
const isCurrentRouteStartup = this.currentRouteInfo ? this.currentRouteInfo.route.startup : true;
|
||||||
const shouldExitApp = ctx.isBack && route.isDefaultRoute && isCurrentRouteStartup;
|
const shouldExitApp = ctx.isBack && route.isDefaultRoute && isCurrentRouteStartup;
|
||||||
|
|
||||||
if (!shouldExitApp && (!apiClient || !apiClient.isLoggedIn()) && !route.anonymous) {
|
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();
|
this.beginConnectionWizard();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -536,16 +538,16 @@ class AppRouter {
|
||||||
if (shouldExitApp) {
|
if (shouldExitApp) {
|
||||||
if (appHost.supports('exit')) {
|
if (appHost.supports('exit')) {
|
||||||
appHost.exit();
|
appHost.exit();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (apiClient && apiClient.isLoggedIn()) {
|
if (apiClient && apiClient.isLoggedIn()) {
|
||||||
console.debug('appRouter - user is authenticated');
|
console.debug('user is authenticated');
|
||||||
|
|
||||||
if (route.isDefaultRoute) {
|
if (route.isDefaultRoute) {
|
||||||
console.debug('appRouter - loading skin home page');
|
console.debug('loading home page');
|
||||||
Emby.Page.goHome();
|
Emby.Page.goHome();
|
||||||
return;
|
return;
|
||||||
} else if (route.roles) {
|
} else if (route.roles) {
|
||||||
|
@ -556,7 +558,7 @@ class AppRouter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.debug('appRouter - proceeding to ' + pathname);
|
console.debug('proceeding to page: ' + pathname);
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ define(function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// hack to work around the server's auto-redirection feature
|
// 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 {
|
return {
|
||||||
|
|
||||||
|
|
|
@ -44,10 +44,6 @@ import 'emby-button';
|
||||||
|
|
||||||
ApiClient.updateNamedConfiguration(brandingConfigKey, brandingConfig).then(function () {
|
ApiClient.updateNamedConfiguration(brandingConfigKey, brandingConfig).then(function () {
|
||||||
Dashboard.processServerConfigurationUpdateResult();
|
Dashboard.processServerConfigurationUpdateResult();
|
||||||
|
|
||||||
if (requiresReload && !AppInfo.isNativeApp) {
|
|
||||||
window.location.reload(true);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}, function () {
|
}, function () {
|
||||||
|
|
|
@ -1,35 +1,41 @@
|
||||||
|
import * as webSettings from 'webSettings';
|
||||||
|
|
||||||
export function getCurrentUser() {
|
export function getCurrentUser() {
|
||||||
return window.ApiClient.getCurrentUser(false);
|
return window.ApiClient.getCurrentUser(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: investigate url prefix support for serverAddress function
|
// TODO: investigate url prefix support for serverAddress function
|
||||||
export function serverAddress() {
|
export async function serverAddress() {
|
||||||
if (AppInfo.isNativeApp) {
|
|
||||||
const apiClient = window.ApiClient;
|
const apiClient = window.ApiClient;
|
||||||
|
|
||||||
if (apiClient) {
|
if (apiClient) {
|
||||||
return apiClient.serverAddress();
|
return Promise.resolve(apiClient.serverAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
let current = await window.connectionManager.getAvailableServers().then(servers => {
|
||||||
|
if (servers.length !== 0) {
|
||||||
|
return Promise.resolve(servers[0].ManualAddress);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const urlLower = window.location.href.toLowerCase();
|
if (current) return Promise.resolve(current);
|
||||||
const index = urlLower.lastIndexOf('/web');
|
|
||||||
|
|
||||||
if (index != -1) {
|
let urls = [];
|
||||||
return urlLower.substring(0, index);
|
urls.push(`${window.location.origin}/System/Info/Public`);
|
||||||
}
|
urls.push(`${window.location.protocol}//${window.location.hostname}:8096/System/Info/Public`);
|
||||||
|
|
||||||
const loc = window.location;
|
let promises = urls.map(url => {
|
||||||
let address = loc.protocol + '//' + loc.hostname;
|
return fetch(url).catch(error => {
|
||||||
|
return Promise.resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
if (loc.port) {
|
return Promise.all(promises).then(responses => {
|
||||||
address += ':' + loc.port;
|
return responses.find(response => response && response.ok);
|
||||||
}
|
}).then(response => response.url).catch(error => {
|
||||||
|
console.log(error);
|
||||||
return address;
|
return Promise.resolve();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCurrentUserId() {
|
export function getCurrentUserId() {
|
||||||
|
@ -49,16 +55,9 @@ export function onServerChanged(userId, accessToken, apiClient) {
|
||||||
|
|
||||||
export function logout() {
|
export function logout() {
|
||||||
window.connectionManager.logout().then(function () {
|
window.connectionManager.logout().then(function () {
|
||||||
let loginPage;
|
webSettings.getMultiServer().then(multi => {
|
||||||
|
multi ? navigate('selectserver.html') : navigate('login.html');
|
||||||
if (AppInfo.isNativeApp) {
|
});
|
||||||
loginPage = 'selectserver.html';
|
|
||||||
window.ApiClient = null;
|
|
||||||
} else {
|
|
||||||
loginPage = 'login.html';
|
|
||||||
}
|
|
||||||
|
|
||||||
navigate(loginPage);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -209,7 +209,7 @@ export class UserSettings {
|
||||||
}
|
}
|
||||||
|
|
||||||
val = this.get('enableBackdrops', false);
|
val = this.get('enableBackdrops', false);
|
||||||
return val !== 'false';
|
return val === 'true';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -63,7 +63,7 @@ function initClient() {
|
||||||
if (!localApiClient) {
|
if (!localApiClient) {
|
||||||
var server = window.connectionManager.getLastUsedServer();
|
var server = window.connectionManager.getLastUsedServer();
|
||||||
|
|
||||||
if (server) {
|
if (server && server.Id) {
|
||||||
localApiClient = window.connectionManager.getApiClient(server.Id);
|
localApiClient = window.connectionManager.getApiClient(server.Id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,42 +83,40 @@ function initClient() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function createConnectionManager() {
|
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;
|
appHost = appHost.default || appHost;
|
||||||
|
|
||||||
var credentialProviderInstance = new credentialProvider();
|
var credentialProviderInstance = new credentialProvider();
|
||||||
var promises = [appHost.init()];
|
var promises = [appHost.init()];
|
||||||
|
|
||||||
return Promise.all(promises).then(function (responses) {
|
return Promise.all(promises).then(responses => {
|
||||||
var capabilities = Dashboard.capabilities(appHost);
|
var capabilities = Dashboard.capabilities(appHost);
|
||||||
|
|
||||||
window.connectionManager = new ConnectionManager(credentialProviderInstance, appHost.appName(), appHost.appVersion(), appHost.deviceName(), appHost.deviceId(), capabilities);
|
window.connectionManager = new ConnectionManager(credentialProviderInstance, appHost.appName(), appHost.appVersion(), appHost.deviceName(), appHost.deviceId(), capabilities);
|
||||||
|
|
||||||
bindConnectionManagerEvents(window.connectionManager, events, userSettings);
|
bindConnectionManagerEvents(window.connectionManager, events, userSettings);
|
||||||
|
clientUtils.serverAddress().then(server => {
|
||||||
|
if (!server) {
|
||||||
|
Dashboard.navigate('selectserver.html');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!AppInfo.isNativeApp) {
|
console.debug('creating apiclient singleton');
|
||||||
console.debug('loading ApiClient singleton');
|
let parts = server.split('/');
|
||||||
|
let url = parts[0] + '//' + parts[2];
|
||||||
return require(['apiclient', 'clientUtils'], function (apiClientFactory, clientUtils) {
|
var apiClient = new apiClientFactory(url, appHost.appName(), appHost.appVersion(), appHost.deviceName(), appHost.deviceId());
|
||||||
console.debug('creating ApiClient singleton');
|
|
||||||
|
|
||||||
var apiClient = new apiClientFactory(Dashboard.serverAddress(), appHost.appName(), appHost.appVersion(), appHost.deviceName(), appHost.deviceId());
|
|
||||||
|
|
||||||
apiClient.enableAutomaticNetworking = false;
|
apiClient.enableAutomaticNetworking = false;
|
||||||
apiClient.manualAddressOnly = true;
|
apiClient.manualAddressOnly = true;
|
||||||
|
|
||||||
window.connectionManager.addApiClient(apiClient);
|
window.connectionManager.addApiClient(apiClient);
|
||||||
|
|
||||||
window.ApiClient = apiClient;
|
window.ApiClient = apiClient;
|
||||||
localApiClient = apiClient;
|
console.debug('loaded apiclient singleton');
|
||||||
|
|
||||||
console.debug('loaded ApiClient singleton');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function returnFirstDependency(obj) {
|
function returnFirstDependency(obj) {
|
||||||
|
@ -434,10 +432,6 @@ function initClient() {
|
||||||
|
|
||||||
define('castSenderApiLoader', [componentsPath + '/castSenderApi'], returnFirstDependency);
|
define('castSenderApiLoader', [componentsPath + '/castSenderApi'], returnFirstDependency);
|
||||||
|
|
||||||
if (window.appMode === 'cordova' || window.appMode === 'android' || window.appMode === 'standalone') {
|
|
||||||
AppInfo.isNativeApp = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
(function() {
|
|
||||||
'use strict';
|
|
||||||
window.appMode = 'standalone';
|
|
||||||
})();
|
|
Loading…
Add table
Add a link
Reference in a new issue