feat(logs): narrate what pacman and flatpak really run

Changing screen is not an operation, and a navigation line per click buried
the entries that matter. Providers now narrate the work itself instead: the
exact command, the fallbacks and the counts, through a Qt-free trace sink that
reaches the journal only, so the status bar stays short.
This commit is contained in:
BlackAngelTV committed 2026-10-03 22:38:00 +02:00
1 parent 3ca9c412d2
commit 28bef75bf6
8 files changed
+157 -48

No files matched your search

+43 -5
View File
@@ -1,6 +1,7 @@
#include "flatpak-manager.h"
#include "progress-tracker.h"
#include "provider-trace.h"
#include <array>
#include <atomic>
@@ -20,6 +21,13 @@
namespace fs = std::filesystem;
// One line of operator trace: the exact command run, the decision taken around
// it, what a listing found. The host routes it to the journal only (see
// provider-trace.h), so being verbose here costs nothing in the interface.
static void trace(const std::string& message) {
provider_trace::report("flatpak", message);
}
// The per-user standard XDG data dir (~/.local/share).
static fs::path userShareDir() {
const char* home = std::getenv("HOME");
@@ -266,6 +274,7 @@ private:
// commands themselves stay silent for minutes at a time, and these are the only
// lines the user gets while a runtime comes down.
static std::string runFlatpak(const std::string& command, ProgressCallback callback) {
trace("$ " + command);
DownloadWatcher watcher(callback);
return runWithProgress(command, callback);
}
@@ -591,6 +600,8 @@ static std::set<std::string> appIdsInOutput(const std::string& output) {
std::vector<PackageInfo> FlatpakManager::search(const std::string& query) {
std::string cmd = "flatpak search " + query + " 2>&1";
std::vector<PackageInfo> results = parseSearchOutput(exec(cmd.c_str()));
trace("flatpak search " + query + " → " + std::to_string(results.size())
+ " résultat(s)");
// Report the honest status of each hit (already installed / pending
// update) so the search page does not keep showing "Disponible" for apps
@@ -614,14 +625,21 @@ std::vector<PackageInfo> FlatpakManager::listInstalled() {
// ref, branch and installation are what tell two installations of the same
// application id apart, so they are listed: without them the view could
// neither show the copies nor choose between them.
return parseInstalledOutput(exec("flatpak list --app "
"--columns=application,version,origin,ref,branch,installation "
"2>&1"));
std::vector<PackageInfo> results =
parseInstalledOutput(exec("flatpak list --app "
"--columns=application,version,origin,ref,branch,installation "
"2>&1"));
trace("flatpak list → " + std::to_string(results.size())
+ " application(s) installée(s), copies comprises");
return results;
}
std::vector<PackageInfo> FlatpakManager::listUpdates() {
return parseUpdatesOutput(
std::vector<PackageInfo> results = parseUpdatesOutput(
exec("flatpak remote-ls --updates --columns=application,version 2>&1"));
trace("flatpak remote-ls --updates → " + std::to_string(results.size())
+ " mise(s) à jour disponible(s)");
return results;
}
bool FlatpakManager::isInstalled(const std::string& appId) {
@@ -637,6 +655,7 @@ bool FlatpakManager::install(const std::string& packageName,
// as installed without re-running the installer, then made sure it appears
// in the desktop launcher (covers apps installed before this feature).
if (isInstalled(packageName)) {
trace("déjà installé : " + packageName + " — aucune installation lancée");
if (progressCallback) progressCallback(packageName + " est déjà installé.", -1);
integrateDesktopEntries(packageName);
return true;
@@ -656,6 +675,7 @@ bool FlatpakManager::install(const std::string& packageName,
// 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");
trace("remote flathub vérifié (--user, --if-not-exists)");
std::string output = tryInstall("");
@@ -674,6 +694,8 @@ bool FlatpakManager::install(const std::string& packageName,
// repeating a doomed attempt.
if (output.find("error:") != std::string::npos && !isInstalled(packageName)
&& (noRefs() || ambiguous())) {
trace(ambiguous() ? "dépôts multiples : passage en --user flathub"
: "références distantes obsolètes : actualisation d'appstream");
if (progressCallback) progressCallback("Mise à jour des métadonnées des dépôts...", -1);
runFlatpak("flatpak update --appstream 2>&1", progressCallback);
output = tryInstall(ambiguous() ? "--user flathub" : "");
@@ -681,6 +703,7 @@ bool FlatpakManager::install(const std::string& packageName,
// Remaining failures get one per-user attempt (no polkit, no ambiguity).
if (output.find("error:") != std::string::npos && !isInstalled(packageName)) {
trace("échec en système : nouvel essai en installation utilisateur (flathub)");
if (progressCallback) progressCallback("Nouvel essai en mode utilisateur...", -1);
output = tryInstall("--user flathub");
}
@@ -688,6 +711,7 @@ bool FlatpakManager::install(const std::string& packageName,
// The authoritative success check is `flatpak info`; the output may carry
// noise such as "already installed" that must not count as a failure.
if (!isInstalled(packageName)) {
trace("échec : `flatpak info " + packageName + "` ne trouve rien après les essais");
m_lastError = lastOutputLines(output);
return false;
}
@@ -768,9 +792,12 @@ void FlatpakManager::uninstallDesktopEntries(const std::string& appId) {
}
void FlatpakManager::integrateAllInstalled() {
for (const auto& pkg : listInstalled()) {
const std::vector<PackageInfo> installed = listInstalled();
for (const auto& pkg : installed) {
integrateDesktopEntries(pkg.name);
}
trace("intégration du lanceur : " + std::to_string(installed.size())
+ " application(s) re-liée(s)");
}
bool FlatpakManager::remove(const std::string& packageName,
@@ -810,6 +837,8 @@ bool FlatpakManager::remove(const std::string& packageName,
m_lastError = lastOutputLines(output);
return false;
}
trace("appel ambigu pour " + appId + " : " + std::to_string(targets.size())
+ " copie(s) à supprimer une par une");
}
bool success = true;
@@ -854,6 +883,8 @@ bool FlatpakManager::update(const std::string& packageName,
m_lastError = lastOutputLines(output);
return false;
}
trace("appel ambigu pour " + packageName + " : "
+ std::to_string(targets.size()) + " copie(s) mise(s) à jour");
bool success = true;
for (const std::string& target : targets) {
const std::string copy = runFlatpak(updateCommand(target), progressCallback);
@@ -867,6 +898,7 @@ bool FlatpakManager::update(const std::string& packageName,
// System-wide updates need polkit: fall back to the per-user installation.
if (output.find("error:") != std::string::npos) {
trace("échec en système (polkit ?) : nouvel essai en installation utilisateur");
if (progressCallback) progressCallback("Nouvel essai en mode utilisateur...", -1);
output = tryUpdate("--user");
}
@@ -888,6 +920,7 @@ bool FlatpakManager::refresh(ProgressCallback progressCallback) {
// System remotes need polkit for that: fall back to the user installation.
if (output.find("error:") != std::string::npos) {
trace("appstream système refusé (polkit ?) : nouvel essai en --user");
exec("flatpak remote-add --if-not-exists --user flathub "
"https://flathub.org/repo/flathub.flatpakrepo 2>&1");
output = runFlatpak("flatpak update --appstream --user 2>&1", progressCallback);
@@ -934,6 +967,7 @@ bool FlatpakManager::installFile(const std::string& path,
// Registering a repository is the whole job, and the per-user scope avoids
// polkit on a machine where the user is not an administrator.
if (kind == FileKind::Repo) {
trace("fichier .flatpakrepo : enregistrement du dépôt " + repoNamespace(path));
if (progressCallback) {
progressCallback("Ajout du dépôt " + repoNamespace(path) + "...", -1);
}
@@ -958,6 +992,7 @@ bool FlatpakManager::installFile(const std::string& path,
// A system-wide install needs polkit: fall back to the per-user one, exactly
// like a name-based install does.
if (output.find("error:") != std::string::npos) {
trace("fichier " + path + " : échec en système, nouvel essai en utilisateur");
if (progressCallback) progressCallback("Nouvel essai en mode utilisateur...", -1);
output = runFlatpak(installFileCommand(kind, path, /*userScope=*/true), progressCallback);
}
@@ -974,8 +1009,11 @@ bool FlatpakManager::installFile(const std::string& path,
// invisible in the desktop menu.
const std::set<std::string> appIds = appIdsInOutput(output);
if (appIds.empty()) {
trace("aucun identifiant lisible dans la sortie : ré-intégration de tout");
integrateAllInstalled();
} else {
trace("intégration du lanceur : " + std::to_string(appIds.size())
+ " application(s) issue(s) du fichier");
for (const auto& appId : appIds) integrateDesktopEntries(appId);
}
return true;