feat(providers): add provider plugin system
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>
This commit is contained in:
7 files changed
+390
No files matched your search
@@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include "package-manager.h"
|
||||
#include <string>
|
||||
|
||||
// Metadata describing a provider, whether it is compiled into the application
|
||||
// (pacman, flatpak) or loaded at runtime from an external plugin.
|
||||
struct ProviderInfo {
|
||||
std::string id; // unique identifier, e.g. "pacman", "flatpak"
|
||||
std::string name; // display name, e.g. "Flatpak"
|
||||
std::string version; // plugin version
|
||||
std::string description; // what this provider manages
|
||||
std::string author; // who wrote the provider
|
||||
bool builtin = false; // true when compiled into the application
|
||||
std::string path; // filesystem path (external plugins only)
|
||||
bool available = false; // whether the backing tool is present on the system
|
||||
// OS package name providing the backing tool (e.g. "flatpak"). Empty when
|
||||
// the provider cannot be installed from the application.
|
||||
std::string installHint;
|
||||
};
|
||||
|
||||
// ---- External plugin contract (C ABI) ----
|
||||
//
|
||||
// An external provider plugin is a shared library (lib*.so / *.dll) dropped in
|
||||
// a plugin directory (see PluginManager). It must export the symbols below so
|
||||
// the host can query metadata and instantiate the provider. The convenience
|
||||
// macro FWS_PROVIDER_PLUGIN generates them from a class implementing
|
||||
// IPackageManager:
|
||||
//
|
||||
// #include "provider-plugin.h"
|
||||
// #include "my-manager.h"
|
||||
// FWS_PROVIDER_PLUGIN(MyManager, "myprov", "My Provider", "1.0.0",
|
||||
// "Manages my stuff", "Jane Doe");
|
||||
//
|
||||
// Plugins are compiled with the same toolchain/headers as the host, exactly
|
||||
// like Qt plugins, so the IPackageManager vtable and PackageInfo layout match.
|
||||
extern "C" {
|
||||
const char* fws_plugin_id();
|
||||
const char* fws_plugin_name();
|
||||
const char* fws_plugin_version();
|
||||
const char* fws_plugin_description();
|
||||
const char* fws_plugin_author();
|
||||
IPackageManager* fws_create_provider();
|
||||
// Optional: OS package name that provides the backing tool, so the app can
|
||||
// offer to install it when unavailable. May be omitted by a plugin.
|
||||
const char* fws_plugin_install_hint();
|
||||
}
|
||||
|
||||
#define FWS_PROVIDER_PLUGIN(PluginClass, id_, name_, version_, desc_, author_) \
|
||||
extern "C" const char* fws_plugin_id() { return id_; } \
|
||||
extern "C" const char* fws_plugin_name() { return name_; } \
|
||||
extern "C" const char* fws_plugin_version() { return version_; } \
|
||||
extern "C" const char* fws_plugin_description() { return desc_; } \
|
||||
extern "C" const char* fws_plugin_author() { return author_; } \
|
||||
extern "C" IPackageManager* fws_create_provider() { return new PluginClass(); }
|
||||
Reference in new issue
Block a user