perf(progress): report real progress instead of a bouncing bar

pacman restarts its "(1/24)" counter at every phase of a transaction, so the
bar was fed 0 percent, 100 percent, 0 percent again a few times per update —
and Flatpak/AUR buffered their whole output, which left it indeterminate for
the entire run. A shared ProgressTracker now folds every counter, file
percentage and package step into one value that only moves forward, the
providers stream their output as it is produced, and each provider owns a
slice of the bar so a multi-provider update keeps advancing. pacman -Qu is
cached like the other read queries, so the sidebar badge, the updates screen
and the update button share a single process.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
BlackAngelTV committed 2026-09-16 22:40:39 +02:00
1 parent ed58e87520
commit b26e907221
12 files changed
+590 -138

No files matched your search

+13 -20
View File
@@ -1,4 +1,7 @@
#include "aur-manager.h"
#include "progress-tracker.h"
#include <array>
#include <memory>
#include <stdexcept>
@@ -18,17 +21,6 @@ static std::string exec(const char* cmd) {
return result;
}
// Stream command output lines to the progress callback (text-only,
// percent = -1 keeps the UI bar indeterminate).
static void streamOutput(const std::string& output, ProgressCallback cb) {
if (!cb) return;
std::istringstream iss(output);
std::string line;
while (std::getline(iss, line)) {
if (!line.empty()) cb(line, -1);
}
}
// Keep the tail of a command's output so the user sees the real failure.
static std::string lastOutputLines(const std::string& output, int maxLines = 4) {
std::istringstream iss(output);
@@ -166,9 +158,11 @@ bool AurManager::install(const std::string& packageName,
return false;
}
if (progressCallback) progressCallback("Installation AUR de " + packageName + "...", -1);
// Helpers handle sudo themselves; run so the prompt reaches the user.
std::string output = exec((h + " -S --noconfirm " + packageName + " 2>&1").c_str());
streamOutput(output, progressCallback);
// Helpers handle sudo themselves; run so the prompt reaches the user. The
// output is streamed: the helpers build with makepkg and then hand over to
// pacman, and both report progress as they go.
std::string output = runWithProgress(
h + " -S --noconfirm " + packageName + " 2>&1", progressCallback);
if (system((h + " -Q " + packageName + " > /dev/null 2>&1").c_str()) != 0) {
m_lastError = lastOutputLines(output);
return false;
@@ -185,8 +179,8 @@ bool AurManager::remove(const std::string& packageName,
return false;
}
if (progressCallback) progressCallback("Suppression de " + packageName + "...", -1);
std::string output = exec((h + " -R --noconfirm " + packageName + " 2>&1").c_str());
streamOutput(output, progressCallback);
std::string output = runWithProgress(
h + " -R --noconfirm " + packageName + " 2>&1", progressCallback);
if (system((h + " -Q " + packageName + " > /dev/null 2>&1").c_str()) == 0) {
m_lastError = lastOutputLines(output);
return false;
@@ -204,8 +198,8 @@ bool AurManager::update(const std::string& packageName,
}
std::string target = packageName.empty() ? "--aur" : packageName;
if (progressCallback) progressCallback("Mise a jour AUR...", -1);
std::string output = exec((h + " -Syu --noconfirm " + target + " 2>&1").c_str());
streamOutput(output, progressCallback);
std::string output = runWithProgress(
h + " -Syu --noconfirm " + target + " 2>&1", progressCallback);
if (output.find("error:") != std::string::npos
|| output.find("erreur") != std::string::npos) {
m_lastError = lastOutputLines(output);
@@ -222,8 +216,7 @@ bool AurManager::refresh(ProgressCallback progressCallback) {
return false;
}
if (progressCallback) progressCallback("Rafraichissement AUR...", -1);
std::string output = exec((h + " -Sy 2>&1").c_str());
streamOutput(output, progressCallback);
std::string output = runWithProgress(h + " -Sy 2>&1", progressCallback);
if (output.find("error:") != std::string::npos
|| output.find("erreur") != std::string::npos) {
m_lastError = lastOutputLines(output);
+19 -32
View File
@@ -1,4 +1,7 @@
#include "flatpak-manager.h"
#include "progress-tracker.h"
#include <array>
#include <memory>
#include <stdexcept>
@@ -41,18 +44,6 @@ static std::string exec(const char* cmd) {
return result;
}
// Stream the lines of a command's output to the progress callback, if any.
// flatpak exposes no simple percentage, so progress is reported text-only
// (percent = -1 keeps the UI bar indeterminate).
static void streamOutput(const std::string& output, ProgressCallback progressCallback) {
if (!progressCallback) return;
std::istringstream iss(output);
std::string line;
while (std::getline(iss, line)) {
if (!line.empty()) progressCallback(line, -1);
}
}
// A flatpak application ID is a dotted identifier with at least two dots whose
// segments start with an alphanumeric character (e.g. org.mozilla.firefox).
// This deliberately rejects version strings such as "128.0.2".
@@ -255,9 +246,12 @@ bool FlatpakManager::install(const std::string& packageName,
if (progressCallback) progressCallback("Installation de " + packageName + "...", -1);
// Installs stream their output: flatpak reports "Installing 1/3…" and the
// percentage of the file it is unpacking, which drives the UI progress bar.
auto tryInstall = [&](const std::string& extra) {
return exec(("flatpak install --noninteractive --assumeyes " + extra + " "
+ packageName + " 2>&1").c_str());
return runWithProgress("flatpak install --noninteractive --assumeyes " + extra
+ " " + packageName + " 2>&1",
progressCallback);
};
// A fresh flatpak setup has no remote configured: add the default flathub
@@ -283,7 +277,7 @@ bool FlatpakManager::install(const std::string& packageName,
if (output.find("error:") != std::string::npos && !isInstalled(packageName)
&& (noRefs() || ambiguous())) {
if (progressCallback) progressCallback("Mise à jour des métadonnées des dépôts...", -1);
exec("flatpak update --appstream 2>&1");
runWithProgress("flatpak update --appstream 2>&1", progressCallback);
output = tryInstall(ambiguous() ? "--user flathub" : "");
}
@@ -293,8 +287,6 @@ bool FlatpakManager::install(const std::string& packageName,
output = tryInstall("--user flathub");
}
streamOutput(output, progressCallback);
// 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)) {
@@ -388,9 +380,9 @@ bool FlatpakManager::remove(const std::string& packageName,
m_lastError.clear();
if (progressCallback) progressCallback("Suppression de " + packageName + "...", -1);
std::string output = exec(
("flatpak uninstall --noninteractive --assumeyes " + packageName + " 2>&1").c_str());
streamOutput(output, progressCallback);
std::string output = runWithProgress(
"flatpak uninstall --noninteractive --assumeyes " + packageName + " 2>&1",
progressCallback);
if (output.find("error:") != std::string::npos || isInstalled(packageName)) {
m_lastError = lastOutputLines(output);
@@ -406,11 +398,9 @@ bool FlatpakManager::update(const std::string& packageName,
ProgressCallback progressCallback) {
m_lastError.clear();
auto tryUpdate = [&](const std::string& extra) {
if (packageName.empty()) {
return exec(("flatpak update --noninteractive --assumeyes " + extra + " 2>&1").c_str());
}
return exec(("flatpak update --noninteractive --assumeyes " + extra + " "
+ packageName + " 2>&1").c_str());
std::string command = "flatpak update --noninteractive --assumeyes " + extra;
if (!packageName.empty()) command += " " + packageName;
return runWithProgress(command + " 2>&1", progressCallback);
};
if (packageName.empty()) {
@@ -425,7 +415,6 @@ bool FlatpakManager::update(const std::string& packageName,
if (progressCallback) progressCallback("Nouvel essai en mode utilisateur...", -1);
output = tryUpdate("--user");
}
streamOutput(output, progressCallback);
if (output.find("error:") != std::string::npos) {
m_lastError = lastOutputLines(output);
@@ -440,15 +429,14 @@ bool FlatpakManager::refresh(ProgressCallback progressCallback) {
// Re-download the appstream metadata of every remote so search and
// update detection reflect the latest published versions.
std::string output = exec("flatpak update --appstream 2>&1");
std::string output = runWithProgress("flatpak update --appstream 2>&1", progressCallback);
// System remotes need polkit for that: fall back to the user installation.
if (output.find("error:") != std::string::npos) {
exec("flatpak remote-add --if-not-exists --user flathub "
"https://flathub.org/repo/flathub.flatpakrepo 2>&1");
output = exec("flatpak update --appstream --user 2>&1");
output = runWithProgress("flatpak update --appstream --user 2>&1", progressCallback);
}
streamOutput(output, progressCallback);
if (output.find("error:") != std::string::npos) {
m_lastError = lastOutputLines(output);
@@ -470,9 +458,8 @@ bool FlatpakManager::cleanCache(ProgressCallback progressCallback) {
// Runtimes left behind by uninstalled applications weigh several hundred
// megabytes each; flatpak only removes those no installed app references.
std::string output = exec(
"flatpak uninstall --unused --noninteractive --assumeyes 2>&1");
streamOutput(output, progressCallback);
std::string output = runWithProgress(
"flatpak uninstall --unused --noninteractive --assumeyes 2>&1", progressCallback);
if (output.find("error:") != std::string::npos) {
m_lastError = lastOutputLines(output);