]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/core/theme/theme.service.ts
Increase test timeout
[github/Chocobozzz/PeerTube.git] / client / src / app / core / theme / theme.service.ts
index c9e6fa7005475ca85b5e4e6812b80d32224372d6..da6f2442a290bdf33c0c88356931a7fbdd386865 100644 (file)
@@ -1,5 +1,5 @@
-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'
@@ -41,6 +41,19 @@ export class ThemeService {
     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
 
@@ -82,10 +95,7 @@ export class ThemeService {
     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'
     }
 
@@ -141,7 +151,6 @@ export class ThemeService {
     }
 
     this.auth.userInformationLoaded
-      .pipe(first())
       .subscribe(() => this.updateCurrentTheme())
   }
 
@@ -195,4 +204,8 @@ export class ThemeService {
   private getTheme (name: string) {
     return this.themes.find(t => t.name === name)
   }
+
+  private hasDarkTheme () {
+    return this.serverConfig.theme.registered.some(t => t.name === 'dark')
+  }
 }