Initial settings tab

This commit is contained in:
Geomitron
2020-02-13 22:33:14 -05:00
parent c6b549340b
commit 49cba89a11
14 changed files with 204 additions and 47 deletions

View File

@@ -6,8 +6,10 @@ import { Settings } from 'src/electron/shared/Settings'
providedIn: 'root'
})
export class SettingsService {
readonly builtinThemes = ['Default', 'Dark']
private settings: Settings
private currentThemeLink: HTMLLinkElement
constructor(private electronService: ElectronService) { }
@@ -17,4 +19,47 @@ export class SettingsService {
}
return this.settings
}
saveSettings() {
if (this.settings != undefined) {
this.electronService.sendIPC('update-settings', this.settings)
}
}
changeTheme(theme: string) {
if (this.currentThemeLink != undefined) this.currentThemeLink.remove()
if (theme == 'Default') { return }
const link = document.createElement('link')
link.type = 'text/css'
link.rel = 'stylesheet'
link.href = `assets/themes/${theme}.css`
this.currentThemeLink = document.head.appendChild(link)
}
async getCacheSize() {
return this.electronService.defaultSession.getCacheSize()
}
async clearCache() {
this.saveSettings()
return this.electronService.defaultSession.clearCache()
}
get libraryDirectory() {
return this.settings == undefined ? '' : this.settings.libraryPath
}
set libraryDirectory(newValue: string) {
this.settings.libraryPath = newValue
this.saveSettings()
}
get theme() {
return this.settings == undefined ? '' : this.settings.theme
}
set theme(newValue: string) {
this.settings.theme = newValue
this.changeTheme(newValue)
this.saveSettings()
}
}