mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Merge pull request #1918 from jellyfin/standalone
Fix startup wizard redirect and standalone mode
This commit is contained in:
commit
3961657c70
10 changed files with 104 additions and 134 deletions
|
@ -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';
|
||||
|
@ -6,38 +5,48 @@ import { appRouter } from '../components/appRouter';
|
|||
import baseAlert from '../components/alert';
|
||||
import baseConfirm from '../components/confirm/confirm';
|
||||
import globalize from '../scripts/globalize';
|
||||
import * as webSettings from './settings/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());
|
||||
}
|
||||
|
||||
const current = await ServerConnections.getAvailableServers().then(servers => {
|
||||
if (servers.length !== 0) {
|
||||
return Promise.resolve(servers[0].ManualAddress);
|
||||
}
|
||||
});
|
||||
|
||||
return null;
|
||||
}
|
||||
// TODO this makes things faster but it also blocks the wizard in some scenarios
|
||||
// if (current) return Promise.resolve(current);
|
||||
|
||||
const urlLower = window.location.href.toLowerCase();
|
||||
const index = urlLower.lastIndexOf('/web');
|
||||
const urls = [];
|
||||
urls.push(window.location.origin);
|
||||
urls.push(`https://${window.location.hostname}:8920`);
|
||||
urls.push(`http://${window.location.hostname}:8096`);
|
||||
urls.push(...await webSettings.getServers());
|
||||
|
||||
if (index != -1) {
|
||||
return urlLower.substring(0, index);
|
||||
}
|
||||
const promises = urls.map(url => {
|
||||
return fetch(`${url}/System/Info/Public`).then(resp => 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 => {
|
||||
responses = responses.filter(response => response);
|
||||
return responses[0];
|
||||
}).catch(error => {
|
||||
console.log(error);
|
||||
return Promise.resolve();
|
||||
});
|
||||
}
|
||||
|
||||
export function getCurrentUserId() {
|
||||
|
@ -56,16 +65,9 @@ export function onServerChanged(userId, accessToken, apiClient) {
|
|||
|
||||
export function logout() {
|
||||
ServerConnections.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');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -85,6 +85,15 @@ export function getMultiServer() {
|
|||
});
|
||||
}
|
||||
|
||||
export function getServers() {
|
||||
return getConfig().then(config => {
|
||||
return config.servers || [];
|
||||
}).catch(error => {
|
||||
console.log('cannot get web config:', error);
|
||||
return [];
|
||||
});
|
||||
}
|
||||
|
||||
const baseDefaultTheme = {
|
||||
'name': 'Dark',
|
||||
'id': 'dark',
|
||||
|
|
|
@ -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';
|
||||
|
@ -26,7 +25,7 @@ import './libraryMenu';
|
|||
import './routes';
|
||||
import '../components/themeMediaPlayer';
|
||||
import './autoBackdrops';
|
||||
import { pageClassOn } from './clientUtils';
|
||||
import { navigate, pageClassOn, serverAddress } from './clientUtils';
|
||||
import '../libraries/screensavermanager';
|
||||
import './serverNotifications';
|
||||
import '../components/playback/playerSelectionMenu';
|
||||
|
@ -60,12 +59,6 @@ window.getParameterByName = function(name, url) {
|
|||
return decodeURIComponent(results[1].replace(/\+/g, ' '));
|
||||
};
|
||||
|
||||
if (window.appMode === 'cordova' || window.appMode === 'android' || window.appMode === 'standalone') {
|
||||
AppInfo.isNativeApp = true;
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -82,18 +75,25 @@ function loadCoreDictionary() {
|
|||
}
|
||||
|
||||
function init() {
|
||||
ServerConnections.initApiClient();
|
||||
serverAddress().then(server => {
|
||||
if (!server) {
|
||||
navigate('selectserver.html');
|
||||
return;
|
||||
}
|
||||
|
||||
console.debug('initAfterDependencies promises resolved');
|
||||
ServerConnections.initApiClient(server);
|
||||
}).then(() => {
|
||||
console.debug('initAfterDependencies promises resolved');
|
||||
|
||||
loadCoreDictionary().then(function () {
|
||||
onGlobalizeInit();
|
||||
loadCoreDictionary().then(function () {
|
||||
onGlobalizeInit();
|
||||
});
|
||||
|
||||
keyboardNavigation.enable();
|
||||
autoFocuser.enable();
|
||||
|
||||
Events.on(ServerConnections, 'localusersignedin', globalize.updateCurrentCulture);
|
||||
});
|
||||
|
||||
keyboardNavigation.enable();
|
||||
autoFocuser.enable();
|
||||
|
||||
Events.on(ServerConnections, 'localusersignedin', globalize.updateCurrentCulture);
|
||||
}
|
||||
|
||||
function onGlobalizeInit() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue