mirror of https://github.com/BTCPrivate/copay.git
plugin system v0
This commit is contained in:
parent
2849f773e2
commit
c0360e7beb
|
@ -44,6 +44,7 @@ module.exports = function(grunt) {
|
|||
files: [
|
||||
'js/models/**/*.js',
|
||||
'plugins/*.js',
|
||||
'copay.js'
|
||||
],
|
||||
tasks: ['shell:dev']
|
||||
},
|
||||
|
|
|
@ -53,10 +53,10 @@ var defaultConfig = {
|
|||
verbose: 1,
|
||||
|
||||
plugins: {
|
||||
googleDrive: true,
|
||||
GoogleDrive: true,
|
||||
},
|
||||
|
||||
googleDrive: {
|
||||
GoogleDrive: {
|
||||
clientId: '1',
|
||||
},
|
||||
};
|
||||
|
|
1
copay.js
1
copay.js
|
@ -16,6 +16,7 @@ var StorageEncrypted = module.exports.StorageEncrypted = require('./js/models/st
|
|||
module.exports.WalletFactory = require('./js/models/core/WalletFactory');
|
||||
module.exports.Wallet = require('./js/models/core/Wallet');
|
||||
module.exports.WalletLock = require('./js/models/core/WalletLock');
|
||||
module.exports.PluginManager = require('./js/models/core/PluginManager');
|
||||
module.exports.version = require('./version').version;
|
||||
module.exports.commitHash = require('./version').commitHash;
|
||||
|
||||
|
|
|
@ -40,12 +40,6 @@ var modules = [
|
|||
if (config.plugins.length)
|
||||
modules.push('angularLoad');
|
||||
|
||||
if (config.plugins.googleDrive) {
|
||||
var googleDrive = require('../plugins/googleDrive');
|
||||
var a = new googleDrive();
|
||||
a.init();
|
||||
console.log('[app.js.41:new:]',a); //TODO
|
||||
}
|
||||
|
||||
|
||||
var copayApp = window.copayApp = angular.module('copayApp', modules);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('HomeController',
|
||||
function($scope, $rootScope, $location, walletFactory, notification, controllerUtils) {
|
||||
function($scope, $rootScope, $location, walletFactory, notification, controllerUtils, pluginManager) {
|
||||
|
||||
controllerUtils.redirIfLogged();
|
||||
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
'use strict';
|
||||
var preconditions = require('preconditions').singleton();
|
||||
|
||||
function PluginManager(config) {
|
||||
this.registered = {};
|
||||
|
||||
for(var ii in config.plugins){
|
||||
var pluginName = ii;
|
||||
|
||||
if (!config.plugins[pluginName])
|
||||
continue;
|
||||
|
||||
console.log('Loading ' + pluginName);
|
||||
var pluginClass = require('../plugins/' + pluginName);
|
||||
var pluginObj = new pluginClass();
|
||||
pluginObj.init();
|
||||
this._register(pluginObj);
|
||||
}
|
||||
};
|
||||
|
||||
var KIND_UNIQUE = PluginManager.KIND_UNIQUE = 1;
|
||||
var KIND_MULTIPLE = PluginManager.KIND_MULTIPLE = 2;
|
||||
|
||||
PluginManager.TYPE = {};
|
||||
PluginManager.TYPE['STORAGE'] = KIND_UNIQUE;
|
||||
|
||||
PluginManager.prototype._register = function(obj) {
|
||||
preconditions.checkArgument(obj.type,'Plugin has not type');
|
||||
var type = obj.type;
|
||||
console.log('[PluginManager.js.29:type:]',type); //TODO
|
||||
|
||||
var kind = PluginManager.TYPE[type];
|
||||
preconditions.checkArgument(kind, 'Plugin has unkown type');
|
||||
preconditions.checkState(kind !== PluginManager.KIND_UNIQUE || !this.registered[type], 'Plugin kind already registered');
|
||||
|
||||
if (kind === PluginManager.KIND_UNIQUE) {
|
||||
this.registered[type] = obj;
|
||||
} else {
|
||||
this.registered[type] = this.registered[type] || [];
|
||||
this.registered[type].push(obj);
|
||||
}
|
||||
};
|
||||
|
||||
PluginManager.prototype.getOne = function(type) {};
|
||||
|
||||
module.exports = PluginManager;
|
|
@ -0,0 +1,3 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.services').value('pluginManager', new copay.PluginManager(config));
|
|
@ -0,0 +1,11 @@
|
|||
'use strict';
|
||||
|
||||
function GoogleDrive() {
|
||||
this.type = 'STORAGE';
|
||||
};
|
||||
|
||||
GoogleDrive.prototype.init = function() {
|
||||
console.log('[googleDrive.js.3] init'); //TODO
|
||||
};
|
||||
|
||||
module.exports = GoogleDrive;
|
|
@ -83,10 +83,16 @@ var createBundle = function(opts) {
|
|||
b.require('./js/models/core/HDPath', {
|
||||
expose: '../js/models/core/HDPath'
|
||||
});
|
||||
b.require('./plugins/googleDrive', {
|
||||
expose: '../plugins/googleDrive'
|
||||
b.require('./js/models/core/PluginManager', {
|
||||
expose: '../js/models/core/PluginManager'
|
||||
});
|
||||
|
||||
if (!opts.disablePlugins) {
|
||||
b.require('./plugins/GoogleDrive', {
|
||||
expose: '../plugins/GoogleDrive'
|
||||
});
|
||||
}
|
||||
|
||||
b.require('./config', {
|
||||
expose: '../config'
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue