feat(flatpak): report the download flatpak never announces

Installing a .flatpakref looked frozen: flatpak prints two lines and
then stays silent for the minutes a runtime takes to come down, so the
window repeated the same sentence over a stalled bar and the journal
recorded nothing at all.

It has no meter to print — measured here, on a real 658 MB install, it
draws nothing on a pipe nor on a full terminal, only on the deltas the
CDN happens to serve — so the provider now measures the transfer itself:
the bytes landing in flatpak's own staging directory, reported as they
grow. When even those stop, the window takes over and says which step is
running and for how long, in the status bar and in the journal.

Along the way the runner reads with read() instead of stdio so in-place
updates are not held back by a buffer, strips the ANSI escapes some
tools colour their output with (the AUR plugin's own copy is gone), and
turns a rewritten meter line into a journal entry every 10 %.
This commit is contained in:
BlackAngelTV committed 2026-09-27 21:33:41 +02:00
1 parent 7c46023489
commit f1fbd3cd8a
11 files changed
+529 -63

No files matched your search

+67
View File
@@ -41,6 +41,21 @@
#include "page.h"
#include "plugins-page.h"
// How long a wait reads best in the status bar: "45 s", "2 min 05", "1 h 03".
static QString formatElapsed(qint64 ms) {
const qint64 seconds = ms / 1000;
const qint64 minutes = seconds / 60;
if (minutes >= 60) {
return QStringLiteral("%1 h %2").arg(minutes / 60)
.arg(minutes % 60, 2, 10, QLatin1Char('0'));
}
if (minutes > 0) {
return QStringLiteral("%1 min %2").arg(minutes)
.arg(seconds % 60, 2, 10, QLatin1Char('0'));
}
return QStringLiteral("%1 s").arg(seconds);
}
// Load one of the embedded SVG icons (see resources/resources.qrc).
static QIcon loadIcon(const QString& name) {
return QIcon(QString(":/icons/%1.svg").arg(name));
@@ -440,6 +455,12 @@ void MainWindow::setupUI() {
m_installProgressBar->setVisible(false);
statusBar()->addPermanentWidget(m_installProgressBar);
// Watchdog of the running operation: it is what tells a two-minute download
// from a frozen app (see onActivityTick).
m_activityTimer = new QTimer(this);
m_activityTimer->setInterval(1000);
connect(m_activityTimer, &QTimer::timeout, this, &MainWindow::onActivityTick);
setStyleSheet(appStyleSheet());
}
@@ -1204,6 +1225,7 @@ void MainWindow::onCoreListFinished(AppCore::ListMode mode,
void MainWindow::onCoreActionProgress(const QString& message, int percent) {
if (!message.isEmpty()) statusBar()->showMessage(message);
noteOperationOutput(message);
if (percent < 0) return;
// A provider running several commands (or a second provider after the
@@ -1249,6 +1271,17 @@ void MainWindow::onCoreBusyChanged(bool busy) {
// operation and must not touch the new one.
++m_progressGeneration;
if (busy) {
m_operationClock.start();
m_operationStep.clear();
m_lastOutputAtMs = 0;
m_lastWaitNoteMs = 0;
m_activityTimer->start();
} else {
m_activityTimer->stop();
m_operationClock.invalidate();
}
if (!busy) {
if (m_installProgressBar->isVisible() && m_installProgressBar->maximum() > 0) {
// Real progress was shown: complete it and let it be seen. A bar
@@ -1279,6 +1312,40 @@ void MainWindow::onCoreBusyChanged(bool busy) {
void MainWindow::onCoreStatusMessage(const QString& message) {
statusBar()->showMessage(message);
noteOperationOutput(message);
}
void MainWindow::noteOperationOutput(const QString& step) {
if (!step.isEmpty()) m_operationStep = step;
if (m_operationClock.isValid()) m_lastOutputAtMs = m_operationClock.elapsed();
}
// A long operation is not always a talkative one: flatpak prints nothing while
// a 1 Go runtime downloads, which left the window repeating the same sentence
// over a frozen bar. After a few seconds of silence the elapsed time joins the
// status bar, and every half-minute of waiting the journal says so too — the
// Logs screen then shows the operation is alive instead of stopped.
void MainWindow::onActivityTick() {
if (!m_operationClock.isValid()) return;
// Five seconds of silence is a download; anything shorter is just a tool
// thinking, and rewriting the message then would only make it flicker.
constexpr qint64 kSilenceBeforeNotice = 5000;
constexpr qint64 kWaitNoteInterval = 30000;
const qint64 elapsed = m_operationClock.elapsed();
if (elapsed - m_lastOutputAtMs < kSilenceBeforeNotice) return;
const QString elapsedText = formatElapsed(elapsed);
const QString step = m_operationStep.isEmpty() ? QStringLiteral("en cours")
: m_operationStep;
statusBar()->showMessage(QStringLiteral("%1 — %2").arg(step, elapsedText));
if (elapsed - m_lastWaitNoteMs < kWaitNoteInterval) return;
m_lastWaitNoteMs = elapsed;
LogManager::instance().logEvent(
QStringLiteral("opération"),
QStringLiteral("toujours en cours après %1 — %2").arg(elapsedText, step));
}
void MainWindow::onCoreHistoryChanged() {