copay/js/services/configService.js

37 lines
906 B
JavaScript
Raw Normal View History

2014-12-05 08:24:46 -08:00
'use strict';
2014-12-12 12:06:17 -08:00
angular.module('copayApp.services').factory('configService', function($timeout, localstorageService, gettextCatalog, defaults) {
2014-12-05 08:24:46 -08:00
var root = {};
root.set = function(opts, cb) {
2014-12-12 06:21:48 -08:00
// Options that have runtime effects
2014-12-05 09:23:33 -08:00
if (opts.logLevel)
copay.logger.setLevel(opts.logLevel);
2014-12-12 06:21:48 -08:00
// Set current version
opts.version = copay.version;
2014-12-05 09:23:33 -08:00
2014-12-12 06:21:48 -08:00
localstorageService.getItem('config', function(err, oldOpsStr) {
2014-12-05 09:23:33 -08:00
var oldOpts = {};
try {
oldOpts = JSON.parse(oldOpsStr);
} catch (e) {};
var newOpts = {};
_.extend(newOpts, copay.defaultConfig, oldOpts, opts);
2014-12-05 08:24:46 -08:00
2014-12-11 18:45:44 -08:00
// TODO remove this global variable.
2014-12-05 09:23:33 -08:00
config = newOpts;
2014-12-12 06:21:48 -08:00
localstorageService.setItem('config', JSON.stringify(newOpts), cb);
2014-12-05 08:24:46 -08:00
});
};
root.reset = function(cb) {
2014-12-17 12:16:05 -08:00
config = defaults;
2014-12-05 09:23:33 -08:00
localstorageService.removeItem('config', cb);
2014-12-05 08:24:46 -08:00
};
return root;
});