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

+1
View File
@@ -72,6 +72,7 @@ set(HEADERS
preferences/language-manager.h
core/workers.h
include/sdk/progress-tracker.h
include/sdk/provider-trace.h
archive/zip-archive.h
plugins/plugin-package.h
core/app-core.h
+2 -22
View File
@@ -908,25 +908,8 @@ void MainWindow::setupShortcuts() {
// ---------------------------------------------------------------------------
void MainWindow::onNavChanged(int id) {
qCDebug(pacmgrUi) << "navigate to page" << id;
QString pageName;
switch (id) {
case NavDashboard: pageName = tr("tableau de bord"); break;
case NavSearch: pageName = tr("recherche"); break;
case NavInstalled: pageName = tr("installés"); break;
case NavUpdates: pageName = tr("mises à jour"); break;
case NavCleanup: pageName = tr("nettoyage"); break;
case NavHistory: pageName = tr("historique"); break;
case NavLogs: pageName = tr("logs"); break;
case NavPlugins: pageName = tr("plugins"); break;
default: break;
}
LogManager::instance().logEvent(
QStringLiteral("ui"),
pageName.isEmpty() ? tr("navigation → page %1").arg(id)
: tr("navigation → %1").arg(pageName));
// Navigating is not something the journal narrates: changing screen is not
// an operation, and a line per click buries the ones that are.
switch (id) {
case NavDashboard:
m_pages->setCurrentWidget(m_dashboard);
@@ -984,9 +967,6 @@ void MainWindow::onOpenPage(const QString& pageId) {
// ways in. Everything a navigation button does for free — switching the stacked
// widget, reloading, retitling, journalling — is done here instead.
void MainWindow::openSettingsPage() {
LogManager::instance().logEvent(QStringLiteral("ui"),
tr("navigation → paramètres"));
// Nothing stays selected in the sidebar: the settings screen is not one of
// the places it lists, and leaving the previous entry highlighted would
// point at the wrong screen. The group has to stop being exclusive first,
+17 -9
View File
@@ -15,6 +15,7 @@
#include "app-logging.h"
#include "log-manager.h"
#include "plugin-package.h"
#include "provider-trace.h"
#include "workers.h"
namespace {
@@ -98,6 +99,17 @@ AppCore::AppCore(QObject* parent) : QObject(parent) {
qRegisterMetaType<std::vector<PackageInfo>>("std::vector<PackageInfo>");
qRegisterMetaType<AppCore::ListMode>("AppCore::ListMode");
// Provider narration — the exact commands run and the decisions around
// them — goes to the journal and nowhere else: it is detail to read after
// the fact, not something to flash in the status bar while an operation
// runs. Providers reach it through a Qt-free sink so they keep building
// into the headless tests.
provider_trace::setSink(
[](const std::string& source, const std::string& message) {
LogManager::instance().logEvent(QString::fromStdString(source),
QString::fromStdString(message));
});
// Plugin registry: pacman is compiled in; every other plugin (Flatpak,
// AUR, ...) ships as an external shared library loaded at runtime from the
// plugins/ directories.
@@ -798,15 +810,11 @@ AppCore::StartResult AppCore::startAction(InstallWorker* worker, const Request&
qCInfo(pacmgrOp) << request.action << QString::fromStdString(request.package.name);
// Journal header: what is about to run, so the raw output that follows reads
// like a hand-run command. A file install logs the file it acted on.
const QString target = request.path.isEmpty()
? QString::fromStdString(request.package.name)
: request.path;
LogManager::instance().beginCommand(
providerLabel(providers), request.action,
target.isEmpty() ? QString()
: QStringLiteral("%1 %2").arg(request.action, target));
// Journal header: which provider(s) and action, so the raw output that
// follows reads like a hand-run session. No synthesized command line here:
// `request.action target` is not what actually runs — the provider reports
// its real command line right after the header, through the trace sink.
LogManager::instance().beginCommand(providerLabel(providers), request.action);
connect(worker, &InstallWorker::progress, this,
[this](const QString& message) {
+45
View File
@@ -0,0 +1,45 @@
#pragma once
#include <functional>
#include <string>
#include <utility>
// Operator-level trace for package-manager work: the exact command a provider
// runs, the decisions it takes around it (a fallback to the user installation,
// a skipped step, a detected lock) and what it found.
//
// This is deliberately separate from ProgressCallback. Progress is what the
// user watches in the status bar while an operation runs, so it stays short;
// a trace is detail to read after the fact, so it lives in the journal, where
// being verbose costs nothing. Both reach the same file, but only progress
// flashes on screen.
//
// The host installs one sink for the whole process; providers call report()
// and stay Qt-free so they keep building into the headless unit tests. With no
// sink installed — every test binary — report() is a no-op.
namespace provider_trace {
// Receives (source, message): `source` is the provider id shown between
// brackets in the journal ("pacman", "flatpak"), `message` is one line.
using Sink = std::function<void(const std::string& source, const std::string& message)>;
// The one sink the process shares. A function-local static, so it is created on
// first use whatever order the providers and the host start in.
inline Sink& sink() {
static Sink instance;
return instance;
}
// Installs the sink, or clears it when given an empty function.
inline void setSink(Sink replacement) { sink() = std::move(replacement); }
// Reports one line of trace. A no-op when no sink is installed. Named
// `report` rather than `emit`: Qt defines `emit` as a macro, which would
// silently swallow the name in every translation unit that includes a Qt
// header.
inline void report(const std::string& source, const std::string& message) {
if (message.empty()) return;
if (sink()) sink()(source, message);
}
} // namespace provider_trace
+6 -4
View File
@@ -23,11 +23,13 @@
// [2026-09-23 14:22:10] ⟶ terminé
//
// - an *event* is a one-line note about something that is not a shelled
// command: navigation, a search, a plugin toggle, a network fetch, a refused
// request...
// command: a search, a plugin toggle, a network fetch, a refused request...
// Screens deliberately do not narrate navigation: a line per click buries
// the ones that matter.
//
// [2026-09-23 14:22:02] [ui] navigation → recherche
// [2026-09-23 14:22:03] [recherche] "firefox" → 12 résultat(s)
// [2026-09-23 14:22:02] [recherche] "firefox" → 12 résultat(s)
// [2026-09-23 14:22:03] [pacman] $ sudo pacman -S --noconfirm firefox
// [2026-09-23 14:22:03] [flatpak] $ flatpak update --appstream
//
// Every Qt log message (qCDebug/qCInfo/qCWarning/qCCritical) is funnelled into
// the same journal by installQtMessageHandler(), so the categories already used
+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;
+43 -5
View File
@@ -1,6 +1,7 @@
#include "pacman-manager.h"
#include "progress-tracker.h"
#include "provider-trace.h"
#include <array>
#include <cctype>
@@ -43,6 +44,13 @@ static std::string shellQuote(const std::string& s) {
return out;
}
// One line of operator trace: the exact command run, a query served from cache,
// 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("pacman", message);
}
// Keep only the last few lines of a command output for error dialogs, so a
// failure shows the real cause without dumping pages of progress lines.
static std::string lastOutputLines(const std::string& output, int keep = 5) {
@@ -75,6 +83,9 @@ static std::string lastOutputLines(const std::string& output, int keep = 5) {
static std::string execPrivileged(const std::string& pacmanCmd,
const std::string& password,
ProgressCallback progressCallback) {
// The journal gets the command as the user would type it. The password is
// piped to sudo on stdin and must never reach the trace.
trace("$ sudo " + pacmanCmd);
const std::string full = "printf '%s\\n' " + shellQuote(password)
+ " | sudo -S " + pacmanCmd + " 2>&1";
return runWithProgress(full, progressCallback);
@@ -106,10 +117,20 @@ static constexpr std::chrono::seconds kQueryTtl{10};
std::string PacmanManager::cachedQuery(PacmanManager::CachedQuery& slot,
const char* command) {
const auto now = std::chrono::steady_clock::now();
bool fromCache = false;
{
std::lock_guard<std::mutex> lock(m_queryMutex);
if (slot.valid && now - slot.fetched < kQueryTtl) return slot.output;
fromCache = slot.valid && now - slot.fetched < kQueryTtl;
}
if (fromCache) {
// Reused for a few seconds: saying so explains why a page opened
// without spawning pacman at all.
trace(std::string("cache · ") + command);
std::lock_guard<std::mutex> lock(m_queryMutex);
return slot.output;
}
trace(std::string("$ ") + command);
// Queried outside the lock: a second thread asking for the same query then
// just runs it too, which is cheaper than serialising the whole app on
@@ -180,7 +201,9 @@ std::vector<PackageInfo> PacmanManager::search(const std::string& query) {
results.back().description = desc;
}
}
trace("pacman -Ss " + query + " → " + std::to_string(results.size())
+ " résultat(s)");
return results;
}
@@ -291,6 +314,8 @@ std::vector<PackageInfo> PacmanManager::listInstalled() {
}
}
trace("pacman -Q / -Qi / -Sl → " + std::to_string(packages.size())
+ " paquet(s) installé(s), taille et dépôt inclus");
return packages;
}
@@ -322,7 +347,11 @@ std::vector<PackageInfo> PacmanManager::listUpdates() {
// Cached like the other read-only queries: the dashboard badge, the updates
// screen and the "Tout mettre à jour" button all ask for it within the same
// second, and one pacman process answers for all of them.
return parseUpdatesOutput(cachedQuery(m_updatesQuery, "pacman -Qu 2>&1"));
std::vector<PackageInfo> results =
parseUpdatesOutput(cachedQuery(m_updatesQuery, "pacman -Qu 2>&1"));
trace("pacman -Qu → " + std::to_string(results.size())
+ " mise(s) à jour disponible(s)");
return results;
}
// Orphans (-Qdt: no installed package requires them) and legacy packages (-Qm:
@@ -330,8 +359,15 @@ std::vector<PackageInfo> PacmanManager::listUpdates() {
std::vector<PackageInfo> PacmanManager::listCleanupCandidates() {
// `pacman -Qdt` warns on stderr when the system has no orphan at all: only
// stdout is parsed, so the warning never reaches the candidate list.
return parseCleanupOutput(exec("pacman -Qdt 2>/dev/null"),
exec("pacman -Qm 2>/dev/null"));
std::vector<PackageInfo> results = parseCleanupOutput(exec("pacman -Qdt 2>/dev/null"),
exec("pacman -Qm 2>/dev/null"));
int orphans = 0;
for (const auto& pkg : results) {
if (pkg.orphan) ++orphans;
}
trace("pacman -Qdt / -Qm → " + std::to_string(orphans) + " orphelin(s) et "
+ std::to_string(results.size() - orphans) + " paquet(s) legacy");
return results;
}
bool PacmanManager::removePackages(const std::vector<std::string>& packages,
@@ -760,6 +796,7 @@ bool PacmanManager::releaseDatabaseLock(const LockHolder& holder,
if (holder.pid > 0) {
const std::string who = describeLockHolder(holder);
trace("db.lck détenu par " + who + " : envoi de SIGTERM");
if (progressCallback) progressCallback("Arrêt de " + who + "...", -1);
if (!terminateProcess(holder.pid, "TERM")) {
@@ -781,6 +818,7 @@ bool PacmanManager::releaseDatabaseLock(const LockHolder& holder,
// No process left to stop (or it would not die): the lock file itself is
// what keeps the database closed.
trace("aucun processus à arrêter : suppression du fichier de verrou résiduel");
if (progressCallback) progressCallback("Suppression du verrou résiduel...", -1);
if (removeLockFile()) return true;
-3
View File
@@ -367,9 +367,6 @@
"mode d'identifiants → %1": "credential mode → %1",
"mot de passe fourni": "password provided",
"mot de passe refusé par l'utilisateur": "password refused by the user",
"navigation → %1": "navigation → %1",
"navigation → page %1": "navigation → page %1",
"navigation → paramètres": "navigation → settings",
"nettoyage": "cleanup",
"ouverture des détails de %1": "opening the details of %1",
"pacman est indisponible sur ce système.": "pacman is not available on this system.",