plugins/ held two unrelated things: the host that discovers and installs plugins, and the plugins themselves. The host moves to plugins/ with the built-in pacman provider beside it in providers/, where the external providers already live — so plugins/ is now one thing, and the name says which. The external plugin projects only change folder, not layout: providers/ holds aur-provider, flatpak-provider, example-provider and example-addon.
73 lines
2.7 KiB
C++
73 lines
2.7 KiB
C++
#pragma once
|
|
|
|
#include "provider-plugin.h"
|
|
#include <QSettings>
|
|
#include <QLibrary>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
// 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<PluginEntry>& plugins() const;
|
|
|
|
// Provider plugins that are enabled (in settings) and whose tool is on the
|
|
// system.
|
|
std::vector<const PluginEntry*> 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 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<IPlugin*> 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<PluginEntry> m_plugins;
|
|
QSettings m_settings;
|
|
}; |