#pragma once #include "provider-plugin.h" #include #include #include #include // Registry of every plugin known to the application. It owns each plugin // (built-in and external), loads shared-library plugins dropped in the plugin // directories at runtime (see PluginManager::scanDirectory) and tracks which // are enabled in the settings. A plugin is either a package-manager provider // (implements IPackageManager) or a generic addon (implements IPlugin) — both // kinds share the same loading, lifecycle and enable/disable flow. class PluginManager { public: struct PluginEntry { PluginInfo info; IPlugin* plugin = nullptr; // non-null for addon plugins IPackageManager* manager = nullptr; // non-null for provider plugins QLibrary* library = nullptr; // owned by the PluginManager; null for built-ins }; PluginManager(); ~PluginManager(); // Register a provider compiled into the application (e.g. pacman). // Takes ownership of the manager. void registerBuiltin(PluginInfo info, IPackageManager* manager); // Scan the plugin directories for external plugins and load them. void discoverExternal(); // Drop external plugins and rescan their directories; built-in plugins // are kept (their instances stay valid). void reload(); // Re-run isAvailable() on every plugin (e.g. after the app installed a // missing tool) so the Plugins page reflects reality. void refreshAvailability(); // All known plugins, in registration order. const std::vector& plugins() const; // Provider plugins that are enabled (in settings) and whose tool is on the // system. std::vector availableProviders() const; // Same as availableProviders() but as plain manager pointers, convenient // for running aggregated operations across every provider. std::vector availableManagers() const; // A single available+enabled provider matching id, or nullptr. const PluginEntry* findAvailable(const std::string& id) const; // Addon plugins that are enabled and available (e.g. to hand the main // window to via IPlugin::onUiReady). std::vector availableAddons() 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 m_plugins; QSettings m_settings; };