Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Sources/AppInfrastructure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ enum LastKnownGoodSnapshotPolicy {
}
}

enum ToolbarStatusFormatter {
static func text(label: String, usage: String) -> String {
"\(label)\(label.count > 1 ? " " : "")\(usage)"
}
}

enum ComputerUsePluginLocator {
static func latestApp(in versionsRoot: URL, fileManager: FileManager = .default) -> URL? {
guard let versionDirectories = try? fileManager.contentsOfDirectory(
Expand Down
10 changes: 8 additions & 2 deletions Sources/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3311,9 +3311,15 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
let percent = toolbarUsagePercent(for: account)
switch toolbarDisplayStyle {
case .detailed:
return "\(label)\(remainingPercentText(fromUsed: percent))"
return ToolbarStatusFormatter.text(
label: label,
usage: remainingPercentText(fromUsed: percent)
)
case .compact:
return "\(label)\(remainingPercentNumberText(fromUsed: percent))"
return ToolbarStatusFormatter.text(
label: label,
usage: remainingPercentNumberText(fromUsed: percent)
)
}
}

Expand Down
7 changes: 7 additions & 0 deletions Tests/InfrastructureTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ struct InfrastructureTests {
testResetRefreshPolicy()
testUsageRefreshPolicy()
testLastKnownGoodSnapshotPolicy()
testToolbarStatusFormatting()
try testComputerUsePluginDiscovery()
try testBackupPruning()
testProcessRunner()
Expand Down Expand Up @@ -65,6 +66,12 @@ struct InfrastructureTests {
expect(unchanged == ["one": 100, "two": 100], "a wholly failed refresh should not roll usage back")
}

private static func testToolbarStatusFormatting() {
expect(ToolbarStatusFormatter.text(label: "A", usage: "89%") == "A89%", "single-character labels should keep the compact menu-bar format")
expect(ToolbarStatusFormatter.text(label: "1287", usage: "100%") == "1287 100%", "multi-character labels should be separated from usage")
expect(ToolbarStatusFormatter.text(label: "1287", usage: "100") == "1287 100", "compact usage should also be separated from multi-character labels")
}

private static func testComputerUsePluginDiscovery() throws {
let root = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString, isDirectory: true)
defer { try? FileManager.default.removeItem(at: root) }
Expand Down