From 1b3f11aad8229f29d7b2c95920d7e80404c52382 Mon Sep 17 00:00:00 2001 From: BlackAngelTV Date: Sat, 29 Aug 2026 15:05:14 +0200 Subject: [PATCH] fix(flatpak): show honest search status and harden install MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Search results now report whether each app is already installed or has a pending update, like pacman does with its [installed] marker, so the UI no longer shows "Disponible" for apps that are already managed. Install is also idempotent (already-deployed apps short-circuit) and skips the doomed bare retry when both a system and a user flathub remote make the ref ambiguous. 🤖 Generated with Codebuff Co-Authored-By: Codebuff --- src/flatpak-manager.cpp | 64 ++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/src/flatpak-manager.cpp b/src/flatpak-manager.cpp index 1e07ff1..62ea175 100644 --- a/src/flatpak-manager.cpp +++ b/src/flatpak-manager.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include // Helper to run shell commands and capture output. @@ -182,7 +183,24 @@ std::vector FlatpakManager::parseUpdatesOutput(const std::string& o std::vector FlatpakManager::search(const std::string& query) { std::string cmd = "flatpak search " + query + " 2>&1"; - return parseSearchOutput(exec(cmd.c_str())); + std::vector results = parseSearchOutput(exec(cmd.c_str())); + + // Report the honest status of each hit (already installed / pending + // update) so the search page does not keep showing "Disponible" for apps + // that are already managed, like pacman does with its [installed] marker. + if (!results.empty()) { + std::set installed; + for (const auto& pkg : listInstalled()) installed.insert(pkg.name); + std::set outdated; + for (const auto& pkg : listUpdates()) outdated.insert(pkg.name); + + for (auto& pkg : results) { + pkg.installed = installed.count(pkg.name) > 0; + pkg.updateAvailable = outdated.count(pkg.name) > 0; + } + } + + return results; } std::vector FlatpakManager::listInstalled() { @@ -203,35 +221,49 @@ bool FlatpakManager::isInstalled(const std::string& appId) { bool FlatpakManager::install(const std::string& packageName, std::function progressCallback) { m_lastError.clear(); - if (progressCallback) progressCallback("Installation de " + packageName + "..."); - // A fresh flatpak setup has no remote configured: add the default flathub - // one (idempotent, per-user) so the install can resolve the app. - streamOutput( - exec("flatpak remote-add --if-not-exists --user flathub " - "https://flathub.org/repo/flathub.flatpakrepo 2>&1"), - progressCallback); + // Idempotent: an app already deployed (in either installation) is reported + // as installed without re-running the installer. + if (isInstalled(packageName)) { + if (progressCallback) progressCallback(packageName + " est déjà installé."); + return true; + } + + if (progressCallback) progressCallback("Installation de " + packageName + "..."); auto tryInstall = [&](const std::string& extra) { return exec(("flatpak install --noninteractive --assumeyes " + extra + " " + packageName + " 2>&1").c_str()); }; + // A fresh flatpak setup has no remote configured: add the default flathub + // one (idempotent, per-user) so the install can resolve the app. + exec("flatpak remote-add --if-not-exists --user flathub " + "https://flathub.org/repo/flathub.flatpakrepo 2>&1"); + std::string output = tryInstall(""); + auto ambiguous = [&]() { + return output.find("Multiple remotes") != std::string::npos; + }; + auto noRefs = [&]() { + return output.find("No refs found") != std::string::npos + || output.find("No remote refs") != std::string::npos; + }; + // Stale remote metadata makes flatpak report "No refs found": refresh the - // appstream cache and retry once before giving up. + // appstream cache and retry once before giving up. When both a system and + // a user flathub remote exist, flatpak refuses to pick one in non- + // interactive mode, so go straight to the per-user installation instead of + // repeating a doomed attempt. if (output.find("error:") != std::string::npos && !isInstalled(packageName) - && (output.find("No refs found") != std::string::npos - || output.find("No remote refs") != std::string::npos)) { + && (noRefs() || ambiguous())) { if (progressCallback) progressCallback("Mise à jour des métadonnées des dépôts..."); - streamOutput(exec("flatpak update --appstream 2>&1"), progressCallback); - output = tryInstall(""); + exec("flatpak update --appstream 2>&1"); + output = tryInstall(ambiguous() ? "--user flathub" : ""); } - // Failures worth a second attempt in the per-user installation (no polkit, - // no ambiguity): "Multiple remotes have refs matching", system-wide - // remotes requiring authentication, or missing user metadata. + // Remaining failures get one per-user attempt (no polkit, no ambiguity). if (output.find("error:") != std::string::npos && !isInstalled(packageName)) { if (progressCallback) progressCallback("Nouvel essai en mode utilisateur..."); output = tryInstall("--user flathub");