mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Move theme and custom css to react components
This commit is contained in:
parent
27f4b8a7e5
commit
88b247596a
8 changed files with 159 additions and 143 deletions
|
@ -17,7 +17,6 @@ import { loadCoreDictionary } from 'lib/globalize/loader';
|
|||
import { initialize as initializeAutoCast } from 'scripts/autocast';
|
||||
import browser from './scripts/browser';
|
||||
import keyboardNavigation from './scripts/keyboardNavigation';
|
||||
import { currentSettings } from './scripts/settings/userSettings';
|
||||
import { getPlugins } from './scripts/settings/webSettings';
|
||||
import taskButton from './scripts/taskbutton';
|
||||
import { pageClassOn, serverAddress } from './utils/dashboard';
|
||||
|
@ -116,9 +115,6 @@ build: ${__JF_BUILD_VERSION__}`);
|
|||
// Load platform specific features
|
||||
loadPlatformFeatures();
|
||||
|
||||
// Load custom CSS styles
|
||||
loadCustomCss();
|
||||
|
||||
// Enable navigation controls
|
||||
keyboardNavigation.enable();
|
||||
autoFocuser.enable();
|
||||
|
@ -191,54 +187,7 @@ function loadPlatformFeatures() {
|
|||
}
|
||||
}
|
||||
|
||||
function loadCustomCss() {
|
||||
// Apply custom CSS
|
||||
const apiClient = ServerConnections.currentApiClient();
|
||||
if (apiClient) {
|
||||
const brandingCss = fetch(apiClient.getUrl('Branding/Css'))
|
||||
.then(function(response) {
|
||||
if (!response.ok) {
|
||||
throw new Error(response.status + ' ' + response.statusText);
|
||||
}
|
||||
return response.text();
|
||||
})
|
||||
.catch(function(err) {
|
||||
console.warn('Error applying custom css', err);
|
||||
});
|
||||
|
||||
const handleStyleChange = async () => {
|
||||
let style = document.querySelector('#cssBranding');
|
||||
if (!style) {
|
||||
// Inject the branding css as a dom element in body so it will take
|
||||
// precedence over other stylesheets
|
||||
style = document.createElement('style');
|
||||
style.id = 'cssBranding';
|
||||
document.body.appendChild(style);
|
||||
}
|
||||
|
||||
const css = [];
|
||||
// Only add branding CSS when enabled
|
||||
if (!currentSettings.disableCustomCss()) css.push(await brandingCss);
|
||||
// Always add user CSS
|
||||
css.push(currentSettings.customCss());
|
||||
|
||||
style.textContent = css.join('\n');
|
||||
};
|
||||
|
||||
Events.on(ServerConnections, 'localusersignedin', handleStyleChange);
|
||||
Events.on(ServerConnections, 'localusersignedout', handleStyleChange);
|
||||
Events.on(currentSettings, 'change', (e, prop) => {
|
||||
if (prop == 'disableCustomCss' || prop == 'customCss') {
|
||||
handleStyleChange();
|
||||
}
|
||||
});
|
||||
|
||||
handleStyleChange();
|
||||
}
|
||||
}
|
||||
|
||||
function registerServiceWorker() {
|
||||
/* eslint-disable compat/compat */
|
||||
if (navigator.serviceWorker && window.appMode !== 'cordova' && window.appMode !== 'android') {
|
||||
navigator.serviceWorker.register('serviceworker.js').then(() =>
|
||||
console.log('serviceWorker registered')
|
||||
|
@ -248,7 +197,6 @@ function registerServiceWorker() {
|
|||
} else {
|
||||
console.warn('serviceWorker unsupported');
|
||||
}
|
||||
/* eslint-enable compat/compat */
|
||||
}
|
||||
|
||||
async function renderApp() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue