plugin system v0

This commit is contained in:
Matias Alejo Garcia 2014-09-01 16:31:35 -03:00
parent 2849f773e2
commit c0360e7beb
9 changed files with 73 additions and 11 deletions

View File

@ -44,6 +44,7 @@ module.exports = function(grunt) {
files: [
'js/models/**/*.js',
'plugins/*.js',
'copay.js'
],
tasks: ['shell:dev']
},

View File

@ -53,10 +53,10 @@ var defaultConfig = {
verbose: 1,
plugins: {
googleDrive: true,
GoogleDrive: true,
},
googleDrive: {
GoogleDrive: {
clientId: '1',
},
};

View File

@ -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;

View File

@ -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);

View File

@ -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();

View 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;

View File

@ -0,0 +1,3 @@
'use strict';
angular.module('copayApp.services').value('pluginManager', new copay.PluginManager(config));

11
plugins/googleDrive.js Normal file
View 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;

View File

@ -83,9 +83,15 @@ 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'