aboutsummaryrefslogtreecommitdiff
path: root/Hotline/Library/NetSocket/FileProgress.swift
diff options
context:
space:
mode:
authorDustin Mierau <dustin@mierau.me>2025-11-11 15:39:02 -0800
committerDustin Mierau <dustin@mierau.me>2025-11-11 15:39:02 -0800
commitf87ff05d17cedf21845abbb8d750759ba725a263 (patch)
tree154feff5eed1b3f7787eeb2f743ffe6602b6cd31 /Hotline/Library/NetSocket/FileProgress.swift
parentcdaff85ac22f45e39ab1f02474beaa7aada9ad9b (diff)
Folder download logic cleanup. Display folder icon on folder download transfers with small icon for the current file. Fix progress for folder downloads.
Diffstat (limited to 'Hotline/Library/NetSocket/FileProgress.swift')
-rw-r--r--Hotline/Library/NetSocket/FileProgress.swift15
1 files changed, 14 insertions, 1 deletions
diff --git a/Hotline/Library/NetSocket/FileProgress.swift b/Hotline/Library/NetSocket/FileProgress.swift
index c2306f3..2064c59 100644
--- a/Hotline/Library/NetSocket/FileProgress.swift
+++ b/Hotline/Library/NetSocket/FileProgress.swift
@@ -12,14 +12,27 @@ public extension NetSocket {
public let sent: Int
/// Total file size (may be nil if unknown)
public let total: Int?
+ /// Size of most recent packet
+ public let now: Int
+ /// Total progress so far (0.0 to 1.0)
+ public let progress: Double
/// Smoothed transfer rate in bytes per second (EMA), if enough samples collected
public let bytesPerSecond: Double?
/// Estimated time remaining (seconds) based on smoothed rate, if available
public let estimatedTimeRemaining: TimeInterval?
- public init(sent: Int, total: Int?, bytesPerSecond: Double? = nil, estimatedTimeRemaining: TimeInterval? = nil) {
+ public init(sent: Int, total: Int?, now: Int = 0, bytesPerSecond: Double? = nil, estimatedTimeRemaining: TimeInterval? = nil) {
self.sent = sent
self.total = total
+ self.now = now
+
+ if let t = total {
+ self.progress = max(0.0, min(1.0, Double(sent) / Double(t)))
+ }
+ else {
+ self.progress = 0.0
+ }
+
self.bytesPerSecond = bytesPerSecond
self.estimatedTimeRemaining = estimatedTimeRemaining
}