mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Move clientUtils and rename
This commit is contained in:
parent
a238ae21f1
commit
2d2b99d3b9
61 changed files with 62 additions and 62 deletions
|
@ -1,7 +1,7 @@
|
|||
import backdrop from '../components/backdrop/backdrop';
|
||||
import * as userSettings from './settings/userSettings';
|
||||
import libraryMenu from './libraryMenu';
|
||||
import { pageClassOn } from './clientUtils';
|
||||
import { pageClassOn } from '../utils/dashboard';
|
||||
|
||||
const cache = {};
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import * as userSettings from './settings/userSettings';
|
|||
import skinManager from './themeManager';
|
||||
import { Events } from 'jellyfin-apiclient';
|
||||
import ServerConnections from '../components/ServerConnections';
|
||||
import { pageClassOn } from '../scripts/clientUtils';
|
||||
import { pageClassOn } from '../utils/dashboard';
|
||||
|
||||
// Set the default theme when loading
|
||||
skinManager.setTheme(userSettings.theme())
|
||||
|
|
|
@ -1,244 +0,0 @@
|
|||
import ServerConnections from '../components/ServerConnections';
|
||||
import toast from '../components/toast/toast';
|
||||
import loading from '../components/loading/loading';
|
||||
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';
|
||||
import datetime from '../scripts/datetime';
|
||||
import DirectoryBrowser from '../components/directorybrowser/directorybrowser';
|
||||
import dialogHelper from '../components/dialogHelper/dialogHelper';
|
||||
import itemIdentifier from '../components/itemidentifier/itemidentifier';
|
||||
import { getLocationSearch } from '../utils/url.ts';
|
||||
|
||||
export function getCurrentUser() {
|
||||
return window.ApiClient.getCurrentUser(false);
|
||||
}
|
||||
|
||||
// TODO: investigate url prefix support for serverAddress function
|
||||
export async function serverAddress() {
|
||||
const apiClient = window.ApiClient;
|
||||
|
||||
if (apiClient) {
|
||||
return Promise.resolve(apiClient.serverAddress());
|
||||
}
|
||||
|
||||
// Use servers specified in config.json
|
||||
const urls = await webSettings.getServers();
|
||||
|
||||
if (urls.length === 0) {
|
||||
// Otherwise use computed base URL
|
||||
let url;
|
||||
const index = window.location.href.toLowerCase().lastIndexOf('/web');
|
||||
if (index != -1) {
|
||||
url = window.location.href.substring(0, index);
|
||||
} else {
|
||||
// fallback to location without path
|
||||
url = window.location.origin;
|
||||
}
|
||||
|
||||
// Don't use bundled app URL (file:) as server URL
|
||||
if (url.startsWith('file:')) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
urls.push(url);
|
||||
}
|
||||
|
||||
console.debug('URL candidates:', urls);
|
||||
|
||||
const promises = urls.map(url => {
|
||||
return fetch(`${url}/System/Info/Public`).then(resp => {
|
||||
return {
|
||||
url: url,
|
||||
response: resp
|
||||
};
|
||||
}).catch(() => {
|
||||
return Promise.resolve();
|
||||
});
|
||||
});
|
||||
|
||||
return Promise.all(promises).then(responses => {
|
||||
responses = responses.filter(obj => obj && obj.response.ok);
|
||||
return Promise.all(responses.map(obj => {
|
||||
return {
|
||||
url: obj.url,
|
||||
config: obj.response.json()
|
||||
};
|
||||
}));
|
||||
}).then(configs => {
|
||||
const selection = configs.find(obj => !obj.config.StartupWizardCompleted) || configs[0];
|
||||
return Promise.resolve(selection?.url);
|
||||
}).catch(error => {
|
||||
console.log(error);
|
||||
return Promise.resolve();
|
||||
});
|
||||
}
|
||||
|
||||
export function getCurrentUserId() {
|
||||
const apiClient = window.ApiClient;
|
||||
|
||||
if (apiClient) {
|
||||
return apiClient.getCurrentUserId();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function onServerChanged(userId, accessToken, apiClient) {
|
||||
ServerConnections.setLocalApiClient(apiClient);
|
||||
}
|
||||
|
||||
export function logout() {
|
||||
ServerConnections.logout().then(function () {
|
||||
webSettings.getMultiServer().then(multi => {
|
||||
multi ? navigate('selectserver.html') : navigate('login.html');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function getPluginUrl(name) {
|
||||
return 'configurationpage?name=' + encodeURIComponent(name);
|
||||
}
|
||||
|
||||
export function getConfigurationResourceUrl(name) {
|
||||
return ApiClient.getUrl('web/ConfigurationPage', {
|
||||
name: name
|
||||
});
|
||||
}
|
||||
|
||||
export function navigate(url, preserveQueryString) {
|
||||
if (!url) {
|
||||
throw new Error('url cannot be null or empty');
|
||||
}
|
||||
|
||||
const queryString = getLocationSearch();
|
||||
|
||||
if (preserveQueryString && queryString) {
|
||||
url += queryString;
|
||||
}
|
||||
|
||||
return appRouter.show(url);
|
||||
}
|
||||
|
||||
export function processPluginConfigurationUpdateResult() {
|
||||
loading.hide();
|
||||
toast(globalize.translate('SettingsSaved'));
|
||||
}
|
||||
|
||||
export function processServerConfigurationUpdateResult() {
|
||||
loading.hide();
|
||||
toast(globalize.translate('SettingsSaved'));
|
||||
}
|
||||
|
||||
export function processErrorResponse(response) {
|
||||
loading.hide();
|
||||
|
||||
let status = '' + response.status;
|
||||
|
||||
if (response.statusText) {
|
||||
status = response.statusText;
|
||||
}
|
||||
|
||||
baseAlert({
|
||||
title: status,
|
||||
text: response.headers ? response.headers.get('X-Application-Error-Code') : null
|
||||
});
|
||||
}
|
||||
|
||||
export function alert(options) {
|
||||
if (typeof options == 'string') {
|
||||
toast({
|
||||
text: options
|
||||
});
|
||||
} else {
|
||||
baseAlert({
|
||||
title: options.title || globalize.translate('HeaderAlert'),
|
||||
text: options.message
|
||||
}).then(options.callback || function () { /* no-op */ });
|
||||
}
|
||||
}
|
||||
|
||||
export function capabilities(appHost) {
|
||||
return Object.assign({
|
||||
PlayableMediaTypes: ['Audio', 'Video'],
|
||||
SupportedCommands: ['MoveUp', 'MoveDown', 'MoveLeft', 'MoveRight', 'PageUp', 'PageDown', 'PreviousLetter', 'NextLetter', 'ToggleOsd', 'ToggleContextMenu', 'Select', 'Back', 'SendKey', 'SendString', 'GoHome', 'GoToSettings', 'VolumeUp', 'VolumeDown', 'Mute', 'Unmute', 'ToggleMute', 'SetVolume', 'SetAudioStreamIndex', 'SetSubtitleStreamIndex', 'DisplayContent', 'GoToSearch', 'DisplayMessage', 'SetRepeatMode', 'SetShuffleQueue', 'ChannelUp', 'ChannelDown', 'PlayMediaSource', 'PlayTrailers'],
|
||||
SupportsPersistentIdentifier: window.appMode === 'cordova' || window.appMode === 'android',
|
||||
SupportsMediaControl: true
|
||||
}, appHost.getPushTokenInfo());
|
||||
}
|
||||
|
||||
export function selectServer() {
|
||||
if (window.NativeShell && typeof window.NativeShell.selectServer === 'function') {
|
||||
window.NativeShell.selectServer();
|
||||
} else {
|
||||
navigate('selectserver.html');
|
||||
}
|
||||
}
|
||||
|
||||
export function hideLoadingMsg() {
|
||||
loading.hide();
|
||||
}
|
||||
|
||||
export function showLoadingMsg() {
|
||||
loading.show();
|
||||
}
|
||||
|
||||
export function confirm(message, title, callback) {
|
||||
baseConfirm(message, title).then(function() {
|
||||
callback(true);
|
||||
}).catch(function() {
|
||||
callback(false);
|
||||
});
|
||||
}
|
||||
|
||||
export const pageClassOn = function(eventName, className, fn) {
|
||||
document.addEventListener(eventName, function (event) {
|
||||
const target = event.target;
|
||||
|
||||
if (target.classList.contains(className)) {
|
||||
fn.call(target, event);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const pageIdOn = function(eventName, id, fn) {
|
||||
document.addEventListener(eventName, function (event) {
|
||||
const target = event.target;
|
||||
|
||||
if (target.id === id) {
|
||||
fn.call(target, event);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const Dashboard = {
|
||||
alert,
|
||||
capabilities,
|
||||
confirm,
|
||||
getPluginUrl,
|
||||
getConfigurationResourceUrl,
|
||||
getCurrentUser,
|
||||
getCurrentUserId,
|
||||
hideLoadingMsg,
|
||||
logout,
|
||||
navigate,
|
||||
onServerChanged,
|
||||
processErrorResponse,
|
||||
processPluginConfigurationUpdateResult,
|
||||
processServerConfigurationUpdateResult,
|
||||
selectServer,
|
||||
serverAddress,
|
||||
showLoadingMsg,
|
||||
datetime,
|
||||
DirectoryBrowser,
|
||||
dialogHelper,
|
||||
itemIdentifier
|
||||
};
|
||||
|
||||
// This is used in plugins and templates, so keep it defined for now.
|
||||
// TODO: Remove once plugins don't need it
|
||||
window.Dashboard = Dashboard;
|
||||
|
||||
export default Dashboard;
|
|
@ -2,7 +2,7 @@ import escapeHtml from 'escape-html';
|
|||
import 'jquery';
|
||||
import globalize from './globalize';
|
||||
import 'material-design-icons-iconfont';
|
||||
import Dashboard from './clientUtils';
|
||||
import Dashboard from '../utils/dashboard';
|
||||
import { getParameterByName } from '../utils/url.ts';
|
||||
|
||||
/* eslint-disable indent */
|
||||
|
|
|
@ -16,7 +16,7 @@ import '../elements/emby-button/paper-icon-button-light';
|
|||
import 'material-design-icons-iconfont';
|
||||
import '../assets/css/scrollstyles.scss';
|
||||
import '../assets/css/flexstyles.scss';
|
||||
import Dashboard, { pageClassOn } from './clientUtils';
|
||||
import Dashboard, { pageClassOn } from '../utils/dashboard';
|
||||
import ServerConnections from '../components/ServerConnections';
|
||||
import Headroom from 'headroom.js';
|
||||
import { getParameterByName } from '../utils/url.ts';
|
||||
|
|
|
@ -6,7 +6,7 @@ import libraryBrowser from './libraryBrowser';
|
|||
import imageLoader from '../components/images/imageLoader';
|
||||
import * as userSettings from './settings/userSettings';
|
||||
import '../elements/emby-itemscontainer/emby-itemscontainer';
|
||||
import Dashboard from './clientUtils';
|
||||
import Dashboard from '../utils/dashboard';
|
||||
|
||||
export default function (view) {
|
||||
function getPageData(context) {
|
||||
|
|
|
@ -25,7 +25,7 @@ import './libraryMenu';
|
|||
import './routes';
|
||||
import '../components/themeMediaPlayer';
|
||||
import './autoBackdrops';
|
||||
import { pageClassOn, serverAddress } from './clientUtils';
|
||||
import { pageClassOn, serverAddress } from '../utils/dashboard';
|
||||
import './screensavermanager';
|
||||
import './serverNotifications';
|
||||
import '../components/playback/playerSelectionMenu';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue