Skip to content

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

The activity strip: one place for everything that takes time

Gauthier Piarrette4cc66b7a276f
diff --git a/Sources/HighballApp/ActivityStrip.swift b/Sources/HighballApp/ActivityStrip.swift
new file mode 100644
index 0000000..a9e1108
--- /dev/null
+++ b/Sources/HighballApp/ActivityStrip.swift
@@ -0,0 +1,111 @@
+import SwiftUI
+import HighballKit
+
+/// One place for everything that takes time (UX plan §3.3): the busy operation with its bytes,
+/// stated range and elapsed time, a finished operation with its next step, and every running
+/// game. Always at the bottom of the window, never modal, never a bare spinner. Details opens
+/// the log sheet.
+struct ActivityStrip: View {
+ @Environment(AppState.self) private var state
+
+ var body: some View {
+ if state.busy || state.doneState != nil || !state.runningSessions.isEmpty {
+ VStack(spacing: 0) {
+ Divider()
+ VStack(spacing: 0) {
+ if state.busy {
+ busyRow
+ } else if let done = state.doneState {
+ doneRow(done)
+ }
+ ForEach(state.runningSessions) { session in
+ if state.busy || state.doneState != nil || session.id != state.runningSessions.first?.id { Divider().opacity(0.5) }
+ sessionRow(session)
+ }
+ }
+ }
+ .background(.bar)
+ .transition(.move(edge: .bottom).combined(with: .opacity))
+ }
+ }
+
+ // MARK: Rows
+
+ private var busyRow: some View {
+ VStack(spacing: 0) {
+ HStack(spacing: 10) {
+ ProgressView().controlSize(.small)
+ VStack(alignment: .leading, spacing: 1) {
+ Text(state.busyTitle).font(.callout.weight(.medium)).lineLimit(1)
+ if !state.stage.isEmpty || !state.stageHint.isEmpty {
+ Text([state.stage, state.stageHint].filter { !$0.isEmpty }.joined(separator: " · "))
+ .font(.caption).foregroundStyle(.secondary).lineLimit(1)
+ }
+ }
+ Spacer(minLength: 12)
+ TimelineView(.periodic(from: .now, by: 15)) { ctx in
+ Text(measurements(at: ctx.date))
+ .font(.caption.monospacedDigit()).foregroundStyle(.secondary).lineLimit(1)
+ }
+ if let stop = state.busyStop {
+ Button(stop.label) { state.stopBusy() }.controlSize(.small)
+ }
+ Button(L("Details")) { state.showLog = true }.controlSize(.small).buttonStyle(.link)
+ }
+ .padding(.horizontal, 14).padding(.vertical, 8)
+ // A determinate bar when bytes are known; nothing invented when they are not.
+ if let p = state.busyProgress, let fraction = ActivityText.fraction(received: p.received, total: p.total) {
+ GeometryReader { geo in
+ ZStack(alignment: .leading) {
+ Rectangle().fill(Color.primary.opacity(0.08))
+ Rectangle().fill(HB.amber).frame(width: geo.size.width * fraction)
+ }
+ }
+ .frame(height: 3)
+ }
+ }
+ }
+
+ /// 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 started = state.busyStartedAt {
+ parts.append(ActivityText.minutes(since: started, now: now).map { String(format: L("%d min"), $0) } ?? L("just started"))
+ }
+ if let expected = state.busyExpected { parts.append(expected) }
+ if state.busyProgress == nil, let last = state.lastOutputAt, now.timeIntervalSince(last) >= 90, state.stageHint.isEmpty {
+ parts.append(L("quiet"))
+ }
+ return parts.joined(separator: " · ")
+ }
+
+ private func doneRow(_ done: AppState.DoneState) -> some View {
+ HStack(spacing: 10) {
+ Image(systemName: "checkmark.circle.fill").foregroundStyle(HB.good)
+ Text(done.title).font(.callout.weight(.medium)).lineLimit(1)
+ Spacer(minLength: 12)
+ if let cta = done.ctaTitle {
+ Button(cta) { state.doneState = nil; done.cta?() }
+ .controlSize(.small).buttonStyle(.borderedProminent).tint(HB.amber)
+ }
+ Button(L("Details")) { state.showLog = true }.controlSize(.small).buttonStyle(.link)
+ Button(L("Dismiss")) { state.doneState = nil }.controlSize(.small)
+ }
+ .padding(.horizontal, 14).padding(.vertical, 8)
+ }
+
+ private func sessionRow(_ session: GameSession) -> some View {
+ HStack(spacing: 10) {
+ Circle().fill(HB.good).frame(width: 8, height: 8).padding(.horizontal, 4)
+ Text(String(format: L("%@ is running"), session.title)).font(.callout.weight(.medium)).lineLimit(1)
+ Spacer(minLength: 12)
+ TimelineView(.periodic(from: .now, by: 15)) { ctx in
+ Text(ActivityText.minutes(since: session.started, now: ctx.date).map { String(format: L("%d min"), $0) } ?? L("just started"))
+ .font(.caption.monospacedDigit()).foregroundStyle(.secondary)
+ }
+ Button(L("Stop")) { state.stopSession(session) }.controlSize(.small)
+ }
+ .padding(.horizontal, 14).padding(.vertical, 8)
+ }
+}
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swift
index b11c369..e6f5558 100644
--- a/Sources/HighballApp/AppState.swift
+++ b/Sources/HighballApp/AppState.swift
@@ -34,6 +34,31 @@ final class AppState {
var ctaTitle: String?
var cta: (() -> Void)?
}
+ // The activity strip (UX plan 0.5): what the busy operation can show beyond its title.
+ struct Transfer: Equatable { var received: Int64; var total: Int64? }
+ var busyProgress: Transfer? // bytes of the current download, for the bar
+ var transferRate: Double? // measured bytes per second, never a prediction
+ /// How a busy operation can be stopped, and what stopping does. A download stops cleanly
+ /// (the partial file stays); a launch stops by ending the bottle's processes.
+ enum BusyStop {
+ case cancelTask(label: String)
+ case killBottle(Bottle, label: String)
+ var label: String {
+ switch self {
+ case .cancelTask(let l), .killBottle(_, let l): return l
+ }
+ }
+ var stoppedTitle: String {
+ switch self {
+ case .cancelTask: return L("Stopped. Nothing already downloaded is lost.")
+ case .killBottle: return L("Stopped.")
+ }
+ }
+ }
+ var busyStop: BusyStop?
+ @ObservationIgnored private var busyTask: Task<Void, Never>?
+ @ObservationIgnored private var transferSamples: [ActivityText.Sample] = []
+ @ObservationIgnored private var stopRequested = false
var requestCreateBottle = false // engine-done CTA → ContentView opens the sheet
// Onboarding
@@ -350,13 +375,10 @@ final class AppState {
let accepted = Set(engines.flatMap { $0.manifest.acceptedLicenses ?? [] })
let title = String(format: L("Updating engine to %@"), manifest.id)
runBusy(title, expected: L("usually a few minutes"),
- done: DoneState(title: L("Engine updated"), ctaTitle: nil, cta: nil)) { [self] in
+ done: DoneState(title: L("Engine updated"), ctaTitle: nil, cta: nil),
+ stop: .cancelTask(label: L("Stop"))) { [self] in
let fresh = try await engineStore.install(manifest, accepted: accepted) { name, received, total in
- Task { @MainActor in
- let mb = { (b: Int64) in String(format: "%.0f", Double(b) / 1_048_576) }
- if let total, total > 0 { self.stage = "Downloading \(name) — \(mb(received)) / \(mb(total)) MB" }
- else { self.stage = "Downloading \(name) — \(mb(received)) MB" }
- }
+ Task { @MainActor in self.reportDownload(name, received: received, total: total) }
}
await MainActor.run { self.appendLog("engine \(fresh.id) installed") }
let sameWine = !EngineManifest.needsPrefixRefresh(from: old.manifest, to: fresh.manifest)
@@ -450,15 +472,18 @@ final class AppState {
if let h = ProgressParser.hint(for: line) { stageHint = h }
}
- private func runBusy(_ title: String, expected: String? = nil, showLogSheet: Bool = true,
- done: DoneState? = nil, cleanup: (() -> Void)? = nil,
+ /// Runs one long operation on the activity strip. The strip is the surface: the log sheet
+ /// opens only from its Details button (or `showLogSheet` for the rare case that needs it).
+ private func runBusy(_ title: String, expected: String? = nil, showLogSheet: Bool = false,
+ done: DoneState? = nil, stop: BusyStop? = nil, cleanup: (() -> Void)? = nil,
_ work: @escaping () async throws -> Void) {
// One busy operation at a time: a second call would reset the sheet's state under the
// first and end it early when the second finishes (found in review, 2026-09-04).
guard !busy else { return }
busy = true; busyTitle = title; stage = ""; stageHint = ""; logLines = []; showLog = showLogSheet
busyStartedAt = Date(); busyExpected = expected; lastOutputAt = nil; doneState = nil
- Task {
+ busyStop = stop; busyProgress = nil; transferRate = nil; transferSamples = []; stopRequested = false
+ busyTask = Task {
// On failure, dismiss the log sheet ourselves: SwiftUI defers the error alert
// until the sheet closes, so a stuck sheet showed "Done" over a failed install
// and hid the alert until the user clicked Close (issues #27/#28).
@@ -467,39 +492,67 @@ final class AppState {
doneState = done ?? DoneState(title: L("Done"), ctaTitle: nil, cta: nil)
} catch {
showLog = false
- // A retry is the same operation with the same closure; the sheet's own state
- // resets when runBusy starts again.
- fail(error, retry: { [weak self] in self?.runBusy(title, expected: expected, showLogSheet: showLogSheet, done: done, cleanup: cleanup, work) })
+ if stopRequested || error is CancellationError || (error as? URLError)?.code == .cancelled {
+ // The user stopped it: a result, not a failure, and no alert.
+ doneState = DoneState(title: stop?.stoppedTitle ?? L("Stopped."), ctaTitle: nil, cta: nil)
+ appendLog("stopped by the user")
+ } else {
+ // A retry is the same operation with the same closure; the sheet's own state
+ // resets when runBusy starts again.
+ fail(error, retry: { [weak self] in self?.runBusy(title, expected: expected, showLogSheet: showLogSheet, done: done, stop: stop, cleanup: cleanup, work) })
+ }
}
cleanup?()
- busy = false
+ busy = false; busyStop = nil; busyProgress = nil; transferRate = nil; busyTask = nil
refresh()
}
}
+ /// The strip's Stop button. What it does depends on the operation (see `BusyStop`); the
+ /// operation's own error path then reads as "stopped", never as a failure.
+ func stopBusy() {
+ guard busy, let stop = busyStop else { return }
+ stopRequested = true
+ switch stop {
+ case .cancelTask:
+ busyTask?.cancel()
+ case .killBottle(let bottle, _):
+ if let engine = engine(for: bottle) { try? WineRunner(paths: paths, engine: engine, bottle: bottle).kill() }
+ busyTask?.cancel()
+ }
+ }
+
+ /// Feeds the strip from a component download: a plain stage, moving bytes, a measured rate.
+ private func reportDownload(_ name: String, received: Int64, total: Int64?) {
+ let total = (total ?? 0) > 0 ? total : nil
+ if let last = transferSamples.last, received < last.bytes { transferSamples = [] } // next component
+ transferSamples.append(.init(bytes: received, at: Date()))
+ if transferSamples.count > 40 { transferSamples.removeFirst(transferSamples.count - 40) }
+ transferRate = ActivityText.rate(transferSamples)
+ busyProgress = Transfer(received: received, total: total)
+ stage = String(format: L("Downloading %@"), name)
+ if let total, received >= total {
+ appendLog("downloaded \(name) — verifying and unpacking…")
+ busyProgress = nil; transferRate = nil; transferSamples = []
+ }
+ }
+
// MARK: Actions
func installDefaultEngine(acceptGPTK: Bool) {
guard let manifestURL = Self.bundledManifest else {
errorMessage = "No engine manifest found. Reinstall Highball."; return
}
- runBusy("Installing engine — about 500 MB of verified downloads",
+ runBusy(L("Downloading the Windows engine"),
expected: L("usually 5–15 minutes"),
done: DoneState(title: L("Engine ready"), ctaTitle: L("Create your first bottle"),
- cta: { [weak self] in self?.requestCreateBottle = true })) { [self] in
+ cta: { [weak self] in self?.requestCreateBottle = true }),
+ stop: .cancelTask(label: L("Stop"))) { [self] in
let manifest = try EngineManifest.load(from: manifestURL)
var accepted: Set<String> = []
if acceptGPTK { accepted.insert("apple-gptk-license-2023-08-17") }
_ = try await engineStore.install(manifest, accepted: accepted) { name, received, total in
- Task { @MainActor in
- let mb = { (b: Int64) in String(format: "%.0f", Double(b) / 1_048_576) }
- if let total, total > 0 {
- self.stage = "Downloading \(name) — \(mb(received)) / \(mb(total)) MB"
- if received >= total { self.appendLog("downloaded \(name) — verifying and unpacking…") }
- } else {
- self.stage = "Downloading \(name) — \(mb(received)) MB"
- }
- }
+ Task { @MainActor in self.reportDownload(name, received: received, total: total) }
}
await MainActor.run { self.appendLog("engine installed") }
}
@@ -636,7 +689,7 @@ final class AppState {
atPath: bottle.driveC.appending(path: "Program Files (x86)/Steam/bin/cef").path)
runBusy(steamFirstBoot ? L("Starting Steam for the first time — it downloads and unpacks its own client") : "Running \(pin.name)",
expected: steamFirstBoot ? L("usually 15–25 minutes; long quiet stretches are normal") : nil,
- showLogSheet: steamFirstBoot,
+ stop: .killBottle(bottle, label: L("Stop")),
cleanup: { [weak self] in self?.launchingPins.remove(pin.id) }) { [self] in
let runner = WineRunner(paths: paths, engine: engine, bottle: bottle)
var extra = [String: String]()
@@ -771,8 +824,9 @@ final class AppState {
// The busy sheet covers the start only: Steam's client outlives the game and its launch
// call says nothing about it, so the game's own processes decide when "starting" ends
// and a session begins, and the app is free while the game runs (UX plan 0.6).
- runBusy("Starting \(game.name)", expected: L("a cold Steam client can take a couple of minutes"), showLogSheet: false,
- done: DoneState(title: L("Running"), ctaTitle: nil, cta: nil)) { [self] in
+ runBusy("Starting \(game.name)", expected: L("a cold Steam client can take a couple of minutes"),
+ done: DoneState(title: L("Running"), ctaTitle: nil, cta: nil),
+ stop: .killBottle(bottle, label: L("Stop"))) { [self] in
let runner = WineRunner(paths: paths, engine: engine, bottle: bottle)
// A running client would serve the launch with its own environment; when that is
// not the game's, cold-start first (never under a running game, see SteamRestart).
@@ -1047,13 +1101,10 @@ final class AppState {
let accepted = Set(engines.flatMap { $0.manifest.acceptedLicenses ?? [] })
let title = String(format: L("Downloading engine %@"), manifest.id)
runBusy(title, expected: L("usually a few minutes"),
- done: DoneState(title: L("Engine switched"), ctaTitle: nil, cta: nil)) { [self] in
+ done: DoneState(title: L("Engine switched"), ctaTitle: nil, cta: nil),
+ stop: .cancelTask(label: L("Stop"))) { [self] in
let fresh = try await engineStore.install(manifest, accepted: accepted) { name, received, total in
- Task { @MainActor in
- let mb = { (b: Int64) in String(format: "%.0f", Double(b) / 1_048_576) }
- if let total, total > 0 { self.stage = "Downloading \(name) — \(mb(received)) / \(mb(total)) MB" }
- else { self.stage = "Downloading \(name) — \(mb(received)) MB" }
- }
+ Task { @MainActor in self.reportDownload(name, received: received, total: total) }
}
await MainActor.run { self.appendLog("engine \(fresh.id) installed"); self.refresh() }
try await performMove(bottle, to: fresh)
diff --git a/Sources/HighballApp/BottleView.swift b/Sources/HighballApp/BottleView.swift
index 3bf01d9..fdaae61 100644
--- a/Sources/HighballApp/BottleView.swift
+++ b/Sources/HighballApp/BottleView.swift
@@ -50,17 +50,6 @@ struct BottleView: View {
var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: 34) {
- // Long operations used to be invisible unless the log sheet was open — the
- // Steam first-update looked frozen for 15-25 min. Surface the stage inline.
- if state.busy && !state.stage.isEmpty && !state.showLog {
- HStack(spacing: 9) {
- ProgressView().controlSize(.small)
- Text(state.stage).font(.callout).foregroundStyle(.secondary)
- Spacer()
- }
- .padding(.horizontal, 14).padding(.vertical, 9)
- .background(RoundedRectangle(cornerRadius: 9).fill(HB.card.opacity(0.8)))
- }
launchersSection
if !customPins.isEmpty { programsSection }
HStack(spacing: 6) {
diff --git a/Sources/HighballApp/HighballApp.swift b/Sources/HighballApp/HighballApp.swift
index 57495d6..c80fdf8 100644
--- a/Sources/HighballApp/HighballApp.swift
+++ b/Sources/HighballApp/HighballApp.swift
@@ -267,6 +267,8 @@ struct ContentView: View {
}
}
}
+ // Everything that takes time lives on one strip at the bottom, never modal (UX plan 0.5).
+ .safeAreaInset(edge: .bottom, spacing: 0) { ActivityStrip() }
.sheet(isPresented: $showCreate) { CreateBottleSheet() }
.onChange(of: state.requestCreateBottle) { _, wants in
if wants { showCreate = true; state.requestCreateBottle = false }
diff --git a/Sources/HighballApp/LibraryView.swift b/Sources/HighballApp/LibraryView.swift
index e202fe7..98b8e49 100644
--- a/Sources/HighballApp/LibraryView.swift
+++ b/Sources/HighballApp/LibraryView.swift
@@ -39,10 +39,6 @@ struct LibraryView: View {
var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: 26) {
- if state.busy && !state.stage.isEmpty && !state.showLog {
- Label(state.stage, systemImage: "clock")
- .font(.callout).foregroundStyle(.secondary)
- }
filterBar
if !continueItems.isEmpty && search.isEmpty && sourceFilter == nil {
VStack(alignment: .leading, spacing: 12) {
diff --git a/Sources/HighballKit/ActivityText.swift b/Sources/HighballKit/ActivityText.swift
new file mode 100644
index 0000000..a12cdaf
--- /dev/null
+++ b/Sources/HighballKit/ActivityText.swift
@@ -0,0 +1,70 @@
+import Foundation
+
+/// The numbers the activity strip shows. Nothing here predicts: bytes, rate and elapsed are
+/// measured, a stated range comes from a recipe, and time remaining is never computed, because
+/// a wrong "about a minute left" at 90% is the surest way to make someone quit a download that
+/// was about to succeed (UX plan §3.3).
+public enum ActivityText {
+ /// Bytes received so far, at a moment.
+ public struct Sample: Sendable, Equatable {
+ public let bytes: Int64
+ public let at: Date
+ public init(bytes: Int64, at: Date) { self.bytes = bytes; self.at = at }
+ }
+
+ /// Bytes per second over the samples inside `window` seconds of the latest, nil until they
+ /// span at least a second. A sample below the previous one starts a new transfer.
+ public static func rate(_ samples: [Sample], window: TimeInterval = 5) -> Double? {
+ guard let last = samples.last else { return nil }
+ var first = last
+ for s in samples.reversed() {
+ if s.bytes > first.bytes { break } // an earlier, larger count: another file
+ if last.at.timeIntervalSince(s.at) > window { break }
+ first = s
+ }
+ let dt = last.at.timeIntervalSince(first.at)
+ guard dt >= 1, last.bytes >= first.bytes else { return nil }
+ 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.
+ 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")
+ } else {
+ parts.append("\(megabytes(received)) MB")
+ }
+ if let rate, rate > 0 { parts.append(Self.rateText(rate)) }
+ return parts.joined(separator: " · ")
+ }
+
+ /// The fraction for a determinate bar, nil without a known total.
+ public static func fraction(received: Int64, total: Int64?) -> Double? {
+ guard let total, total > 0 else { return nil }
+ return min(1, max(0, Double(received) / Double(total)))
+ }
+
+ /// The step counter of a stage line ("Step 2 of 3 — Battle.net-Setup"), if it names one.
+ public static func steps(in stage: String) -> (done: Int, total: Int)? {
+ guard let m = stage.firstMatch(of: #/^Step (?<a>\d+) of (?<b>\d+)/#),
+ let a = Int(m.a), let b = Int(m.b), b > 0 else { return nil }
+ return (a, b)
+ }
+
+ /// Whole minutes for the strip: nil under a minute (the caller says "just started").
+ public static func minutes(since start: Date, now: Date = Date()) -> Int? {
+ let m = Int(now.timeIntervalSince(start) / 60)
+ return m < 1 ? nil : m
+ }
+
+ static func megabytes(_ bytes: Int64) -> String {
+ String(format: "%.0f", Double(bytes) / 1_048_576)
+ }
+
+ static func rateText(_ bytesPerSecond: Double) -> String {
+ if bytesPerSecond >= 1_048_576 { return String(format: "%.1f MB/s", bytesPerSecond / 1_048_576) }
+ return String(format: "%.0f KB/s", bytesPerSecond / 1024)
+ }
+}
diff --git a/Sources/HighballKit/EngineStore.swift b/Sources/HighballKit/EngineStore.swift
index 1139053..7b14310 100644
--- a/Sources/HighballKit/EngineStore.swift
+++ b/Sources/HighballKit/EngineStore.swift
@@ -182,6 +182,9 @@ public struct EngineStore: Sendable {
lastError = nil
break
} catch {
+ // A stop from the user is not a transient network failure: no retry, the
+ // partial file stays for the next attempt.
+ if error is CancellationError || (error as? URLError)?.code == .cancelled || Task.isCancelled { throw error }
lastError = error
if attempt < 3 { try? await Task.sleep(for: .seconds([2, 5][attempt - 1])) }
}
diff --git a/Tests/HighballKitTests/ActivityTextTests.swift b/Tests/HighballKitTests/ActivityTextTests.swift
new file mode 100644
index 0000000..3b3c228
--- /dev/null
+++ b/Tests/HighballKitTests/ActivityTextTests.swift
@@ -0,0 +1,50 @@
+import XCTest
+@testable import HighballKit
+
+final class ActivityTextTests: XCTestCase {
+ private let t0 = Date(timeIntervalSince1970: 1_000_000)
+ private func sample(_ mb: Double, _ seconds: TimeInterval) -> ActivityText.Sample {
+ .init(bytes: Int64(mb * 1_048_576), at: t0.addingTimeInterval(seconds))
+ }
+
+ func testRateNeedsASecondOfSamples() {
+ XCTAssertNil(ActivityText.rate([]))
+ XCTAssertNil(ActivityText.rate([sample(1, 0)]))
+ XCTAssertNil(ActivityText.rate([sample(1, 0), sample(2, 0.5)]))
+ }
+
+ func testRateIsMeasuredOverTheWindow() {
+ let r = ActivityText.rate([sample(0, 0), sample(2, 1), sample(4, 2), sample(6, 3)])
+ XCTAssertEqual(r.map { $0 / 1_048_576 } ?? 0, 2, accuracy: 0.01)
+ // Samples older than the window do not drag the rate down.
+ let stalled = ActivityText.rate([sample(0, 0), sample(0, 60), sample(10, 62), sample(20, 64)])
+ XCTAssertEqual(stalled.map { $0 / 1_048_576 } ?? 0, 5, accuracy: 0.01)
+ }
+
+ func testANewFileRestartsTheRate() {
+ // The second component starts from zero: its rate must not go negative or mix files.
+ let r = ActivityText.rate([sample(100, 0), sample(110, 1), sample(1, 2), sample(3, 4)])
+ XCTAssertEqual(r.map { $0 / 1_048_576 } ?? 0, 1, accuracy: 0.01)
+ }
+
+ func testTransferText() {
+ 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")
+ }
+
+ func testFractionAndSteps() {
+ XCTAssertEqual(ActivityText.fraction(received: 135 << 20, total: 270 << 20) ?? 0, 0.5, accuracy: 0.001)
+ XCTAssertNil(ActivityText.fraction(received: 1, total: nil))
+ XCTAssertEqual(ActivityText.fraction(received: 300, total: 200), 1)
+ XCTAssertEqual(ActivityText.steps(in: "Step 2 of 3 — Battle.net-Setup")?.done, 2)
+ XCTAssertEqual(ActivityText.steps(in: "Step 2 of 3")?.total, 3)
+ XCTAssertNil(ActivityText.steps(in: "Downloading wine"))
+ }
+
+ func testMinutes() {
+ 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)
+ }
+}