Files
FWS-PacManage/include/flatpak-manager.h
T
BlackAngelTV a1d8c96e4e feat(flatpak): link installed apps into the desktop launcher
When a flatpak app is installed through the app, its .desktop entries and
icons are now symlinked into the user's standard XDG dirs
(~/.local/share/{applications,icons}), which every desktop scans by default.
This makes flatpak apps appear in any launcher (wofi, GNOME, KDE...) the same
way a pacman install would, without relying on XDG_DATA_DIRS or any
desktop-specific configuration. The links are removed on uninstall, and a
refresh re-links every installed app so ones installed before this feature
(or outside the app) self-heal.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
2026-08-29 16:54:39 +02:00

69 lines
3.2 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;
// 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;
};