mirror of https://github.com/BTCPrivate/copay.git
Store and read config from storage. Set language
This commit is contained in:
parent
d0d9139825
commit
8e4ae44f76
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue