This commit is contained in:
Eugene Pankov
2017-04-17 13:26:33 +02:00
parent be72ad3c36
commit 36c2aef860
9 changed files with 170 additions and 32 deletions

View File

@@ -3,7 +3,8 @@ import * as path from 'path'
import * as fs from 'fs'
import { EventEmitter, Injectable, Inject } from '@angular/core'
import { ConfigProvider } from '../api/configProvider'
import { ElectronService } from '../services/electron.service'
import { ElectronService } from './electron.service'
import { HostAppService } from './hostApp.service'
export class ConfigProxy {
@@ -57,14 +58,24 @@ export class ConfigService {
restartRequested: boolean
private _store: any
private path: string
private defaultConfigValues: any = require('../defaultConfigValues.yaml')
private defaults: any
constructor (
electron: ElectronService,
hostApp: HostAppService,
@Inject(ConfigProvider) configProviders: ConfigProvider[],
) {
this.path = path.join(electron.app.getPath('userData'), 'config.yaml')
this.defaultConfigValues = configProviders.map(x => x.defaultConfigValues).reduce(configMerge, this.defaultConfigValues)
this.defaults = configProviders.map(provider => {
let defaults = {}
if (provider.platformDefaults) {
defaults = configMerge(defaults, provider.platformDefaults[hostApp.platform])
}
if (provider.defaults) {
defaults = configMerge(defaults, provider.defaults)
}
return defaults
}).reduce(configMerge)
this.load()
}
@@ -74,7 +85,7 @@ export class ConfigService {
} else {
this._store = {}
}
this.store = new ConfigProxy(this._store, this.defaultConfigValues)
this.store = new ConfigProxy(this._store, this.defaults)
}
save (): void {
@@ -82,10 +93,6 @@ export class ConfigService {
this.emitChange()
}
full (): any {
return configMerge(this.defaultConfigValues, this._store)
}
emitChange (): void {
this.change.emit()
}