mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Apply styles using user events and also immediately when changed.
This commit is contained in:
parent
99c902a1a1
commit
8d59d2a0fe
2 changed files with 48 additions and 55 deletions
|
@ -21,9 +21,6 @@ const defaultSubtitleAppearanceSettings = {
|
|||
|
||||
export class UserSettings {
|
||||
constructor() {
|
||||
this._userSetPromise = new Promise(resolve => {
|
||||
this._userSetPromiseResolve = resolve;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,11 +36,6 @@ export class UserSettings {
|
|||
this.currentUserId = userId;
|
||||
this.currentApiClient = apiClient;
|
||||
|
||||
if (this._userSetPromiseResolve) {
|
||||
this._userSetPromiseResolve();
|
||||
this._userSetPromiseResolve = null;
|
||||
}
|
||||
|
||||
if (!userId) {
|
||||
this.displayPrefs = null;
|
||||
return Promise.resolve();
|
||||
|
@ -67,14 +59,6 @@ export class UserSettings {
|
|||
this.displayPrefs = instance.getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows waiting until the user id is set.
|
||||
* @returns {Promise}
|
||||
*/
|
||||
userIsSet() {
|
||||
return this._userSetPromise;
|
||||
}
|
||||
|
||||
// FIXME: 'appSettings.set' doesn't return any value
|
||||
/**
|
||||
* Set value of setting.
|
||||
|
|
|
@ -176,7 +176,7 @@ function initSyncPlay() {
|
|||
Events.on(ServerConnections, 'apiclientcreated', (e, newApiClient) => SyncPlay.Manager.init(newApiClient));
|
||||
}
|
||||
|
||||
function onAppReady() {
|
||||
async function onAppReady() {
|
||||
console.debug('begin onAppReady');
|
||||
|
||||
console.debug('onAppReady: loading dependencies');
|
||||
|
@ -217,21 +217,9 @@ function onAppReady() {
|
|||
}
|
||||
}
|
||||
|
||||
let cssHasLoadedTrigger;
|
||||
const cssHasLoadedPromise = new Promise(resolve => {
|
||||
cssHasLoadedTrigger = resolve;
|
||||
});
|
||||
|
||||
const apiClient = ServerConnections.currentApiClient();
|
||||
if (apiClient) {
|
||||
fetch(apiClient.getUrl('Branding/Css'))
|
||||
.then(function(response) {
|
||||
if (!response.ok) {
|
||||
throw new Error(response.status + ' ' + response.statusText);
|
||||
}
|
||||
return response.text();
|
||||
})
|
||||
.then(function(css) {
|
||||
const updateStyle = (css) => {
|
||||
let style = document.querySelector('#cssBranding');
|
||||
if (!style) {
|
||||
// Inject the branding css as a dom element in body so it will take
|
||||
|
@ -241,33 +229,54 @@ function onAppReady() {
|
|||
document.body.appendChild(style);
|
||||
}
|
||||
style.textContent = css;
|
||||
cssHasLoadedTrigger(style);
|
||||
};
|
||||
|
||||
const style = 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);
|
||||
});
|
||||
}
|
||||
|
||||
currentSettings.userIsSet().then(() => {
|
||||
const handleStyleChange = async () => {
|
||||
if (currentSettings.disableCustomCss()) {
|
||||
cssHasLoadedPromise.then(style => {
|
||||
style.textContent = '';
|
||||
});
|
||||
updateStyle('');
|
||||
} else {
|
||||
updateStyle(await style);
|
||||
}
|
||||
|
||||
const localCss = currentSettings.customCss();
|
||||
let localStyle = document.querySelector('#localCssBranding');
|
||||
if (localCss) {
|
||||
let style = document.querySelector('#localCssBranding');
|
||||
if (!style) {
|
||||
if (!localStyle) {
|
||||
// Inject the branding css as a dom element in body so it will take
|
||||
// precedence over other stylesheets
|
||||
style = document.createElement('style');
|
||||
style.id = 'localCssBranding';
|
||||
document.body.appendChild(style);
|
||||
localStyle = document.createElement('style');
|
||||
localStyle.id = 'localCssBranding';
|
||||
document.body.appendChild(localStyle);
|
||||
}
|
||||
style.textContent = localCss;
|
||||
localStyle.textContent = localCss;
|
||||
} else {
|
||||
if (localStyle) {
|
||||
localStyle.textContent = '';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Events.on(ServerConnections, 'localusersignedin', handleStyleChange);
|
||||
Events.on(ServerConnections, 'localusersignedout', handleStyleChange);
|
||||
Events.on(currentSettings, 'change', (e, prop) => {
|
||||
if (prop == 'disableCustomCss' || prop == 'customCss') {
|
||||
handleStyleChange();
|
||||
}
|
||||
});
|
||||
|
||||
style.then(updateStyle);
|
||||
}
|
||||
}
|
||||
|
||||
function registerServiceWorker() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue