From 3719ac405fa65adcd3cae19dcb7c6f7025ce4ad0 Mon Sep 17 00:00:00 2001 From: araidz Date: Tue, 21 Jul 2026 21:25:22 +0400 Subject: [PATCH] Clamp download progress to 100% Progress.fractionCompleted can exceed 1.0 when the server delivers more bytes than the expected Content-Length (e.g. resumed downloads), causing the activity view to display values like "103.00% completed". Clamp currentValue at the source so every consumer (progress bar, percentage text, byte count) stays capped at 100%. Fixes #222 --- Mist/Helpers/DownloadManager.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Mist/Helpers/DownloadManager.swift b/Mist/Helpers/DownloadManager.swift index 18e3331..90ff0dd 100644 --- a/Mist/Helpers/DownloadManager.swift +++ b/Mist/Helpers/DownloadManager.swift @@ -12,7 +12,9 @@ class DownloadManager: NSObject, ObservableObject { private var task: URLSessionDownloadTask? private var progress: Progress = .init() var currentValue: Double { - progress.fractionCompleted + // ponytail: clamp to 1.0 - Progress.fractionCompleted can exceed 1.0 when the + // server sends more bytes than the expected Content-Length (e.g. resumed downloads) + min(progress.fractionCompleted, 1) } // swiftlint:disable:next cyclomatic_complexity function_body_length