Move plugin initialization into PluginManager and log plugin loading

This commit is contained in:
Adam Honse 2021-03-05 16:57:31 -06:00
parent 00a47f600c
commit a08fb8b532
3 changed files with 17 additions and 8 deletions

View file

@ -1,7 +1,12 @@
#include "LogManager.h"
#include "PluginManager.h"
void PluginManager::ScanAndLoadPlugins()
void PluginManager::ScanAndLoadPlugins(bool dark_theme)
{
int plugin_section = LogSection("Plugins", LL_DEBUG);
LogAppend(plugin_section, LL_DEBUG, "Loading plugins");
std::string OpenRGBConfigDir = ResourceManager::get()->GetConfigurationDirectory();
std::string PluginPath = OpenRGBConfigDir + "/Plugins";
@ -28,12 +33,21 @@ void PluginManager::ScanAndLoadPlugins()
{
const std::string filePath = pluginsDir.absoluteFilePath(QString().fromStdString(fileName)).toStdString();
LogAppend(plugin_section, LL_DEBUG, "Attempting to load: %s", filePath.c_str());
QPluginLoader loader(pluginsDir.absoluteFilePath(QString().fromStdString(fileName)));
if (QObject *instance = loader.instance())
{
if ((OpenRGBPlugin = qobject_cast<OpenRGBPluginInterface*>(instance)))
{
/*-----------------------------------------------------*\
| Initialize the plugin |
\*-----------------------------------------------------*/
OpenRGBPlugin->info = OpenRGBPlugin->Initialize(dark_theme, ResourceManager::get());
LogAppend(plugin_section, LL_DEBUG, "Loaded plugin %s", OpenRGBPlugin->info.PluginName.c_str());
PluginManager::ActivePlugins.push_back(OpenRGBPlugin);
}
}

View file

@ -16,5 +16,5 @@ class PluginManager
public:
std::vector<OpenRGBPluginInterface*> ActivePlugins;
void ScanAndLoadPlugins();
void ScanAndLoadPlugins(bool dark_theme);
};

View file

@ -332,7 +332,7 @@ OpenRGBDialog2::OpenRGBDialog2(QWidget *parent) : QMainWindow(parent), ui(new Op
\*-----------------------------------------------------*/
plugin_manager = new PluginManager;
plugin_manager->ScanAndLoadPlugins();
plugin_manager->ScanAndLoadPlugins(IsDarkTheme());
if(plugin_manager->ActivePlugins.size() > 0)
{
@ -440,11 +440,6 @@ void OpenRGBDialog2::AddSupportedDevicesPage()
void OpenRGBDialog2::AddPluginTab(PluginManager* plugin_manager, int plugin_index)
{
/*-----------------------------------------------------*\
| Initialize the plugin |
\*-----------------------------------------------------*/
plugin_manager->ActivePlugins[plugin_index]->info = plugin_manager->ActivePlugins[plugin_index]->Initialize(OpenRGBDialog2::IsDarkTheme(), ResourceManager::get());
/*-----------------------------------------------------*\
| Create Label for the Tab |
\*-----------------------------------------------------*/