add LocalStorage plugin
This commit is contained in:
parent
c0360e7beb
commit
b9881c1147
10 changed files with 101 additions and 16 deletions
|
|
@ -44,7 +44,8 @@ module.exports = function(grunt) {
|
||||||
files: [
|
files: [
|
||||||
'js/models/**/*.js',
|
'js/models/**/*.js',
|
||||||
'plugins/*.js',
|
'plugins/*.js',
|
||||||
'copay.js'
|
'copay.js',
|
||||||
|
'utils/*.js'
|
||||||
],
|
],
|
||||||
tasks: ['shell:dev']
|
tasks: ['shell:dev']
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,8 @@ var defaultConfig = {
|
||||||
verbose: 1,
|
verbose: 1,
|
||||||
|
|
||||||
plugins: {
|
plugins: {
|
||||||
GoogleDrive: true,
|
LocalStorage: true,
|
||||||
|
// GoogleDrive: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
GoogleDrive: {
|
GoogleDrive: {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('HomeController',
|
angular.module('copayApp.controllers').controller('HomeController',
|
||||||
function($scope, $rootScope, $location, walletFactory, notification, controllerUtils, pluginManager) {
|
function($scope, $rootScope, $location, walletFactory, notification, controllerUtils) {
|
||||||
|
|
||||||
controllerUtils.redirIfLogged();
|
controllerUtils.redirIfLogged();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,11 @@ function PluginManager(config) {
|
||||||
if (!config.plugins[pluginName])
|
if (!config.plugins[pluginName])
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
console.log('Loading ' + pluginName);
|
console.log('Loading plugin: ' + pluginName);
|
||||||
var pluginClass = require('../plugins/' + pluginName);
|
var pluginClass = require('../plugins/' + pluginName);
|
||||||
var pluginObj = new pluginClass();
|
var pluginObj = new pluginClass();
|
||||||
pluginObj.init();
|
pluginObj.init();
|
||||||
this._register(pluginObj);
|
this._register(pluginObj, pluginName);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -24,14 +24,12 @@ var KIND_MULTIPLE = PluginManager.KIND_MULTIPLE = 2;
|
||||||
PluginManager.TYPE = {};
|
PluginManager.TYPE = {};
|
||||||
PluginManager.TYPE['STORAGE'] = KIND_UNIQUE;
|
PluginManager.TYPE['STORAGE'] = KIND_UNIQUE;
|
||||||
|
|
||||||
PluginManager.prototype._register = function(obj) {
|
PluginManager.prototype._register = function(obj, name) {
|
||||||
preconditions.checkArgument(obj.type,'Plugin has not type');
|
preconditions.checkArgument(obj.type,'Plugin has not type:' + name);
|
||||||
var type = obj.type;
|
var type = obj.type;
|
||||||
console.log('[PluginManager.js.29:type:]',type); //TODO
|
|
||||||
|
|
||||||
var kind = PluginManager.TYPE[type];
|
var kind = PluginManager.TYPE[type];
|
||||||
preconditions.checkArgument(kind, 'Plugin has unkown type');
|
preconditions.checkArgument(kind, 'Plugin has unkown type' + name);
|
||||||
preconditions.checkState(kind !== PluginManager.KIND_UNIQUE || !this.registered[type], 'Plugin kind already registered');
|
preconditions.checkState(kind !== PluginManager.KIND_UNIQUE || !this.registered[type], 'Plugin kind already registered: ' + name);
|
||||||
|
|
||||||
if (kind === PluginManager.KIND_UNIQUE) {
|
if (kind === PluginManager.KIND_UNIQUE) {
|
||||||
this.registered[type] = obj;
|
this.registered[type] = obj;
|
||||||
|
|
@ -41,6 +39,8 @@ console.log('[PluginManager.js.29:type:]',type); //TODO
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
PluginManager.prototype.getOne = function(type) {};
|
PluginManager.prototype.get = function(type) {
|
||||||
|
return this.registered[type];
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = PluginManager;
|
module.exports = PluginManager;
|
||||||
|
|
|
||||||
|
|
@ -36,11 +36,13 @@ function WalletFactory(config, version) {
|
||||||
var self = this;
|
var self = this;
|
||||||
config = config || {};
|
config = config || {};
|
||||||
|
|
||||||
this.Storage = config.Storage || StorageEncrypted;
|
this.pluginManager = new copay.PluginManager(config);
|
||||||
|
|
||||||
|
this.Storage = config.Storage || StorageEncrypted;
|
||||||
this.Network = config.Network || Async;
|
this.Network = config.Network || Async;
|
||||||
this.Blockchain = config.Blockchain || Insight;
|
this.Blockchain = config.Blockchain || Insight;
|
||||||
|
this.storage = new this.Storage({storage: this.pluginManager.get('STORAGE')});
|
||||||
|
|
||||||
this.storage = new this.Storage(config.storage);
|
|
||||||
this.networks = {
|
this.networks = {
|
||||||
'livenet': new this.Network(config.network.livenet),
|
'livenet': new this.Network(config.network.livenet),
|
||||||
'testnet': new this.Network(config.network.testnet),
|
'testnet': new this.Network(config.network.testnet),
|
||||||
|
|
|
||||||
|
|
@ -130,6 +130,8 @@ Storage.prototype.getWalletIds = function() {
|
||||||
var walletIds = [];
|
var walletIds = [];
|
||||||
var uniq = {};
|
var uniq = {};
|
||||||
|
|
||||||
|
console.log('[Encrypted.js.144]', this.storage); //TODO
|
||||||
|
console.log('[Encrypted.js.144]', this.storage.length); //TODO
|
||||||
for (var i = 0; i < this.storage.length; i++) {
|
for (var i = 0; i < this.storage.length; i++) {
|
||||||
var key = this.storage.key(i);
|
var key = this.storage.key(i);
|
||||||
var split = key.split('::');
|
var split = key.split('::');
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.services').value('pluginManager', new copay.PluginManager(config));
|
angular.module('copayApp.services').factory('pluginManager', function(angularLoad){
|
||||||
|
return new copay.PluginManager(config);
|
||||||
|
});
|
||||||
|
|
|
||||||
42
plugins/LocalStorage.js
Normal file
42
plugins/LocalStorage.js
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
function LocalStorage() {
|
||||||
|
this.type = 'STORAGE';
|
||||||
|
};
|
||||||
|
|
||||||
|
LocalStorage.prototype.init = function() {
|
||||||
|
console.log(' init LocalStorage'); //TODO
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
LocalStorage.prototype.getItem = function(k) {
|
||||||
|
return localStorage.getItem(k);
|
||||||
|
};
|
||||||
|
|
||||||
|
LocalStorage.prototype.setItem = function(k,v) {
|
||||||
|
localStorage.setItem(k,v);
|
||||||
|
};
|
||||||
|
|
||||||
|
LocalStorage.prototype.removeItem = function(k) {
|
||||||
|
localStorage.removeItem(k);
|
||||||
|
};
|
||||||
|
|
||||||
|
LocalStorage.prototype.clear = function() {
|
||||||
|
localStorage.clear();
|
||||||
|
};
|
||||||
|
|
||||||
|
delete LocalStorage.prototype.length;
|
||||||
|
|
||||||
|
Object.defineProperty(LocalStorage.prototype, 'length', {
|
||||||
|
get: function() {
|
||||||
|
return localStorage.length;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
LocalStorage.prototype.key = function(k) {
|
||||||
|
var v = localStorage.key(k);
|
||||||
|
return v;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = LocalStorage;
|
||||||
|
|
@ -5,7 +5,38 @@ function GoogleDrive() {
|
||||||
};
|
};
|
||||||
|
|
||||||
GoogleDrive.prototype.init = function() {
|
GoogleDrive.prototype.init = function() {
|
||||||
console.log('[googleDrive.js.3] init'); //TODO
|
console.log('[googleDrive.js.3] init GoogleDrive'); //TODO
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
GoogleDrive.prototype.getItem = function(k) {
|
||||||
|
return localStorage.getItem(k);
|
||||||
|
};
|
||||||
|
|
||||||
|
GoogleDrive.prototype.setItem = function(k,v) {
|
||||||
|
localStorage.setItem(k,v);
|
||||||
|
};
|
||||||
|
|
||||||
|
GoogleDrive.prototype.removeItem = function(k) {
|
||||||
|
localStorage.removeItem(k);
|
||||||
|
};
|
||||||
|
|
||||||
|
GoogleDrive.prototype.clear = function() {
|
||||||
|
localStorage.clear();
|
||||||
|
};
|
||||||
|
|
||||||
|
delete GoogleDrive.prototype.length;
|
||||||
|
|
||||||
|
Object.defineProperty(GoogleDrive.prototype, 'length', {
|
||||||
|
get: function() {
|
||||||
|
return localStorage.length;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
GoogleDrive.prototype.key = function(k) {
|
||||||
|
var v = localStorage.key(k);
|
||||||
|
return v;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
module.exports = GoogleDrive;
|
module.exports = GoogleDrive;
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,10 @@ var createBundle = function(opts) {
|
||||||
b.require('./plugins/GoogleDrive', {
|
b.require('./plugins/GoogleDrive', {
|
||||||
expose: '../plugins/GoogleDrive'
|
expose: '../plugins/GoogleDrive'
|
||||||
});
|
});
|
||||||
|
b.require('./plugins/LocalStorage', {
|
||||||
|
expose: '../plugins/LocalStorage'
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
b.require('./config', {
|
b.require('./config', {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue