mirror of
https://github.com/Myxelium/Bridge-Multi.git
synced 2026-04-11 14:19:38 +00:00
111 lines
2.3 KiB
TypeScript
111 lines
2.3 KiB
TypeScript
import { DOCUMENT } from '@angular/common'
|
|
import { Inject, Injectable } from '@angular/core'
|
|
|
|
import _ from 'lodash'
|
|
import { Difficulty, Instrument } from 'scan-chart'
|
|
|
|
import { Settings, themes } from '../../../../src-shared/Settings.js'
|
|
|
|
@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)
|
|
}
|
|
|
|
get instrument() {
|
|
return this.settings.instrument
|
|
}
|
|
set instrument(newValue: Instrument | null) {
|
|
this.settings.instrument = newValue
|
|
this.saveSettings()
|
|
}
|
|
|
|
get difficulty() {
|
|
return this.settings.difficulty
|
|
}
|
|
set difficulty(newValue: Difficulty | null) {
|
|
this.settings.difficulty = newValue
|
|
this.saveSettings()
|
|
}
|
|
|
|
// 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 isSng() {
|
|
return this.settings.isSng
|
|
}
|
|
set isSng(value: boolean) {
|
|
this.settings.isSng = value
|
|
this.saveSettings()
|
|
}
|
|
|
|
get isCompactTable() {
|
|
return this.settings.isCompactTable
|
|
}
|
|
set isCompactTable(value: boolean) {
|
|
this.settings.isCompactTable = value
|
|
this.saveSettings()
|
|
}
|
|
|
|
get zoomFactor() {
|
|
return this.settings.zoomFactor
|
|
}
|
|
set zoomFactor(value: number) {
|
|
this.settings.zoomFactor = value
|
|
this.saveSettings()
|
|
}
|
|
zoomIn() {
|
|
this.zoomFactor = _.round(this.zoomFactor + 0.1, 3)
|
|
}
|
|
zoomOut() {
|
|
if (_.round(this.zoomFactor - 0.1, 3) > 0) {
|
|
this.zoomFactor = _.round(this.zoomFactor - 0.1, 3)
|
|
}
|
|
}
|
|
}
|