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>
61 lines
2.1 KiB
C++
61 lines
2.1 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
#include <functional>
|
|
|
|
// Information about a single package
|
|
struct PackageInfo {
|
|
std::string name;
|
|
std::string version;
|
|
std::string description;
|
|
std::string repository;
|
|
std::string size;
|
|
std::string installedSize;
|
|
// Id of the provider that owns this package (e.g. "pacman", "flatpak").
|
|
// Filled by the aggregating workers so operations can be routed to the
|
|
// right manager without the user picking one.
|
|
std::string provider;
|
|
bool installed = false;
|
|
bool updateAvailable = false;
|
|
};
|
|
|
|
// Abstract interface for the package manager
|
|
class IPackageManager {
|
|
public:
|
|
virtual ~IPackageManager() = default;
|
|
|
|
// Identity
|
|
virtual std::string getName() const = 0;
|
|
virtual std::string getVersion() const = 0;
|
|
virtual std::string getDescription() const = 0;
|
|
|
|
// Capabilities
|
|
virtual bool canSearch() const = 0;
|
|
virtual bool canInstall() const = 0;
|
|
virtual bool canRemove() const = 0;
|
|
virtual bool canUpdate() const = 0;
|
|
virtual bool canListInstalled() const = 0;
|
|
|
|
// Operations
|
|
virtual std::vector<PackageInfo> search(const std::string& query) = 0;
|
|
virtual bool install(const std::string& packageName,
|
|
std::function<void(const std::string&)> progressCallback = nullptr) = 0;
|
|
virtual bool remove(const std::string& packageName,
|
|
std::function<void(const std::string&)> progressCallback = nullptr) = 0;
|
|
virtual bool update(const std::string& packageName = "",
|
|
std::function<void(const std::string&)> progressCallback = nullptr) = 0;
|
|
virtual std::vector<PackageInfo> listInstalled() = 0;
|
|
virtual std::vector<PackageInfo> listUpdates() = 0;
|
|
virtual bool refresh(std::function<void(const std::string&)> progressCallback = nullptr) = 0;
|
|
|
|
// Check if the package manager is available on the system
|
|
virtual bool isAvailable() const = 0;
|
|
|
|
// Whether privileged operations need a password (e.g. sudo for pacman).
|
|
// Providers that run per-user (e.g. flatpak) can keep the default.
|
|
virtual bool requiresPassword() const { return false; }
|
|
};
|
|
|
|
|