-import { first } from 'rxjs/operators'
import { Injectable } from '@angular/core'
+import { capitalizeFirstLetter } from '@root-helpers/string'
import { UserLocalStorageKeys } from '@root-helpers/users'
import { HTMLServerConfig, ServerConfigTheme } from '@shared/models'
import { environment } from '../../../environments/environment'
this.listenUserTheme()
}
+ getDefaultThemeLabel () {
+ if (this.hasDarkTheme()) {
+ return $localize`Light/Orange or Dark`
+ }
+
+ return $localize`Light/Orange`
+ }
+
+ getAvailableThemeLabels () {
+ return this.serverConfig.theme.registered
+ .map(t => capitalizeFirstLetter(t.name))
+ }
+
private injectThemes (themes: ServerConfigTheme[], fromLocalStorage = false) {
this.themes = themes
if (instanceTheme !== 'default') return instanceTheme
// Default to dark theme if available and wanted by the user
- if (
- this.themes.find(t => t.name === 'dark') &&
- window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
- ) {
+ if (this.hasDarkTheme() && window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
return 'dark'
}
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
}
}
const theme = this.getTheme(currentTheme)
if (theme) {
console.log('Adding scripts of theme %s.', currentTheme)
+
this.pluginService.addPlugin(theme, true)
this.pluginService.reloadLoadedScopes()
}
this.auth.userInformationLoaded
- .pipe(first())
.subscribe(() => this.updateCurrentTheme())
}
private getTheme (name: string) {
return this.themes.find(t => t.name === name)
}
+
+ private hasDarkTheme () {
+ return this.serverConfig.theme.registered.some(t => t.name === 'dark')
+ }
}