diff options
| author | Dustin Mierau <dustin@mierau.me> | 2025-11-11 16:13:47 -0800 |
|---|---|---|
| committer | Dustin Mierau <dustin@mierau.me> | 2025-11-11 16:13:47 -0800 |
| commit | 86560ac84504f2da63c8fb08505857d8827684d4 (patch) | |
| tree | 92fdd4ac23fcd6b0020ab58e1e9da9750a287b98 /Hotline/Models | |
| parent | f87ff05d17cedf21845abbb8d750759ba725a263 (diff) | |
Use linear progress bar for transfers in the Server side bar.
Diffstat (limited to 'Hotline/Models')
| -rw-r--r-- | Hotline/Models/TransferInfo.swift | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/Hotline/Models/TransferInfo.swift b/Hotline/Models/TransferInfo.swift index ebe9f64..cac4b90 100644 --- a/Hotline/Models/TransferInfo.swift +++ b/Hotline/Models/TransferInfo.swift @@ -58,4 +58,47 @@ class TransferInfo: Identifiable, Equatable, Hashable { func hash(into hasher: inout Hasher) { hasher.combine(self.id) } + +// var formatSize(_ bytes: UInt) -> String { +// let formatter = ByteCountFormatter() +// formatter.countStyle = .file +// formatter.allowedUnits = [.useKB, .useMB, .useGB] +// return formatter.string(fromByteCount: Int64(bytes)) +// } + + var displaySize: String { + let formatter = ByteCountFormatter() + formatter.countStyle = .file + formatter.allowedUnits = [.useKB, .useMB, .useGB] + return formatter.string(fromByteCount: Int64(self.size)) + } + + var displaySpeed: String? { + guard let speed = self.speed else { + return nil + } + + let formatter = ByteCountFormatter() + formatter.countStyle = .file + formatter.allowedUnits = [.useKB, .useMB, .useGB] + return "\(formatter.string(fromByteCount: Int64(speed)))/s" + } + + var displayTimeRemaining: String? { + guard let timeRemaining = self.timeRemaining else { + return nil + } + + if timeRemaining < 60 { + return "\(Int(timeRemaining))s" + } else if timeRemaining < 3600 { + let minutes = Int(timeRemaining / 60) + let secs = Int(timeRemaining.truncatingRemainder(dividingBy: 60)) + return "\(minutes)m \(secs)s" + } else { + let hours = Int(timeRemaining / 3600) + let minutes = Int((timeRemaining.truncatingRemainder(dividingBy: 3600)) / 60) + return "\(hours)h \(minutes)m" + } + } } |