smoother progress

This commit is contained in:
Andy Miller
2025-10-17 14:09:56 -06:00
parent 7e73ba9a61
commit 4aedf58f78
3 changed files with 77 additions and 17 deletions

View File

@@ -4612,6 +4612,8 @@ var SafeUpgrade = /*#__PURE__*/function () {
this.statusFailures = 0;
this.statusContext = null;
this.statusIdleCount = 0;
this.currentStage = null;
this.stageEnteredAt = 0;
this.directStatusUrl = this.resolveDirectStatusUrl();
this.preferDirectStatus = !!this.directStatusUrl;
this.registerEvents();
@@ -4680,6 +4682,8 @@ var SafeUpgrade = /*#__PURE__*/function () {
this.preferDirectStatus = !!this.directStatusUrl;
this.statusContext = null;
this.statusIdleCount = 0;
this.currentStage = null;
this.stageEnteredAt = 0;
this.renderLoading();
this.modal.open();
this.fetchPreflight();
@@ -5101,9 +5105,14 @@ var SafeUpgrade = /*#__PURE__*/function () {
return;
}
var stage = data.stage || 'initializing';
if (stage !== this.currentStage) {
this.currentStage = stage;
this.stageEnteredAt = Date.now();
}
var titleResolver = STAGE_TITLES[stage] || STAGE_TITLES.initializing;
var title = titleResolver();
var percent = typeof data.percent === 'number' ? data.percent : null;
var self = this;
var scaledPercent = function scaledPercent() {
if (stage === 'queued') {
return 0;
@@ -5113,15 +5122,15 @@ var SafeUpgrade = /*#__PURE__*/function () {
}
if (stage === 'downloading') {
if (percent !== null) {
return Math.min(60, Math.round(10 + percent * 0.5));
return Math.min(20, Math.max(5, Math.round(percent * 0.2)));
}
return 25;
return 12;
}
if (stage === 'installing') {
return percent !== null ? Math.min(Math.max(percent, 80), 94) : 80;
return self.computeSmoothPercent(20, 90, 28, percent);
}
if (stage === 'finalizing') {
return percent !== null ? Math.min(Math.max(percent, 95), 99) : 95;
return self.computeSmoothPercent(90, 99, 6, percent);
}
if (stage === 'complete') {
return 100;
@@ -5136,7 +5145,8 @@ var SafeUpgrade = /*#__PURE__*/function () {
var statusLine = job && job.status ? "<p class=\"safe-upgrade-status\">".concat(t('SAFE_UPGRADE_JOB_STATUS', 'Status'), ": <strong>").concat(job.status.toUpperCase(), "</strong>").concat(job.error ? " &mdash; ".concat(job.error) : '', "</p>") : '';
var animateBar = stage !== 'complete' && stage !== 'error' && percent !== null;
var barClass = "safe-upgrade-progress-bar".concat(animateBar ? ' is-active' : '');
this.steps.progress.html("\n <div class=\"safe-upgrade-progress\">\n <h3>".concat(title, "</h3>\n <p>").concat(data.message || '', "</p>\n ").concat(statusLine, "\n ").concat(percentLabel ? "<div class=\"".concat(barClass, "\"><span style=\"width:").concat(percent, "%\"></span></div><div class=\"progress-value\">").concat(percentLabel, "</div>") : '', "\n </div>\n "));
var detailMessage = stage === 'error' ? "<p>".concat(data.message || '', "</p>") : data.message && stage !== 'installing' && stage !== 'finalizing' ? "<p>".concat(data.message, "</p>") : '';
this.steps.progress.html("\n <div class=\"safe-upgrade-progress\">\n <h3>".concat(title, "</h3>\n ").concat(detailMessage, "\n ").concat(statusLine, "\n ").concat(percentLabel ? "<div class=\"".concat(barClass, "\"><span style=\"width:").concat(percent, "%\"></span></div><div class=\"progress-value\">").concat(percentLabel, "</div>") : '', "\n </div>\n "));
this.switchStep('progress');
if (stage === 'complete') {
this.renderResult({
@@ -5187,6 +5197,24 @@ var SafeUpgrade = /*#__PURE__*/function () {
_this7.steps[handle].toggleClass('hidden', !isActive);
});
}
}, {
key: "computeSmoothPercent",
value: function computeSmoothPercent(base, target, durationSeconds, actualPercent) {
var span = target - base;
if (span <= 0) {
if (actualPercent !== null && !Number.isNaN(actualPercent)) {
return Math.min(Math.max(actualPercent, base), target);
}
return base;
}
var elapsed = Math.max(0, (Date.now() - this.stageEnteredAt) / 1000);
var ratio = Math.min(1, elapsed / Math.max(durationSeconds, 1));
var smooth = base + ratio * span;
if (actualPercent !== null && !Number.isNaN(actualPercent)) {
smooth = Math.max(smooth, Math.min(actualPercent, target));
}
return Math.min(smooth, target);
}
}, {
key: "stopPolling",
value: function stopPolling() {