plugin system v0
This commit is contained in:
parent
2849f773e2
commit
c0360e7beb
9 changed files with 73 additions and 11 deletions
|
|
@ -44,6 +44,7 @@ module.exports = function(grunt) {
|
||||||
files: [
|
files: [
|
||||||
'js/models/**/*.js',
|
'js/models/**/*.js',
|
||||||
'plugins/*.js',
|
'plugins/*.js',
|
||||||
|
'copay.js'
|
||||||
],
|
],
|
||||||
tasks: ['shell:dev']
|
tasks: ['shell:dev']
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -53,10 +53,10 @@ var defaultConfig = {
|
||||||
verbose: 1,
|
verbose: 1,
|
||||||
|
|
||||||
plugins: {
|
plugins: {
|
||||||
googleDrive: true,
|
GoogleDrive: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
googleDrive: {
|
GoogleDrive: {
|
||||||
clientId: '1',
|
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.WalletFactory = require('./js/models/core/WalletFactory');
|
||||||
module.exports.Wallet = require('./js/models/core/Wallet');
|
module.exports.Wallet = require('./js/models/core/Wallet');
|
||||||
module.exports.WalletLock = require('./js/models/core/WalletLock');
|
module.exports.WalletLock = require('./js/models/core/WalletLock');
|
||||||
|
module.exports.PluginManager = require('./js/models/core/PluginManager');
|
||||||
module.exports.version = require('./version').version;
|
module.exports.version = require('./version').version;
|
||||||
module.exports.commitHash = require('./version').commitHash;
|
module.exports.commitHash = require('./version').commitHash;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,12 +40,6 @@ var modules = [
|
||||||
if (config.plugins.length)
|
if (config.plugins.length)
|
||||||
modules.push('angularLoad');
|
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);
|
var copayApp = window.copayApp = angular.module('copayApp', modules);
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
function($scope, $rootScope, $location, walletFactory, notification, controllerUtils, pluginManager) {
|
||||||
|
|
||||||
controllerUtils.redirIfLogged();
|
controllerUtils.redirIfLogged();
|
||||||
|
|
||||||
|
|
|
||||||
46
js/models/core/PluginManager.js
Normal file
46
js/models/core/PluginManager.js
Normal file
|
|
@ -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;
|
||||||
3
js/services/pluginManager.js
Normal file
3
js/services/pluginManager.js
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
angular.module('copayApp.services').value('pluginManager', new copay.PluginManager(config));
|
||||||
11
plugins/googleDrive.js
Normal file
11
plugins/googleDrive.js
Normal file
|
|
@ -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', {
|
b.require('./js/models/core/HDPath', {
|
||||||
expose: '../js/models/core/HDPath'
|
expose: '../js/models/core/HDPath'
|
||||||
});
|
});
|
||||||
b.require('./plugins/googleDrive', {
|
b.require('./js/models/core/PluginManager', {
|
||||||
expose: '../plugins/googleDrive'
|
expose: '../js/models/core/PluginManager'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!opts.disablePlugins) {
|
||||||
|
b.require('./plugins/GoogleDrive', {
|
||||||
|
expose: '../plugins/GoogleDrive'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
b.require('./config', {
|
b.require('./config', {
|
||||||
expose: '../config'
|
expose: '../config'
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue