Initial support for system-installed plugins in Linux
This commit is contained in:
parent
806ababa05
commit
d03701c58d
5 changed files with 56 additions and 20 deletions
|
|
@ -485,6 +485,9 @@ contains(QMAKE_PLATFORM, linux) {
|
|||
|
||||
QMAKE_CXXFLAGS += -Wno-implicit-fallthrough
|
||||
|
||||
DEFINES += \
|
||||
OPENRGB_SYSTEM_PLUGIN_DIRECTORY=\\"\"\"$$PREFIX/lib/openrgb/plugins\\"\"\" \
|
||||
|
||||
#-------------------------------------------------------------------------------------------#
|
||||
# Determine which hidapi to use based on availability #
|
||||
# Prefer hidraw backend, then libusb #
|
||||
|
|
|
|||
|
|
@ -46,26 +46,36 @@ void PluginManager::RegisterRemovePluginCallback(RemovePluginCallback new_callba
|
|||
void PluginManager::ScanAndLoadPlugins()
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Get the plugins directory |
|
||||
| Get the user plugins directory |
|
||||
| |
|
||||
| The plugins directory is a directory named "plugins" in |
|
||||
| the configuration directory |
|
||||
| The user plugins directory is a directory named "plugins" |
|
||||
| in the configuration directory |
|
||||
\*---------------------------------------------------------*/
|
||||
filesystem::path plugins_dir = ResourceManager::get()->GetConfigurationDirectory() / plugins_path;
|
||||
ScanAndLoadPluginsFrom(plugins_dir);
|
||||
ScanAndLoadPluginsFrom(plugins_dir, false);
|
||||
|
||||
#ifdef OPENRGB_EXTRA_PLUGIN_DIRECTORY
|
||||
/*-----------------------------------------------------------------*\
|
||||
| An additional plugin directory can be set during build time, e.g. |
|
||||
| by the Linux distro to load plugins installed via package manager |
|
||||
\*-----------------------------------------------------------------*/
|
||||
ScanAndLoadPluginsFrom(OPENRGB_EXTRA_PLUGIN_DIRECTORY);
|
||||
#ifdef OPENRGB_SYSTEM_PLUGIN_DIRECTORY
|
||||
/*---------------------------------------------------------*\
|
||||
| Get the system plugins directory |
|
||||
| |
|
||||
| The system plugin directory can be set during build time, |
|
||||
| e.g. by the package maintainer to load plugins installed |
|
||||
| via package manager |
|
||||
\*---------------------------------------------------------*/
|
||||
ScanAndLoadPluginsFrom(OPENRGB_SYSTEM_PLUGIN_DIRECTORY, true);
|
||||
#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))
|
||||
{
|
||||
|
|
@ -85,11 +95,11 @@ void PluginManager::ScanAndLoadPluginsFrom(const filesystem::path & plugins_dir)
|
|||
|
||||
filesystem::path plugin_path = entry.path();
|
||||
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;
|
||||
|
||||
|
|
@ -214,6 +224,7 @@ void PluginManager::AddPlugin(const filesystem::path& path)
|
|||
entry.widget = nullptr;
|
||||
entry.incompatible = false;
|
||||
entry.api_version = plugin->GetPluginAPIVersion();
|
||||
entry.is_system = is_system;
|
||||
|
||||
loader->unload();
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ typedef struct
|
|||
std::string path;
|
||||
bool enabled;
|
||||
bool incompatible;
|
||||
bool is_system;
|
||||
int api_version;
|
||||
} OpenRGBPluginEntry;
|
||||
|
||||
|
|
@ -43,7 +44,7 @@ public:
|
|||
|
||||
void ScanAndLoadPlugins();
|
||||
|
||||
void AddPlugin(const filesystem::path& path);
|
||||
void AddPlugin(const filesystem::path& path, bool is_system);
|
||||
void RemovePlugin(const filesystem::path& path);
|
||||
|
||||
void LoadPlugin(const filesystem::path& path);
|
||||
|
|
@ -54,7 +55,7 @@ public:
|
|||
std::vector<OpenRGBPluginEntry> ActivePlugins;
|
||||
|
||||
private:
|
||||
void ScanAndLoadPluginsFrom(const filesystem::path & plugins_dir);
|
||||
void ScanAndLoadPluginsFrom(const filesystem::path & plugins_dir, bool is_system);
|
||||
|
||||
AddPluginCallback AddPluginCallbackVal;
|
||||
void * AddPluginCallbackArg;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,9 @@ class Ui::OpenRGBPluginsEntry : public QWidget
|
|||
public:
|
||||
explicit OpenRGBPluginsEntry(QWidget *parent = nullptr);
|
||||
~OpenRGBPluginsEntry();
|
||||
Ui::OpenRGBPluginsEntryUi *ui;
|
||||
|
||||
Ui::OpenRGBPluginsEntryUi * ui;
|
||||
bool is_system;
|
||||
|
||||
void RegisterEnableClickCallback(EnableClickCallback new_callback, void * new_callback_arg);
|
||||
|
||||
|
|
|
|||
|
|
@ -96,6 +96,8 @@ void Ui::OpenRGBPluginsPage::RefreshList()
|
|||
|
||||
entry->RegisterEnableClickCallback(EnableClickCallbackFunction, this);
|
||||
|
||||
entry->is_system = plugin.is_system;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| 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());
|
||||
filesystem::copy(from_path, to_path, filesystem::copy_options::overwrite_existing);
|
||||
|
||||
plugin_manager->AddPlugin(to_path);
|
||||
plugin_manager->AddPlugin(to_path, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -207,6 +209,14 @@ void Ui::OpenRGBPluginsPage::on_RemovePluginButton_clicked()
|
|||
return;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Don't allow removing system plugins |
|
||||
\*-----------------------------------------------------*/
|
||||
if(entries[cur_row]->is_system)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Open plugin settings |
|
||||
\*-----------------------------------------------------*/
|
||||
|
|
@ -336,9 +346,18 @@ void Ui::OpenRGBPluginsPage::on_EnableButton_clicked(OpenRGBPluginsEntry* entry)
|
|||
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue