Initial support for system-installed plugins in Linux

This commit is contained in:
Adam Honse 2024-05-14 20:06:01 -05:00
parent 806ababa05
commit d03701c58d
5 changed files with 56 additions and 20 deletions

View file

@ -485,6 +485,9 @@ contains(QMAKE_PLATFORM, linux) {
QMAKE_CXXFLAGS += -Wno-implicit-fallthrough QMAKE_CXXFLAGS += -Wno-implicit-fallthrough
DEFINES += \
OPENRGB_SYSTEM_PLUGIN_DIRECTORY=\\"\"\"$$PREFIX/lib/openrgb/plugins\\"\"\" \
#-------------------------------------------------------------------------------------------# #-------------------------------------------------------------------------------------------#
# Determine which hidapi to use based on availability # # Determine which hidapi to use based on availability #
# Prefer hidraw backend, then libusb # # Prefer hidraw backend, then libusb #

View file

@ -46,26 +46,36 @@ void PluginManager::RegisterRemovePluginCallback(RemovePluginCallback new_callba
void PluginManager::ScanAndLoadPlugins() void PluginManager::ScanAndLoadPlugins()
{ {
/*---------------------------------------------------------*\ /*---------------------------------------------------------*\
| Get the plugins directory | | Get the user plugins directory |
| | | |
| The plugins directory is a directory named "plugins" in | | The user plugins directory is a directory named "plugins" |
| the configuration directory | | in the configuration directory |
\*---------------------------------------------------------*/ \*---------------------------------------------------------*/
filesystem::path plugins_dir = ResourceManager::get()->GetConfigurationDirectory() / plugins_path; filesystem::path plugins_dir = ResourceManager::get()->GetConfigurationDirectory() / plugins_path;
ScanAndLoadPluginsFrom(plugins_dir); ScanAndLoadPluginsFrom(plugins_dir, false);
#ifdef OPENRGB_EXTRA_PLUGIN_DIRECTORY #ifdef OPENRGB_SYSTEM_PLUGIN_DIRECTORY
/*-----------------------------------------------------------------*\ /*---------------------------------------------------------*\
| An additional plugin directory can be set during build time, e.g. | | Get the system plugins directory |
| by the Linux distro to load plugins installed via package manager | | |
\*-----------------------------------------------------------------*/ | The system plugin directory can be set during build time, |
ScanAndLoadPluginsFrom(OPENRGB_EXTRA_PLUGIN_DIRECTORY); | e.g. by the package maintainer to load plugins installed |
| via package manager |
\*---------------------------------------------------------*/
ScanAndLoadPluginsFrom(OPENRGB_SYSTEM_PLUGIN_DIRECTORY, true);
#endif #endif
} }
void PluginManager::ScanAndLoadPluginsFrom(const filesystem::path & plugins_dir) void PluginManager::ScanAndLoadPluginsFrom(const filesystem::path & plugins_dir, bool is_system)
{ {
LOG_TRACE("[PluginManager] Scanning plugin directory: %s", plugins_dir.generic_u8string().c_str()); if(is_system)
{
LOG_TRACE("[PluginManager] Scanning system plugin directory: %s", plugins_dir.generic_u8string().c_str());
}
else
{
LOG_TRACE("[PluginManager] Scanning user plugin directory: %s", plugins_dir.generic_u8string().c_str());
}
if(!filesystem::is_directory(plugins_dir)) if(!filesystem::is_directory(plugins_dir))
{ {
@ -85,11 +95,11 @@ void PluginManager::ScanAndLoadPluginsFrom(const filesystem::path & plugins_dir)
filesystem::path plugin_path = entry.path(); filesystem::path plugin_path = entry.path();
LOG_TRACE("[PluginManager] Found plugin file %s", plugin_path.filename().generic_u8string().c_str()); LOG_TRACE("[PluginManager] Found plugin file %s", plugin_path.filename().generic_u8string().c_str());
AddPlugin(plugin_path); AddPlugin(plugin_path, is_system);
} }
} }
void PluginManager::AddPlugin(const filesystem::path& path) void PluginManager::AddPlugin(const filesystem::path& path, bool is_system)
{ {
OpenRGBPluginInterface* plugin = nullptr; OpenRGBPluginInterface* plugin = nullptr;
@ -214,6 +224,7 @@ void PluginManager::AddPlugin(const filesystem::path& path)
entry.widget = nullptr; entry.widget = nullptr;
entry.incompatible = false; entry.incompatible = false;
entry.api_version = plugin->GetPluginAPIVersion(); entry.api_version = plugin->GetPluginAPIVersion();
entry.is_system = is_system;
loader->unload(); loader->unload();

View file

@ -27,6 +27,7 @@ typedef struct
std::string path; std::string path;
bool enabled; bool enabled;
bool incompatible; bool incompatible;
bool is_system;
int api_version; int api_version;
} OpenRGBPluginEntry; } OpenRGBPluginEntry;
@ -43,7 +44,7 @@ public:
void ScanAndLoadPlugins(); void ScanAndLoadPlugins();
void AddPlugin(const filesystem::path& path); void AddPlugin(const filesystem::path& path, bool is_system);
void RemovePlugin(const filesystem::path& path); void RemovePlugin(const filesystem::path& path);
void LoadPlugin(const filesystem::path& path); void LoadPlugin(const filesystem::path& path);
@ -54,7 +55,7 @@ public:
std::vector<OpenRGBPluginEntry> ActivePlugins; std::vector<OpenRGBPluginEntry> ActivePlugins;
private: private:
void ScanAndLoadPluginsFrom(const filesystem::path & plugins_dir); void ScanAndLoadPluginsFrom(const filesystem::path & plugins_dir, bool is_system);
AddPluginCallback AddPluginCallbackVal; AddPluginCallback AddPluginCallbackVal;
void * AddPluginCallbackArg; void * AddPluginCallbackArg;

View file

@ -26,7 +26,9 @@ class Ui::OpenRGBPluginsEntry : public QWidget
public: public:
explicit OpenRGBPluginsEntry(QWidget *parent = nullptr); explicit OpenRGBPluginsEntry(QWidget *parent = nullptr);
~OpenRGBPluginsEntry(); ~OpenRGBPluginsEntry();
Ui::OpenRGBPluginsEntryUi *ui;
Ui::OpenRGBPluginsEntryUi * ui;
bool is_system;
void RegisterEnableClickCallback(EnableClickCallback new_callback, void * new_callback_arg); void RegisterEnableClickCallback(EnableClickCallback new_callback, void * new_callback_arg);

View file

@ -96,6 +96,8 @@ void Ui::OpenRGBPluginsPage::RefreshList()
entry->RegisterEnableClickCallback(EnableClickCallbackFunction, this); entry->RegisterEnableClickCallback(EnableClickCallbackFunction, this);
entry->is_system = plugin.is_system;
/*---------------------------------------------------------*\ /*---------------------------------------------------------*\
| Add the entry to the plugin list | | Add the entry to the plugin list |
\*---------------------------------------------------------*/ \*---------------------------------------------------------*/
@ -171,7 +173,7 @@ bool Ui::OpenRGBPluginsPage::InstallPlugin(std::string install_file)
LOG_TRACE("[OpenRGBPluginsPage] Copying from %s to %s", from_path.c_str(), to_path.c_str()); LOG_TRACE("[OpenRGBPluginsPage] Copying from %s to %s", from_path.c_str(), to_path.c_str());
filesystem::copy(from_path, to_path, filesystem::copy_options::overwrite_existing); filesystem::copy(from_path, to_path, filesystem::copy_options::overwrite_existing);
plugin_manager->AddPlugin(to_path); plugin_manager->AddPlugin(to_path, false);
return true; return true;
} }
@ -207,6 +209,14 @@ void Ui::OpenRGBPluginsPage::on_RemovePluginButton_clicked()
return; return;
} }
/*-----------------------------------------------------*\
| Don't allow removing system plugins |
\*-----------------------------------------------------*/
if(entries[cur_row]->is_system)
{
return;
}
/*-----------------------------------------------------*\ /*-----------------------------------------------------*\
| Open plugin settings | | Open plugin settings |
\*-----------------------------------------------------*/ \*-----------------------------------------------------*/
@ -336,9 +346,18 @@ void Ui::OpenRGBPluginsPage::on_EnableButton_clicked(OpenRGBPluginsEntry* entry)
void Ui::OpenRGBPluginsPage::on_PluginsList_itemSelectionChanged() void Ui::OpenRGBPluginsPage::on_PluginsList_itemSelectionChanged()
{ {
/*-----------------------------------------------------*\ /*-----------------------------------------------------*\
| Enable the remove button when there's a selected item | | Get index of selected plugin entry |
\*-----------------------------------------------------*/ \*-----------------------------------------------------*/
ui->RemovePluginButton->setEnabled(!ui->PluginsList->selectedItems().empty()); int cur_row = ui->PluginsList->currentRow();
/*-----------------------------------------------------*\
| Enable the remove button when there's a selected item |
| and the selected item is not a system plugin |
\*-----------------------------------------------------*/
if(!entries[cur_row]->is_system)
{
ui->RemovePluginButton->setEnabled(!ui->PluginsList->selectedItems().empty());
}
} }
void Ui::OpenRGBPluginsPage::on_PluginsList_PluginsDropped(std::vector<std::string> path_list) void Ui::OpenRGBPluginsPage::on_PluginsList_PluginsDropped(std::vector<std::string> path_list)