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>
53 lines
2.2 KiB
C++
53 lines
2.2 KiB
C++
// Example external provider plugin — a template for adding new package
|
|
// providers without touching the application code.
|
|
//
|
|
// Build it as a shared library and drop it in a plugin directory
|
|
// (next to the PacManager binary in ./plugins/ or in
|
|
// ~/.local/share/PacManager/plugins/); the app discovers it at launch and on
|
|
// the Providers page via "Recharger".
|
|
//
|
|
// A plugin only needs to:
|
|
// 1. implement IPackageManager (see include/package-manager.h)
|
|
// 2. export the C ABI symbols via the FWS_PROVIDER_PLUGIN macro
|
|
//
|
|
// To build with CMake from the project root:
|
|
// cmake -B build -DFWS_BUILD_EXAMPLE_PLUGIN=ON && cmake --build build
|
|
|
|
#include "provider-plugin.h"
|
|
|
|
// A trivial provider that reports itself as always available but manages
|
|
// nothing — replace the stubs with real commands (apt, dnf, zypper, ...).
|
|
class SampleProvider : public IPackageManager {
|
|
public:
|
|
std::string getName() const override { return "sample"; }
|
|
std::string getVersion() const override { return "0.1.0"; }
|
|
std::string getDescription() const override {
|
|
return "Exemple de plugin fournisseur (modèle à copier)";
|
|
}
|
|
|
|
bool canSearch() const override { return false; }
|
|
bool canInstall() const override { return false; }
|
|
bool canRemove() const override { return false; }
|
|
bool canUpdate() const override { return false; }
|
|
bool canListInstalled() const override { return false; }
|
|
|
|
bool isAvailable() const override { return true; }
|
|
|
|
std::vector<PackageInfo> search(const std::string&) override { return {}; }
|
|
bool install(const std::string&, std::function<void(const std::string&)>) override {
|
|
return false;
|
|
}
|
|
bool remove(const std::string&, std::function<void(const std::string&)>) override {
|
|
return false;
|
|
}
|
|
bool update(const std::string&, std::function<void(const std::string&)>) override {
|
|
return false;
|
|
}
|
|
std::vector<PackageInfo> listInstalled() override { return {}; }
|
|
std::vector<PackageInfo> listUpdates() override { return {}; }
|
|
bool refresh(std::function<void(const std::string&)>) override { return false; }
|
|
};
|
|
|
|
FWS_PROVIDER_PLUGIN(SampleProvider, "sample", "Sample Provider", "0.1.0",
|
|
"Exemple de plugin fournisseur (modèle à copier)", "FWS");
|