diff options
author | Chocobozzz <me@florianbigard.com> | 2022-06-16 14:36:51 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-06-16 14:44:14 +0200 |
commit | 5e93a6d142b1151d1ebc16123206f87998839108 (patch) | |
tree | 71dff17c1a79bb87e753216a83e317ad6efebf47 /client/src/app/core | |
parent | 3256771725430ab6fc716e937b88ca2b2b85263b (diff) | |
download | PeerTube-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.ts | 23 |
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 @@ | |||
1 | import { Injectable } from '@angular/core' | 1 | import { Injectable } from '@angular/core' |
2 | import { capitalizeFirstLetter } from '@root-helpers/string' | ||
2 | import { UserLocalStorageKeys } from '@root-helpers/users' | 3 | import { UserLocalStorageKeys } from '@root-helpers/users' |
3 | import { HTMLServerConfig, ServerConfigTheme } from '@shared/models' | 4 | import { HTMLServerConfig, ServerConfigTheme } from '@shared/models' |
4 | import { environment } from '../../../environments/environment' | 5 | import { 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 | } |