Files
Bridge-Multi/src-angular/app/core/services/settings.service.ts
2023-11-29 20:06:11 -06:00

68 lines
1.4 KiB
TypeScript

import { DOCUMENT } from '@angular/common'
import { Inject, Injectable } from '@angular/core'
import { Settings, themes } from '../../../../src-shared/Settings'
@Injectable({
providedIn: 'root',
})
export class SettingsService {
private settings: Settings
constructor(
@Inject(DOCUMENT) private document: Document,
) { }
async loadSettings() {
this.settings = await window.electron.invoke.getSettings()
if (!themes.includes(this.settings.theme)) {
this.changeTheme('dark')
} else {
this.changeTheme(this.settings.theme)
}
}
saveSettings() {
window.electron.emit.setSettings(this.settings)
}
changeTheme(theme: typeof themes[number]) {
this.document.documentElement.setAttribute('data-theme', theme)
}
// Individual getters/setters
get libraryDirectory() {
return this.settings.libraryPath
}
set libraryDirectory(newValue: string | undefined) {
this.settings.libraryPath = newValue
this.saveSettings()
}
get downloadVideos() {
return this.settings.downloadVideos
}
set downloadVideos(isChecked) {
this.settings.downloadVideos = isChecked
this.saveSettings()
}
get theme() {
return this.settings.theme
}
set theme(newValue: typeof themes[number]) {
this.settings.theme = newValue
this.changeTheme(newValue)
this.saveSettings()
}
get rateLimitDelay() {
return this.settings.rateLimitDelay
}
set rateLimitDelay(delay: number) {
this.settings.rateLimitDelay = delay
this.saveSettings()
}
}