now plugins can be read on runtime

This commit is contained in:
Matias Alejo Garcia 2014-12-05 14:23:33 -03:00
commit 93b287bedc
5 changed files with 67 additions and 41 deletions

View file

@ -4,20 +4,31 @@ angular.module('copayApp.services').factory('configService', function(localstora
var root = {};
root.set = function(opts, cb) {
copay.logger.setLevel(opts.logLevel);
localstorageService.getItem('config', function(err, oldOps) {
_.defaults(opts, JSON.parse(oldOps));
if (opts.logLevel)
copay.logger.setLevel(opts.logLevel);
localstorageService.getItem('config', function(err, oldOpsStr) {
var oldOpts = {};
try {
oldOpts = JSON.parse(oldOpsStr);
} catch (e) {};
var newOpts = {};
_.extend(newOpts, copay.defaultConfig, oldOpts, opts);
// TODO remove this gloval variable.
config = opts;
localstorageService.setItem('config', JSON.stringify(opts), cb);
config = newOpts;
localstorageService.setItem('config', JSON.stringify(newOpts), cb);
});
};
root.reset = function(cb) {
config = copay.defaultConfig;
localstorageService.removeItem('config',cb);
localstorageService.removeItem('config', cb);
};
return root;