Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Use dependency injection for extra pluginmanager #1818

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,17 @@ function CoreCommandRouter(server) {
// Start the music library
this.musicLibrary = new (require('./musiclibrary.js'))(this);

// Start plugins
this.pluginManager = new (require(__dirname + '/pluginmanager.js'))(this, server);
// Start plugins
this.configManager = new(require(__dirname+'/configManager.js'))(this.logger);
let myVolumioPluginManagerPath = '/myvolumio/app/myvolumio-pluginmanager';
if (fs.existsSync(myVolumioPluginManagerPath)) {
this.logger.info('MYVOLUMIO Environment detected');
let myVolumioPluginManager = new (require(myVolumioPluginManagerPath))(this, server, this.configManager);
this.extraPluginManager = myVolumioPluginManager;
}
this.pluginManager = new (require(__dirname + '/pluginmanager.js'))(this, server, this.extraPluginManager);
this.pluginManager.checkIndex();
this.pluginManager.pluginFolderCleanup();
this.configManager=new(require(__dirname+'/configManager.js'))(this.logger);

this.pluginManager.startPlugins();

Expand Down
30 changes: 14 additions & 16 deletions app/pluginmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var device = '';
module.exports = PluginManager;


function PluginManager(ccommand, server) {
function PluginManager(ccommand, server, extraPluginManager) {
var self = this;

self.corePlugins = new HashMap();
Expand Down Expand Up @@ -73,11 +73,9 @@ function PluginManager(ccommand, server) {
}
}

var myVolumioPMPath = '/myvolumio/app/myvolumio-pluginmanager';
if (fs.existsSync(myVolumioPMPath)) {
this.logger.info('MYVOLUMIO Environment detected');
self.myVolumioPluginManager = new (require(myVolumioPMPath))(self.coreCommand, self.websocketServer, self.configManager, self.config);
}
if (extraPluginManager !== undefined) {
self.extraPluginManager = extraPluginManager;
}
}

PluginManager.prototype.startPlugins = function () {
Expand All @@ -89,8 +87,8 @@ PluginManager.prototype.startPlugins = function () {
this.loadCorePlugins();
this.startCorePlugins();

if (this.myVolumioPluginManager !== undefined) {
this.myVolumioPluginManager.startPlugins();
if (this.extraPluginManager !== undefined) {
this.extraPluginManager.startPlugins();
}
}

Expand Down Expand Up @@ -446,9 +444,9 @@ PluginManager.prototype.getPluginCategories = function () {
if (libFast.indexOf(categories, metadata.category) == -1)
categories.push(metadata.category);
}
if (self.myVolumioPluginManager !== undefined) {
let myVolumioCategories = self.myVolumioPluginManager.getPluginCategories();
categories.concat(myVolumioCategories);
if (self.extraPluginManager !== undefined && typeof self.extraPluginManager.getPluginCategories === 'function') {
let extraPluginCategories = self.extraPluginManager.getPluginCategories();
categories.concat(extraPluginCategories);
}

return categories
Expand All @@ -466,9 +464,9 @@ PluginManager.prototype.getPluginNames = function (category) {
names.push(metadata.name);
}

if (self.myVolumioPluginManager !== undefined) {
let myVolumioNames = self.myVolumioPluginManager.getPluginNames();
names.concat(myVolumioNames);
if (self.extraPluginManager !== undefined && typeof self.extraPluginManager.getPluginNames === 'function') {
let extraPluginNames = self.extraPluginManager.getPluginNames();
names.concat(extraPluginNames);
}

return names
Expand Down Expand Up @@ -621,8 +619,8 @@ PluginManager.prototype.getPlugin = function (category, name) {
var self = this;
if (self.corePlugins.get(category + '.' + name)) {
return self.corePlugins.get(category + '.' + name).instance;
} else if (self.myVolumioPluginManager !== undefined) {
return self.myVolumioPluginManager.getPlugin(category, name);
} else if (self.extraPluginManager !== undefined && typeof self.extraPluginManager.getPlugin === 'function') {
return self.extraPluginManager.getPlugin(category, name);
} else {
self.logger.error('Could not retrieve plugin ' + category + ' ' + name);
}
Expand Down