diff --git a/ui/src/app/app.component.ts b/ui/src/app/app.component.ts index 26ae3c5..970aa74 100644 --- a/ui/src/app/app.component.ts +++ b/ui/src/app/app.component.ts @@ -19,6 +19,7 @@ export class AppComponent implements AfterViewInit { quality: string; format: string; addInProgress = false; + darkMode: boolean; @ViewChild('queueMasterCheckbox') queueMasterCheckbox: MasterCheckboxComponent; @ViewChild('queueDelSelected') queueDelSelected: ElementRef; @@ -37,6 +38,7 @@ export class AppComponent implements AfterViewInit { // Needs to be set or qualities won't automatically be set this.setQualities() this.quality = cookieService.get('metube_quality') || 'best'; + this.setupTheme(cookieService) } ngAfterViewInit() { @@ -67,6 +69,27 @@ export class AppComponent implements AfterViewInit { this.cookieService.set('metube_quality', this.quality, { expires: 3650 }); } + setupTheme(cookieService) { + if (cookieService.check('metube_dark')) { + this.darkMode = cookieService.get('metube_dark') === "true" + } else { + this.darkMode = window.matchMedia("prefers-color-scheme: dark").matches + } + this.setTheme() + } + + themeChanged() { + this.darkMode = !this.darkMode + this.cookieService.set('metube_dark', this.darkMode.toString(), { expires: 3650 }); + this.setTheme() + } + + setTheme() { + const doc = document.querySelector('html') + const filter = this.darkMode ? "invert(1) hue-rotate(180deg)" : "" + doc.style.filter = filter + } + formatChanged() { this.cookieService.set('metube_format', this.format, { expires: 3650 }); // Updates to use qualities available -- cgit