Installing through a system-wide remote fails under polkit and, when a
remote exists in both installations, flatpak refuses non-interactive
installs ("Multiple remotes have refs matching"). Retry with an explicit
`--user flathub` target, refresh appstream metadata before giving up on
stale refs, and let update/refresh fall back to the user installation as
well. Expose the last command output through IPackageManager::lastError
and show it in a dialog on failure instead of failing silently.
🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
57 lines
2.5 KiB
C++
57 lines
2.5 KiB
C++
#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);
|
|
|
|
std::vector<PackageInfo> search(const std::string& query) override;
|
|
bool install(const std::string& packageName,
|
|
std::function<void(const std::string&)> progressCallback) override;
|
|
bool remove(const std::string& packageName,
|
|
std::function<void(const std::string&)> progressCallback) override;
|
|
bool update(const std::string& packageName = "",
|
|
std::function<void(const std::string&)> progressCallback = nullptr) override;
|
|
std::vector<PackageInfo> listInstalled() override;
|
|
std::vector<PackageInfo> listUpdates() override;
|
|
bool refresh(std::function<void(const std::string&)> progressCallback = nullptr) override;
|
|
|
|
private:
|
|
bool isInstalled(const std::string& appId);
|
|
|
|
std::string m_lastError;
|
|
};
|