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:
1 parent
ed58e87520
commit
b26e907221
12 files changed
+590
-138
No files matched your search
+53
-14
@@ -222,8 +222,12 @@ static QString appStyleSheet() {
|
||||
" color: #e2e8f0;"
|
||||
"}"
|
||||
// ---- Progress bar ----
|
||||
"QProgressBar { background: #273449; border: none; border-radius: 3px; }"
|
||||
"QProgressBar::chunk { background: #38bdf8; border-radius: 3px; }"
|
||||
// The value is spelled out beside the bar rather than inside it: the
|
||||
// label Qt centres on the bar would sit half on the fill and half on
|
||||
// the track, where no single colour stays readable.
|
||||
"QLabel#progressLabel { color: #7dd3fc; font-size: 11px; font-weight: 700; padding-right: 8px; }"
|
||||
"QProgressBar { background: #273449; border: none; border-radius: 4px; }"
|
||||
"QProgressBar::chunk { background: #38bdf8; border-radius: 4px; }"
|
||||
// ---- Package table ----
|
||||
// No outer frame: the table blends with the card it sits in, keeping
|
||||
// only the column header and alternating rows as visual separators.
|
||||
@@ -408,14 +412,20 @@ void MainWindow::setupUI() {
|
||||
|
||||
statusBar()->showMessage("Prêt");
|
||||
|
||||
// Tiny indeterminate bar anchored at the bottom of the window: it appears
|
||||
// while install/update/remove/search operations run, without taking space
|
||||
// on the screens.
|
||||
// Progress of the running operation, anchored at the bottom of the window
|
||||
// so it takes no space on the screens. It appears while install/update/
|
||||
// remove/search operations run: indeterminate at first, then filled to the
|
||||
// real percentage reported by the provider (see onCoreActionProgress).
|
||||
m_progressLabel = new QLabel();
|
||||
m_progressLabel->setObjectName("progressLabel");
|
||||
m_progressLabel->setVisible(false);
|
||||
statusBar()->addPermanentWidget(m_progressLabel);
|
||||
|
||||
m_installProgressBar = new QProgressBar();
|
||||
m_installProgressBar->setRange(0, 0);
|
||||
m_installProgressBar->setTextVisible(false);
|
||||
m_installProgressBar->setFixedHeight(4);
|
||||
m_installProgressBar->setFixedWidth(120);
|
||||
m_installProgressBar->setFixedHeight(8);
|
||||
m_installProgressBar->setFixedWidth(160);
|
||||
m_installProgressBar->setVisible(false);
|
||||
statusBar()->addPermanentWidget(m_installProgressBar);
|
||||
|
||||
@@ -1011,11 +1021,17 @@ void MainWindow::onCoreActionProgress(const QString& message, int percent) {
|
||||
if (!message.isEmpty()) statusBar()->showMessage(message);
|
||||
if (percent < 0) return;
|
||||
|
||||
// A real download percentage reported by the provider fills the bottom bar
|
||||
// as a determinate progress.
|
||||
// A provider running several commands (or a second provider after the
|
||||
// first) starts its own count at 0: within one operation the bar only ever
|
||||
// moves forward, so a retry or a second command never sends it backwards.
|
||||
if (percent > m_progressValue) m_progressValue = percent;
|
||||
|
||||
m_installProgressBar->setVisible(true);
|
||||
m_installProgressBar->setRange(0, 100);
|
||||
m_installProgressBar->setValue(percent);
|
||||
m_installProgressBar->setValue(m_progressValue);
|
||||
|
||||
m_progressLabel->setText(QString("%1 %").arg(m_progressValue));
|
||||
m_progressLabel->setVisible(true);
|
||||
}
|
||||
|
||||
void MainWindow::onCoreActionFinished(const QString& action, const QString& name,
|
||||
@@ -1036,13 +1052,36 @@ void MainWindow::onCoreActionFinished(const QString& action, const QString& name
|
||||
}
|
||||
|
||||
void MainWindow::onCoreBusyChanged(bool busy) {
|
||||
m_installProgressBar->setVisible(busy);
|
||||
if (!busy) return;
|
||||
// Any pending "hide the finished bar" timer belongs to the previous
|
||||
// operation and must not touch the new one.
|
||||
++m_progressGeneration;
|
||||
|
||||
// Start indeterminate; a real percentage (onCoreActionProgress) switches the
|
||||
// bar to a determinate fill once the tool reports progress.
|
||||
if (!busy) {
|
||||
if (m_installProgressBar->isVisible() && m_installProgressBar->maximum() > 0) {
|
||||
// Real progress was shown: complete it and let it be seen. A bar
|
||||
// that disappears at 97 % looks like a failure.
|
||||
m_installProgressBar->setValue(100);
|
||||
m_progressLabel->setText(QStringLiteral("100 %"));
|
||||
const int generation = m_progressGeneration;
|
||||
QTimer::singleShot(500, this, [this, generation] {
|
||||
if (generation != m_progressGeneration) return;
|
||||
m_installProgressBar->setVisible(false);
|
||||
m_progressLabel->setVisible(false);
|
||||
});
|
||||
return;
|
||||
}
|
||||
m_installProgressBar->setVisible(false);
|
||||
m_progressLabel->setVisible(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Start indeterminate; the first real percentage (onCoreActionProgress)
|
||||
// switches the bar to a determinate fill.
|
||||
m_progressValue = 0;
|
||||
m_installProgressBar->setRange(0, 0);
|
||||
m_installProgressBar->setValue(0);
|
||||
m_installProgressBar->setVisible(true);
|
||||
m_progressLabel->setVisible(false);
|
||||
}
|
||||
|
||||
void MainWindow::onCoreStatusMessage(const QString& message) {
|
||||
|
||||
Reference in new issue
Block a user