diff options
Diffstat (limited to 'ufund-ui/src/app/app.component.ts')
-rw-r--r-- | ufund-ui/src/app/app.component.ts | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/ufund-ui/src/app/app.component.ts b/ufund-ui/src/app/app.component.ts index 615397f..78fd050 100644 --- a/ufund-ui/src/app/app.component.ts +++ b/ufund-ui/src/app/app.component.ts @@ -40,6 +40,15 @@ export class AppComponent implements OnInit { this.authService.restoreLogin(dataParsed.username, dataParsed.key) console.log("Key found", dataParsed.key) } + + let theme = localStorage.getItem("theme") + if(!theme) { + // if no color scheme is set, get the system settings + let preferredTheme = this.document.defaultView?.matchMedia('(prefers-color-scheme: light)').matches ? "light" : "dark"; + localStorage.setItem("theme",preferredTheme); + theme = preferredTheme; + } + this.document.body.parentElement!.setAttribute("theme",theme); } login() { @@ -51,5 +60,17 @@ export class AppComponent implements OnInit { location.reload() } + toggleColorScheme() { + let theme = localStorage.getItem("theme"); + // fallback + if (!theme) { + theme = "light"; + } + let newTheme = theme == "light" ? "dark" : "light"; + this.document.body.parentElement!.setAttribute("theme",newTheme); + localStorage.setItem("theme", newTheme); + console.log(newTheme, this.document.body.parentElement); + } + protected readonly userType = userType; } |