mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 20:14:49 +00:00
* rename frontend to web and update contributing guide * rename this time * fix build * restructure rust code * update documentation * update descriptions * Update CONTRIBUTING.md Co-authored-by: J H <2364004+Blu-J@users.noreply.github.com> --------- Co-authored-by: Aiden McClelland <me@drbonez.dev> Co-authored-by: Aiden McClelland <3732071+dr-bonez@users.noreply.github.com> Co-authored-by: J H <2364004+Blu-J@users.noreply.github.com>
38 lines
1.0 KiB
TypeScript
38 lines
1.0 KiB
TypeScript
import { Inject, Injectable } from '@angular/core'
|
|
import { WINDOW } from '@ng-web-apis/common'
|
|
import { PatchDB } from 'patch-db-client'
|
|
import { BehaviorSubject } from 'rxjs'
|
|
import { ApiService } from './api/embassy-api.service'
|
|
import { DataModel } from './patch-db/data-model'
|
|
import { filter, take } from 'rxjs/operators'
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class ThemeSwitcherService extends BehaviorSubject<string> {
|
|
constructor(
|
|
private readonly patch: PatchDB<DataModel>,
|
|
private readonly embassyApi: ApiService,
|
|
@Inject(WINDOW) private readonly windowRef: Window,
|
|
) {
|
|
super('Dark')
|
|
|
|
this.patch
|
|
.watch$('ui', 'theme')
|
|
.pipe(take(1), filter(Boolean))
|
|
.subscribe(theme => {
|
|
this.updateTheme(theme)
|
|
})
|
|
}
|
|
|
|
override next(theme: string): void {
|
|
this.embassyApi.setDbValue(['theme'], theme)
|
|
this.updateTheme(theme)
|
|
}
|
|
|
|
private updateTheme(theme: string): void {
|
|
this.windowRef.document.body.setAttribute('data-theme', theme)
|
|
super.next(theme)
|
|
}
|
|
}
|