aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/core
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-06-16 14:36:51 +0200
committerChocobozzz <me@florianbigard.com>2022-06-16 14:44:14 +0200
commit5e93a6d142b1151d1ebc16123206f87998839108 (patch)
tree71dff17c1a79bb87e753216a83e317ad6efebf47 /client/src/app/core
parent3256771725430ab6fc716e937b88ca2b2b85263b (diff)
downloadPeerTube-5e93a6d142b1151d1ebc16123206f87998839108.tar.gz
PeerTube-5e93a6d142b1151d1ebc16123206f87998839108.tar.zst
PeerTube-5e93a6d142b1151d1ebc16123206f87998839108.zip
Improve theme label
Diffstat (limited to 'client/src/app/core')
-rw-r--r--client/src/app/core/theme/theme.service.ts23
1 files changed, 19 insertions, 4 deletions
diff --git a/client/src/app/core/theme/theme.service.ts b/client/src/app/core/theme/theme.service.ts
index e88511054..da6f2442a 100644
--- a/client/src/app/core/theme/theme.service.ts
+++ b/client/src/app/core/theme/theme.service.ts
@@ -1,4 +1,5 @@
1import { Injectable } from '@angular/core' 1import { Injectable } from '@angular/core'
2import { capitalizeFirstLetter } from '@root-helpers/string'
2import { UserLocalStorageKeys } from '@root-helpers/users' 3import { UserLocalStorageKeys } from '@root-helpers/users'
3import { HTMLServerConfig, ServerConfigTheme } from '@shared/models' 4import { HTMLServerConfig, ServerConfigTheme } from '@shared/models'
4import { environment } from '../../../environments/environment' 5import { environment } from '../../../environments/environment'
@@ -40,6 +41,19 @@ export class ThemeService {
40 this.listenUserTheme() 41 this.listenUserTheme()
41 } 42 }
42 43
44 getDefaultThemeLabel () {
45 if (this.hasDarkTheme()) {
46 return $localize`Light/Orange or Dark`
47 }
48
49 return $localize`Light/Orange`
50 }
51
52 getAvailableThemeLabels () {
53 return this.serverConfig.theme.registered
54 .map(t => capitalizeFirstLetter(t.name))
55 }
56
43 private injectThemes (themes: ServerConfigTheme[], fromLocalStorage = false) { 57 private injectThemes (themes: ServerConfigTheme[], fromLocalStorage = false) {
44 this.themes = themes 58 this.themes = themes
45 59
@@ -81,10 +95,7 @@ export class ThemeService {
81 if (instanceTheme !== 'default') return instanceTheme 95 if (instanceTheme !== 'default') return instanceTheme
82 96
83 // Default to dark theme if available and wanted by the user 97 // Default to dark theme if available and wanted by the user
84 if ( 98 if (this.hasDarkTheme() && window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
85 this.themes.find(t => t.name === 'dark') &&
86 window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
87 ) {
88 return 'dark' 99 return 'dark'
89 } 100 }
90 101
@@ -193,4 +204,8 @@ export class ThemeService {
193 private getTheme (name: string) { 204 private getTheme (name: string) {
194 return this.themes.find(t => t.name === name) 205 return this.themes.find(t => t.name === name)
195 } 206 }
207
208 private hasDarkTheme () {
209 return this.serverConfig.theme.registered.some(t => t.name === 'dark')
210 }
196} 211}