]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/core/theme/theme.service.ts
Oup's
[github/Chocobozzz/PeerTube.git] / client / src / app / core / theme / theme.service.ts
index d8e02e2e5747fc0937d7b9caf1e6e2164f753588..a6eef089843017bb889e5ef4b55f579597df0d78 100644 (file)
@@ -1,8 +1,10 @@
 import { Injectable } from '@angular/core'
+import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage'
 
 @Injectable()
 export class ThemeService {
   private theme = document.querySelector('body')
+  private darkTheme = false
   private previousTheme = {}
 
   constructor () {
@@ -12,15 +14,23 @@ export class ThemeService {
     this.previousTheme['submenuColor'] = 'rgb(32,32,32)'
     this.previousTheme['inputColor'] = 'gray'
     this.previousTheme['inputPlaceholderColor'] = '#fff'
+
+    this.darkTheme = (peertubeLocalStorage.getItem('theme') === 'dark')
+    if (this.darkTheme) this.toggleDarkTheme(false)
   }
 
-  toggleDarkTheme () {
+  toggleDarkTheme (setLocalStorage = true) {
     // switch properties
     this.switchProperty('mainBackgroundColor')
     this.switchProperty('mainForegroundColor')
     this.switchProperty('submenuColor')
     this.switchProperty('inputColor')
     this.switchProperty('inputPlaceholderColor')
+
+    if (setLocalStorage) {
+      this.darkTheme = !this.darkTheme
+      peertubeLocalStorage.setItem('theme', (this.darkTheme) ? 'dark' : 'default')
+    }
   }
 
   private switchProperty (property, newValue?) {