Store and read config from storage. Set language

This commit is contained in:
Gustavo Maximiliano Cortez 2017-09-26 18:24:36 -03:00
parent d0d9139825
commit 8e4ae44f76
No known key found for this signature in database
GPG Key ID: 15EDAD8D9F2EB1AF
2 changed files with 13 additions and 5 deletions

View File

@ -1,6 +1,7 @@
import { Injectable } from '@angular/core';
import { Logger } from '@nsalaun/ng-logger';
import { Events } from 'ionic-angular';
import { PersistenceProvider } from '../persistence/persistence';
import { PlatformProvider } from '../platform/platform';
import * as _ from "lodash";
@ -100,15 +101,19 @@ export class ConfigProvider {
constructor(
private logger: Logger,
private events: Events,
private platform: PlatformProvider
private platform: PlatformProvider,
private persistence: PersistenceProvider
) {
this.logger.debug('ConfigProvider initialized.');
}
public load() {
return new Promise((resolve, reject) => {
this.configCache = _.clone(this.configDefault);
resolve(this.configCache);
this.persistence.getConfig().then((config: object) => {
if (!_.isEmpty(config)) this.configCache = _.clone(config);
else this.configCache = _.clone(this.configDefault);
resolve(this.configCache);
});
});
}
@ -121,6 +126,9 @@ export class ConfigProvider {
_.merge(config, this.configCache, newOpts);
this.configCache = config;
this.persistence.storeConfig(this.configCache).then(() => {
this.logger.info('Config saved');
});
this.events.publish('config:updated', this.configCache);
}

View File

@ -133,11 +133,11 @@ export class PersistenceProvider {
return this.storage.remove(Keys.CLEAN_AND_SCAN_ADDRESSES);
};
getConfig(): Promise<void> {
getConfig(): Promise<object> {
return this.storage.get(Keys.CONFIG);
};
storeConfig(config: any): Promise<void> {
storeConfig(config: object): Promise<void> {
return this.storage.set(Keys.CONFIG, config);
};