mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
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
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue