Skip to content

Clamp download progress to 100%#235

Open
araidz wants to merge 1 commit into
ninxsoft:mainfrom
araidz:fix/download-progress-over-100
Open

Clamp download progress to 100%#235
araidz wants to merge 1 commit into
ninxsoft:mainfrom
araidz:fix/download-progress-over-100

Conversation

@araidz

@araidz araidz commented Jul 21, 2026

Copy link
Copy Markdown

Summary

Fixes #222 ("More than 100%").

Progress.fractionCompleted can exceed 1.0 when the server delivers more bytes than the expected Content-Length (e.g. on resumed downloads). The activity view then renders values like 103.00% completed. SwiftUI's ProgressView clamps the bar internally, but the percentage label and the "X of Y bytes" label read the raw value directly, so they overshoot.

Fix

Clamp currentValue at its single source in DownloadManager so every consumer (progress bar, percentage text, byte count) stays capped at 100%:

var currentValue: Double {
    min(progress.fractionCompleted, 1)
}

Verification

Reproduced the exact scenario with the same Progress API (completed 103 of expected 100 units):

old (buggy):  103.00% completed
new (fixed):  100.00% completed

Valid mid-download values (e.g. 50%) pass through unchanged.

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 ninxsoft#222
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

More than 100%

1 participant