refactor(tree): split the plugin host from the providers it loads
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.
This commit is contained in:
15 files changed
+39
-39
No files matched your search
@@ -0,0 +1,108 @@
|
||||
#pragma once
|
||||
|
||||
#include "package-manager.h"
|
||||
|
||||
// Flatpak provider: manages flatpak applications through the `flatpak` CLI.
|
||||
// Unlike pacman it runs per-user (no sudo), so requiresPassword() is false.
|
||||
class FlatpakManager : public IPackageManager {
|
||||
public:
|
||||
std::string getName() const override { return "flatpak"; }
|
||||
std::string getVersion() const override { return "1.0.0"; }
|
||||
std::string getDescription() const override {
|
||||
return "Gestionnaire d'applications Flatpak";
|
||||
}
|
||||
|
||||
bool canSearch() const override { return true; }
|
||||
bool canInstall() const override { return true; }
|
||||
bool canRemove() const override { return true; }
|
||||
bool canUpdate() const override { return true; }
|
||||
bool canListInstalled() const override { return true; }
|
||||
|
||||
bool isAvailable() const override {
|
||||
return system("which flatpak > /dev/null 2>&1") == 0;
|
||||
}
|
||||
|
||||
// Last lines of the failed command output, shown to the user on failure.
|
||||
std::string lastError() const override { return m_lastError; }
|
||||
|
||||
// Parse `flatpak search` output (one whitespace-aligned row per app:
|
||||
// "Name Description Application ID Version Branch Remotes").
|
||||
// Exposed as static so the parsing can be unit-tested without flatpak.
|
||||
static std::vector<PackageInfo> parseSearchOutput(const std::string& output);
|
||||
|
||||
// Parse `flatpak list --columns=application,version,origin` output
|
||||
// (tab-separated fields per installed application).
|
||||
static std::vector<PackageInfo> parseInstalledOutput(const std::string& output);
|
||||
|
||||
// Parse `flatpak remote-ls --updates --columns=application,version` output
|
||||
// (tab-separated fields per application with a pending update).
|
||||
static std::vector<PackageInfo> parseUpdatesOutput(const std::string& output);
|
||||
|
||||
// The Flatpak file formats the app accepts from the window (drag & drop) and
|
||||
// from the file manager ("Ouvrir avec PacManager").
|
||||
enum class FileKind { None, Ref, Repo, Bundle };
|
||||
|
||||
// Classify by extension, ignoring case and any URL query/fragment, so a
|
||||
// local path and a flathub URL are both recognised. Exposed as static so the
|
||||
// routing can be unit-tested without flatpak.
|
||||
static FileKind classifyFile(const std::string& path);
|
||||
|
||||
// Command that installs a ref or bundle file, or registers a repository
|
||||
// (.flatpakrepo). Exposed so the exact command line is testable without
|
||||
// running flatpak.
|
||||
static std::string installFileCommand(FileKind kind, const std::string& path,
|
||||
bool userScope = false);
|
||||
|
||||
// Commands that act on exactly one installation of an application. Both take
|
||||
// either an application id — flatpak then refuses it when several copies
|
||||
// exist — or a target ("user:com.example.App/x86_64/stable") naming one copy,
|
||||
// as found in PackageInfo::instances. Exposed so the exact command line is
|
||||
// testable without running flatpak.
|
||||
static std::string uninstallCommand(const std::string& packageName);
|
||||
static std::string updateCommand(const std::string& packageName);
|
||||
|
||||
// Name a `.flatpakrepo` is registered under: its base name without the
|
||||
// extension (flathub.flatpakrepo -> flathub), which is what the user then
|
||||
// types in `flatpak install <name> <app>`.
|
||||
static std::string repoNamespace(const std::string& path);
|
||||
|
||||
std::vector<PackageInfo> search(const std::string& query) override;
|
||||
bool install(const std::string& packageName,
|
||||
ProgressCallback progressCallback) override;
|
||||
bool remove(const std::string& packageName,
|
||||
ProgressCallback progressCallback) override;
|
||||
bool update(const std::string& packageName = "",
|
||||
ProgressCallback progressCallback = nullptr) override;
|
||||
std::vector<PackageInfo> listInstalled() override;
|
||||
std::vector<PackageInfo> listUpdates() override;
|
||||
bool refresh(ProgressCallback progressCallback = nullptr) override;
|
||||
|
||||
// Cleanup: flatpak knows which runtimes no installed application uses any
|
||||
// more, so it can reclaim them from the maintenance page.
|
||||
bool canCleanCache() const override { return true; }
|
||||
bool cleanCache(ProgressCallback progressCallback = nullptr) override;
|
||||
|
||||
// Install from a Flatpak file: a `.flatpakref` (an application reference
|
||||
// served by a remote), a `.flatpakrepo` (a remote definition) or a `.flatpak`
|
||||
// bundle. Unlike a name-based install these come from the user's disk or a
|
||||
// URL, so flatpak resolves the remote itself.
|
||||
bool canInstallFile(const std::string& path) const override;
|
||||
bool installFile(const std::string& path, ProgressCallback progressCallback) override;
|
||||
|
||||
// Make an app appear in the desktop's application launcher (wofi, GNOME,
|
||||
// KDE, ...) regardless of XDG_DATA_DIRS, like a pacman install would: link
|
||||
// its .desktop entries and icons from flatpak's exports into the user's
|
||||
// standard XDG directories (~/.local/share/{applications,icons}). Exposed
|
||||
// as static so the linking can be unit/integration tested without flatpak.
|
||||
static void integrateDesktopEntries(const std::string& appId);
|
||||
static void uninstallDesktopEntries(const std::string& appId);
|
||||
|
||||
// Re-link every installed app so launchers pick up apps whose integration
|
||||
// is missing (e.g. installed before this feature existed).
|
||||
void integrateAllInstalled();
|
||||
|
||||
private:
|
||||
bool isInstalled(const std::string& appId);
|
||||
|
||||
std::string m_lastError;
|
||||
};
|
||||
Reference in new issue
Block a user