X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fcore%2Ftheme%2Ftheme.service.ts;h=ac34689419df7a271cb7edc05ace477904083e85;hb=0882c8e6509b2a4ea48f6c48ecb2aa4aa371500a;hp=e7a5ae17a52d7e24867fae535e271817c49eb261;hpb=8f608a4cb22ab232cfab20665050764b38bac9c7;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/core/theme/theme.service.ts b/client/src/app/core/theme/theme.service.ts index e7a5ae17a..ac3468941 100644 --- a/client/src/app/core/theme/theme.service.ts +++ b/client/src/app/core/theme/theme.service.ts @@ -1,7 +1,7 @@ import { first } from 'rxjs/operators' import { Injectable } from '@angular/core' import { UserLocalStorageKeys } from '@root-helpers/users' -import { ServerConfig, ServerConfigTheme } from '@shared/models' +import { HTMLServerConfig, ServerConfigTheme } from '@shared/models' import { environment } from '../../../environments/environment' import { AuthService } from '../auth' import { PluginService } from '../plugins/plugin.service' @@ -18,7 +18,7 @@ export class ThemeService { private themeFromLocalStorage: ServerConfigTheme private themeDOMLinksFromLocalStorage: HTMLLinkElement[] = [] - private serverConfig: ServerConfig + private serverConfig: HTMLServerConfig constructor ( private auth: AuthService, @@ -32,18 +32,13 @@ export class ThemeService { // Try to load from local storage first, so we don't have to wait network requests this.loadAndSetFromLocalStorage() - this.serverConfig = this.server.getTmpConfig() - this.server.getConfig() - .subscribe(config => { - this.serverConfig = config + this.serverConfig = this.server.getHTMLConfig() + const themes = this.serverConfig.theme.registered - const themes = this.serverConfig.theme.registered + this.removeThemeFromLocalStorageIfNeeded(themes) + this.injectThemes(themes) - this.removeThemeFromLocalStorageIfNeeded(themes) - this.injectThemes(themes) - - this.listenUserTheme() - }) + this.listenUserTheme() } private injectThemes (themes: ServerConfigTheme[], fromLocalStorage = false) { @@ -100,8 +95,8 @@ export class ThemeService { private loadTheme (name: string) { const links = document.getElementsByTagName('link') for (let i = 0; i < links.length; i++) { - const link = links[ i ] - if (link.getAttribute('rel').indexOf('style') !== -1 && link.getAttribute('title')) { + const link = links[i] + if (link.getAttribute('rel').includes('style') && link.getAttribute('title')) { link.disabled = link.getAttribute('title') !== name } } @@ -119,6 +114,7 @@ export class ThemeService { const theme = this.getTheme(currentTheme) if (theme) { console.log('Adding scripts of theme %s.', currentTheme) + this.pluginService.addPlugin(theme, true) this.pluginService.reloadLoadedScopes() @@ -145,7 +141,6 @@ export class ThemeService { } this.auth.userInformationLoaded - .pipe(first()) .subscribe(() => this.updateCurrentTheme()) }