From 74db9dd254c3a9b870ef576cee7e6283b8aa961f Mon Sep 17 00:00:00 2001 From: Stas Date: Thu, 23 Jul 2026 16:58:00 +0300 Subject: [PATCH] Fix menu bar spacing for custom account labels --- Sources/AppInfrastructure.swift | 6 ++++++ Sources/main.swift | 10 ++++++++-- Tests/InfrastructureTests.swift | 7 +++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Sources/AppInfrastructure.swift b/Sources/AppInfrastructure.swift index 014db82..f29ebcd 100644 --- a/Sources/AppInfrastructure.swift +++ b/Sources/AppInfrastructure.swift @@ -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( diff --git a/Sources/main.swift b/Sources/main.swift index ac500b2..e6a5a5f 100644 --- a/Sources/main.swift +++ b/Sources/main.swift @@ -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) + ) } } diff --git a/Tests/InfrastructureTests.swift b/Tests/InfrastructureTests.swift index 012ff73..b15f173 100644 --- a/Tests/InfrastructureTests.swift +++ b/Tests/InfrastructureTests.swift @@ -9,6 +9,7 @@ struct InfrastructureTests { testResetRefreshPolicy() testUsageRefreshPolicy() testLastKnownGoodSnapshotPolicy() + testToolbarStatusFormatting() try testComputerUsePluginDiscovery() try testBackupPruning() testProcessRunner() @@ -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) }