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 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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -44,10 +44,6 @@ import 'emby-button';
|
|||
|
||||
ApiClient.updateNamedConfiguration(brandingConfigKey, brandingConfig).then(function () {
|
||||
Dashboard.processServerConfigurationUpdateResult();
|
||||
|
||||
if (requiresReload && !AppInfo.isNativeApp) {
|
||||
window.location.reload(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
}, function () {
|
||||
|
|
|
@ -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');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -209,7 +209,7 @@ export class UserSettings {
|
|||
}
|
||||
|
||||
val = this.get('enableBackdrops', false);
|
||||
return val !== 'false';
|
||||
return val === 'true';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
(function() {
|
||||
'use strict';
|
||||
window.appMode = 'standalone';
|
||||
})();
|
Loading…
Add table
Add a link
Reference in a new issue