diff --git a/src-ui/src/app/app.component.ts b/src-ui/src/app/app.component.ts index 30ecb40d0..73c5fc861 100644 --- a/src-ui/src/app/app.component.ts +++ b/src-ui/src/app/app.component.ts @@ -1,5 +1,5 @@ import { Component } from '@angular/core'; -import { AppViewService } from './services/app-view.service'; +import { SettingsService } from './services/settings.service'; @Component({ selector: 'app-root', @@ -8,10 +8,10 @@ import { AppViewService } from './services/app-view.service'; }) export class AppComponent { - constructor (appViewService: AppViewService) { - (window as any).pdfWorkerSrc = '/assets/js/pdf.worker.min.js'; - appViewService.updateDarkModeSettings() + constructor (private settings: SettingsService) { + let anyWindow = (window as any) + anyWindow.pdfWorkerSrc = '/assets/js/pdf.worker.min.js'; + this.settings.updateDarkModeSettings() } - } diff --git a/src-ui/src/app/components/app-frame/app-frame.component.ts b/src-ui/src/app/components/app-frame/app-frame.component.ts index dca0d9106..ad4460f16 100644 --- a/src-ui/src/app/components/app-frame/app-frame.component.ts +++ b/src-ui/src/app/components/app-frame/app-frame.component.ts @@ -26,8 +26,7 @@ export class AppFrameComponent implements OnInit, OnDestroy { public savedViewService: SavedViewService, private meta: Meta ) { - console.log(meta); - + } versionString = `${environment.appTitle} ${environment.version}` diff --git a/src-ui/src/app/components/manage/settings/settings.component.ts b/src-ui/src/app/components/manage/settings/settings.component.ts index df3015e21..0b0646157 100644 --- a/src-ui/src/app/components/manage/settings/settings.component.ts +++ b/src-ui/src/app/components/manage/settings/settings.component.ts @@ -5,7 +5,6 @@ import { DocumentListViewService } from 'src/app/services/document-list-view.ser import { SavedViewService } from 'src/app/services/rest/saved-view.service'; import { SettingsService, SETTINGS_KEYS } from 'src/app/services/settings.service'; import { ToastService } from 'src/app/services/toast.service'; -import { AppViewService } from 'src/app/services/app-view.service'; @Component({ selector: 'app-settings', @@ -31,8 +30,7 @@ export class SettingsComponent implements OnInit { public savedViewService: SavedViewService, private documentListViewService: DocumentListViewService, private toastService: ToastService, - private settings: SettingsService, - private appViewService: AppViewService + private settings: SettingsService ) { } ngOnInit() { @@ -72,7 +70,7 @@ export class SettingsComponent implements OnInit { this.settings.set(SETTINGS_KEYS.DARK_MODE_USE_SYSTEM, this.settingsForm.value.darkModeUseSystem) this.settings.set(SETTINGS_KEYS.DARK_MODE_ENABLED, (this.settingsForm.value.darkModeEnabled == true).toString()) this.documentListViewService.updatePageSize() - this.appViewService.updateDarkModeSettings() + this.settings.updateDarkModeSettings() this.toastService.showInfo($localize`Settings saved successfully.`) } diff --git a/src-ui/src/app/services/app-view.service.spec.ts b/src-ui/src/app/services/app-view.service.spec.ts deleted file mode 100644 index fc44ed3a4..000000000 --- a/src-ui/src/app/services/app-view.service.spec.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { TestBed } from '@angular/core/testing'; - -import { AppViewService } from './app-view.service'; - -describe('AppViewService', () => { - let service: AppViewService; - - beforeEach(() => { - TestBed.configureTestingModule({}); - service = TestBed.inject(AppViewService); - }); - - it('should be created', () => { - expect(service).toBeTruthy(); - }); -}); diff --git a/src-ui/src/app/services/app-view.service.ts b/src-ui/src/app/services/app-view.service.ts deleted file mode 100644 index 67a429ffe..000000000 --- a/src-ui/src/app/services/app-view.service.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { Inject, Injectable, Renderer2, RendererFactory2 } from '@angular/core'; -import { DOCUMENT } from '@angular/common'; -import { SettingsService, SETTINGS_KEYS } from './settings.service'; - -@Injectable({ - providedIn: 'root' -}) -export class AppViewService { - private renderer: Renderer2; - - constructor( - private settings: SettingsService, - private rendererFactory: RendererFactory2, - @Inject(DOCUMENT) private document - ) { - this.renderer = rendererFactory.createRenderer(null, null); - - this.updateDarkModeSettings() - } - - updateDarkModeSettings(): void { - let darkModeUseSystem = this.settings.get(SETTINGS_KEYS.DARK_MODE_USE_SYSTEM) - let darkModeEnabled = this.settings.get(SETTINGS_KEYS.DARK_MODE_ENABLED) - - if (darkModeUseSystem) { - this.renderer.addClass(this.document.body, 'color-scheme-system') - this.renderer.removeClass(this.document.body, 'color-scheme-dark') - } else { - this.renderer.removeClass(this.document.body, 'color-scheme-system') - darkModeEnabled ? this.renderer.addClass(this.document.body, 'color-scheme-dark') : this.renderer.removeClass(this.document.body, 'color-scheme-dark') - } - - } - -} diff --git a/src-ui/src/app/services/settings.service.ts b/src-ui/src/app/services/settings.service.ts index 7b1cfe9e3..a8f85972d 100644 --- a/src-ui/src/app/services/settings.service.ts +++ b/src-ui/src/app/services/settings.service.ts @@ -1,4 +1,5 @@ -import { Injectable } from '@angular/core'; +import { DOCUMENT } from '@angular/common'; +import { Inject, Injectable, Renderer2, RendererFactory2 } from '@angular/core'; export interface PaperlessSettings { key: string @@ -27,7 +28,30 @@ const SETTINGS: PaperlessSettings[] = [ }) export class SettingsService { - constructor() { } + private renderer: Renderer2; + + constructor( + private rendererFactory: RendererFactory2, + @Inject(DOCUMENT) private document + ) { + this.renderer = rendererFactory.createRenderer(null, null); + + this.updateDarkModeSettings() + } + + updateDarkModeSettings(): void { + let darkModeUseSystem = this.get(SETTINGS_KEYS.DARK_MODE_USE_SYSTEM) + let darkModeEnabled = this.get(SETTINGS_KEYS.DARK_MODE_ENABLED) + + if (darkModeUseSystem) { + this.renderer.addClass(this.document.body, 'color-scheme-system') + this.renderer.removeClass(this.document.body, 'color-scheme-dark') + } else { + this.renderer.removeClass(this.document.body, 'color-scheme-system') + darkModeEnabled ? this.renderer.addClass(this.document.body, 'color-scheme-dark') : this.renderer.removeClass(this.document.body, 'color-scheme-dark') + } + + } get(key: string): any { let setting = SETTINGS.find(s => s.key == key)