Introduce a registry (PluginManager) that owns package managers and can load additional providers at runtime from shared-library plugins dropped in a plugins directory. Providers declare their metadata and a factory through a C ABI (provider-plugin.h); requiresPassword() tells the UI whether a provider needs sudo. Ships a sample external plugin as a template for adding new backends. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
65 lines
2.3 KiB
C++
65 lines
2.3 KiB
C++
#pragma once
|
|
|
|
#include "provider-plugin.h"
|
|
#include <QSettings>
|
|
#include <QLibrary>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
// Registry of package providers. It owns every IPackageManager (built-in and
|
|
// external) and can load additional providers at runtime from shared-library
|
|
// plugins dropped in the plugin directories (see PluginManager::scanDirectory).
|
|
class PluginManager {
|
|
public:
|
|
struct ProviderEntry {
|
|
ProviderInfo info;
|
|
IPackageManager* manager = nullptr; // owned by the PluginManager
|
|
QLibrary* library = nullptr; // owned by the PluginManager; null for built-ins
|
|
};
|
|
|
|
PluginManager();
|
|
~PluginManager();
|
|
|
|
// Register a provider compiled into the application (e.g. pacman, flatpak).
|
|
// Takes ownership of the manager.
|
|
void registerBuiltin(ProviderInfo info, IPackageManager* manager);
|
|
|
|
// Scan the plugin directories for external provider plugins and load them.
|
|
void discoverExternal();
|
|
|
|
// Drop external plugins and rescan their directories; built-in providers
|
|
// are kept (their instances stay valid).
|
|
void reload();
|
|
|
|
// Re-run isAvailable() on every known provider (e.g. after the app
|
|
// installed a missing tool) so the Providers page reflects reality.
|
|
void refreshAvailability();
|
|
|
|
// All known providers, in registration order.
|
|
const std::vector<ProviderEntry>& providers() const;
|
|
|
|
// Providers that are enabled (in settings) and whose tool is on the system.
|
|
std::vector<const ProviderEntry*> availableProviders() const;
|
|
|
|
// Same as availableProviders() but as plain manager pointers, convenient
|
|
// for running aggregated operations across every provider.
|
|
std::vector<IPackageManager*> availableManagers() const;
|
|
|
|
// A single available+enabled provider matching id, or nullptr.
|
|
const ProviderEntry* findAvailable(const std::string& id) const;
|
|
|
|
bool isEnabled(const std::string& id) const;
|
|
void setEnabled(const std::string& id, bool enabled);
|
|
|
|
// Manager for a known provider id (enabled or not), or nullptr.
|
|
IPackageManager* managerFor(const std::string& id) const;
|
|
|
|
private:
|
|
bool loadPluginFile(const QString& filePath);
|
|
void scanDirectory(const QString& dir);
|
|
void unloadExternal();
|
|
|
|
std::vector<ProviderEntry> m_providers;
|
|
QSettings m_settings;
|
|
};
|