Skip to content

Run Windows games on Apple Silicon — free, open source, with an open compatibility database that tells you what actually works.

activity strip: show KB and seconds, not 0 MB · just started

Silverdragon1224895eb26db5a
diff --git a/Sources/HighballApp/ActivityStrip.swift b/Sources/HighballApp/ActivityStrip.swift
index 754b3ba..0aecb15 100644
--- a/Sources/HighballApp/ActivityStrip.swift
+++ b/Sources/HighballApp/ActivityStrip.swift
@@ -50,7 +50,7 @@ struct ActivityStrip: View {
}
}
Spacer(minLength: 12)
- TimelineView(.periodic(from: .now, by: 15)) { ctx in
+ TimelineView(.periodic(from: .now, by: 1)) { ctx in
Text(measurements(at: ctx.date))
.font(.caption.monospacedDigit()).foregroundStyle(.secondary).lineLimit(1)
}
@@ -76,9 +76,16 @@ struct ActivityStrip: View {
/// Bytes and rate when a download runs, elapsed always, the stated range when there is one.
private func measurements(at now: Date) -> String {
var parts: [String] = []
- if let p = state.busyProgress { parts.append(ActivityText.transfer(received: p.received, total: p.total, rate: state.transferRate)) }
+ if let p = state.busyProgress, p.received > 0 {
+ parts.append(ActivityText.transfer(received: p.received, total: p.total, rate: state.transferRate))
+ }
if let started = state.busyStartedAt {
- parts.append(ActivityText.minutes(since: started, now: now).map { String(format: L("%d min"), $0) } ?? L("just started"))
+ let e = ActivityText.elapsed(since: started, now: now)
+ if e.asSeconds, e.amount == 0 {
+ parts.append(L("just started"))
+ } else {
+ parts.append(String(format: e.asSeconds ? L("%d sec") : L("%d min"), e.amount))
+ }
}
if let expected = state.busyExpected { parts.append(expected) }
if state.busyProgress == nil, let last = state.lastOutputAt, now.timeIntervalSince(last) >= 90, state.stageHint.isEmpty {
diff --git a/Sources/HighballApp/L10n.swift b/Sources/HighballApp/L10n.swift
index e87009e..3d7a198 100644
--- a/Sources/HighballApp/L10n.swift
+++ b/Sources/HighballApp/L10n.swift
@@ -309,6 +309,7 @@ enum L10n {
"%@ quit after %d seconds": "%@ s'est fermé après %d secondes",
"%@ quit right away": "%@ s'est fermé tout de suite",
"%d min": "%d min",
+ "%d sec": "%d s",
"A Windows program I have": "Un programme Windows que j'ai",
"A Windows program I have…": "Un programme Windows que j'ai…",
"A few counts from this Mac, no game names; you read the text before it is sent.": "Quelques comptages depuis ce Mac, sans nom de jeu ; vous lisez le texte avant l'envoi.",
diff --git a/Sources/HighballKit/ActivityText.swift b/Sources/HighballKit/ActivityText.swift
index a12cdaf..6895b5d 100644
--- a/Sources/HighballKit/ActivityText.swift
+++ b/Sources/HighballKit/ActivityText.swift
@@ -27,12 +27,18 @@ public enum ActivityText {
return Double(last.bytes - first.bytes) / dt
}
- /// "164 of 270 MB · 2.4 MB/s"; "164 MB" alone when the total is unknown; no rate until one
- /// is measured.
+ /// "164 of 270 MB · 2.4 MB/s"; "240 KB" before the first megabyte so a live copy is not
+ /// stuck on "0 MB".
public static func transfer(received: Int64, total: Int64?, rate: Double?) -> String {
var parts: [String] = []
if let total, total > 0 {
- parts.append("\(megabytes(received)) of \(megabytes(total)) MB")
+ if total < 1_048_576 {
+ parts.append("\(received / 1024) of \(total / 1024) KB")
+ } else {
+ parts.append("\(megabytes(received)) of \(megabytes(total)) MB")
+ }
+ } else if received < 1_048_576 {
+ parts.append("\(received / 1024) KB")
} else {
parts.append("\(megabytes(received)) MB")
}
@@ -59,6 +65,12 @@ public enum ActivityText {
return m < 1 ? nil : m
}
+ /// Seconds until a minute, then whole minutes.
+ public static func elapsed(since start: Date, now: Date = Date()) -> (amount: Int, asSeconds: Bool) {
+ let s = max(0, Int(now.timeIntervalSince(start)))
+ return s < 60 ? (s, true) : (s / 60, false)
+ }
+
static func megabytes(_ bytes: Int64) -> String {
String(format: "%.0f", Double(bytes) / 1_048_576)
}
diff --git a/Tests/HighballKitTests/ActivityTextTests.swift b/Tests/HighballKitTests/ActivityTextTests.swift
index 3b3c228..398d57e 100644
--- a/Tests/HighballKitTests/ActivityTextTests.swift
+++ b/Tests/HighballKitTests/ActivityTextTests.swift
@@ -31,6 +31,8 @@ final class ActivityTextTests: XCTestCase {
XCTAssertEqual(ActivityText.transfer(received: 164 << 20, total: 270 << 20, rate: 2.4 * 1_048_576), "164 of 270 MB · 2.4 MB/s")
XCTAssertEqual(ActivityText.transfer(received: 164 << 20, total: nil, rate: nil), "164 MB")
XCTAssertEqual(ActivityText.transfer(received: 5 << 20, total: 0, rate: 640 * 1024), "5 MB · 640 KB/s")
+ XCTAssertEqual(ActivityText.transfer(received: 240 * 1024, total: nil, rate: nil), "240 KB")
+ XCTAssertEqual(ActivityText.transfer(received: 0, total: nil, rate: nil), "0 KB")
}
func testFractionAndSteps() {
@@ -46,5 +48,13 @@ final class ActivityTextTests: XCTestCase {
XCTAssertNil(ActivityText.minutes(since: t0, now: t0.addingTimeInterval(59)))
XCTAssertEqual(ActivityText.minutes(since: t0, now: t0.addingTimeInterval(61)), 1)
XCTAssertEqual(ActivityText.minutes(since: t0, now: t0.addingTimeInterval(12 * 60 + 30)), 12)
+ XCTAssertEqual(ActivityText.elapsed(since: t0, now: t0).amount, 0)
+ XCTAssertTrue(ActivityText.elapsed(since: t0, now: t0).asSeconds)
+ XCTAssertEqual(ActivityText.elapsed(since: t0, now: t0.addingTimeInterval(12)).amount, 12)
+ XCTAssertTrue(ActivityText.elapsed(since: t0, now: t0.addingTimeInterval(12)).asSeconds)
+ XCTAssertEqual(ActivityText.elapsed(since: t0, now: t0.addingTimeInterval(59)).amount, 59)
+ XCTAssertTrue(ActivityText.elapsed(since: t0, now: t0.addingTimeInterval(59)).asSeconds)
+ XCTAssertEqual(ActivityText.elapsed(since: t0, now: t0.addingTimeInterval(90)).amount, 1)
+ XCTAssertFalse(ActivityText.elapsed(since: t0, now: t0.addingTimeInterval(90)).asSeconds)
}
}