From f058f36dbd67c49ce8da711307ef3c91fcb37fe1 Mon Sep 17 00:00:00 2001 From: iamtoruk Date: Mon, 11 May 2026 11:21:39 -0700 Subject: [PATCH] Normalize menubar version display --- mac/Scripts/package-app.sh | 8 ++-- mac/Sources/CodeBurnMenubar/AppVersion.swift | 43 +++++++++++++++++++ mac/Sources/CodeBurnMenubar/CodeBurnApp.swift | 4 +- .../CodeBurnMenubar/Data/UpdateChecker.swift | 6 +-- .../Views/MenuBarContent.swift | 2 +- .../CodeBurnMenubar/Views/SettingsView.swift | 6 +-- .../AppVersionTests.swift | 19 ++++++++ 7 files changed, 75 insertions(+), 13 deletions(-) create mode 100644 mac/Sources/CodeBurnMenubar/AppVersion.swift create mode 100644 mac/Tests/CodeBurnMenubarTests/AppVersionTests.swift diff --git a/mac/Scripts/package-app.sh b/mac/Scripts/package-app.sh index ee0dc06..6df7abb 100755 --- a/mac/Scripts/package-app.sh +++ b/mac/Scripts/package-app.sh @@ -9,6 +9,8 @@ set -euo pipefail VERSION="${1:-dev}" +ASSET_VERSION="${VERSION#mac-}" +BUNDLE_VERSION="${ASSET_VERSION#v}" BUNDLE_NAME="CodeBurnMenubar.app" BUNDLE_ID="org.agentseal.codeburn-menubar" EXECUTABLE_NAME="CodeBurnMenubar" @@ -66,9 +68,9 @@ cat > "${BUNDLE}/Contents/Info.plist" <CFBundlePackageType APPL CFBundleShortVersionString - ${VERSION} + ${BUNDLE_VERSION} CFBundleVersion - ${VERSION} + ${BUNDLE_VERSION} LSMinimumSystemVersion ${MIN_MACOS} LSUIElement @@ -93,7 +95,7 @@ echo "▸ Ad-hoc signing..." codesign --force --sign - --timestamp=none --deep "${BUNDLE}" 2>/dev/null || true codesign --verify --deep --strict "${BUNDLE}" 2>/dev/null || echo " (signature verify skipped)" -ZIP_NAME="CodeBurnMenubar-${VERSION}.zip" +ZIP_NAME="CodeBurnMenubar-${ASSET_VERSION}.zip" ZIP_PATH="${DIST_DIR}/${ZIP_NAME}" echo "▸ Packaging ${ZIP_NAME}..." (cd "${DIST_DIR}" && COPYFILE_DISABLE=1 /usr/bin/ditto -c -k --norsrc --keepParent "${BUNDLE_NAME}" "${ZIP_NAME}") diff --git a/mac/Sources/CodeBurnMenubar/AppVersion.swift b/mac/Sources/CodeBurnMenubar/AppVersion.swift new file mode 100644 index 0000000..c5ee14a --- /dev/null +++ b/mac/Sources/CodeBurnMenubar/AppVersion.swift @@ -0,0 +1,43 @@ +import Foundation + +enum AppVersion { + static var bundleShortVersion: String { + Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "" + } + + static var bundleBuildVersion: String { + Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? "" + } + + static var normalizedBundleShortVersion: String { + normalize(bundleShortVersion) + } + + static var normalizedBundleBuildVersion: String { + normalize(bundleBuildVersion) + } + + static var displayBundleShortVersion: String { + display(bundleShortVersion) + } + + static func normalize(_ version: String) -> String { + let trimmed = version.trimmingCharacters(in: .whitespacesAndNewlines) + if trimmed.lowercased().hasPrefix("mac-v") { + return String(trimmed.dropFirst(5)) + } + if trimmed.lowercased().hasPrefix("v") { + return String(trimmed.dropFirst()) + } + return trimmed + } + + static func display(_ version: String) -> String { + let normalized = normalize(version) + guard !normalized.isEmpty else { return "v?" } + if normalized == "?" || normalized == "dev" || normalized == "dev-preview" || normalized == "—" { + return normalized + } + return "v\(normalized)" + } +} diff --git a/mac/Sources/CodeBurnMenubar/CodeBurnApp.swift b/mac/Sources/CodeBurnMenubar/CodeBurnApp.swift index a58d044..851ad43 100644 --- a/mac/Sources/CodeBurnMenubar/CodeBurnApp.swift +++ b/mac/Sources/CodeBurnMenubar/CodeBurnApp.swift @@ -705,10 +705,10 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSPopoverDelegate { alert.icon = codeburnAlertIcon() if updateChecker.updateAvailable, let latest = updateChecker.latestVersion { alert.messageText = "Update Available" - alert.informativeText = "v\(latest) is available (you have v\(updateChecker.currentVersion)). Run:\n\ncodeburn menubar --force" + alert.informativeText = "\(AppVersion.display(latest)) is available (you have \(AppVersion.display(updateChecker.currentVersion))). Run:\n\ncodeburn menubar --force" } else { alert.messageText = "Up to Date" - alert.informativeText = "You're on the latest version (v\(updateChecker.currentVersion))." + alert.informativeText = "You're on the latest version (\(AppVersion.display(updateChecker.currentVersion)))." } alert.alertStyle = .informational alert.addButton(withTitle: "OK") diff --git a/mac/Sources/CodeBurnMenubar/Data/UpdateChecker.swift b/mac/Sources/CodeBurnMenubar/Data/UpdateChecker.swift index ce575b6..955718f 100644 --- a/mac/Sources/CodeBurnMenubar/Data/UpdateChecker.swift +++ b/mac/Sources/CodeBurnMenubar/Data/UpdateChecker.swift @@ -16,14 +16,14 @@ final class UpdateChecker { var updateAvailable: Bool { guard let latest = latestVersion else { return false } let current = currentVersion - let normalizedLatest = latest.hasPrefix("v") ? String(latest.dropFirst()) : latest - let normalizedCurrent = current.hasPrefix("v") ? String(current.dropFirst()) : current + let normalizedLatest = AppVersion.normalize(latest) + let normalizedCurrent = AppVersion.normalize(current) guard !normalizedCurrent.isEmpty && normalizedCurrent != "dev" else { return false } return normalizedLatest.compare(normalizedCurrent, options: .numeric) == .orderedDescending } var currentVersion: String { - Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "" + AppVersion.normalizedBundleShortVersion } func checkIfNeeded() async { diff --git a/mac/Sources/CodeBurnMenubar/Views/MenuBarContent.swift b/mac/Sources/CodeBurnMenubar/Views/MenuBarContent.swift index fbf3dd9..6a38b1c 100644 --- a/mac/Sources/CodeBurnMenubar/Views/MenuBarContent.swift +++ b/mac/Sources/CodeBurnMenubar/Views/MenuBarContent.swift @@ -567,7 +567,7 @@ struct FooterBar: View { Spacer() - Text("v\(Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "?")") + Text(AppVersion.displayBundleShortVersion) .font(.system(size: 10, weight: .regular, design: .monospaced)) .foregroundStyle(.tertiary) diff --git a/mac/Sources/CodeBurnMenubar/Views/SettingsView.swift b/mac/Sources/CodeBurnMenubar/Views/SettingsView.swift index a4c3585..a317380 100644 --- a/mac/Sources/CodeBurnMenubar/Views/SettingsView.swift +++ b/mac/Sources/CodeBurnMenubar/Views/SettingsView.swift @@ -337,10 +337,8 @@ private struct CodexConnectionRow: View { // MARK: - About private struct AboutSettingsTab: View { - private let appVersion: String = - (Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String) ?? "—" - private let buildVersion: String = - (Bundle.main.infoDictionary?["CFBundleVersion"] as? String) ?? "—" + private let appVersion: String = AppVersion.normalizedBundleShortVersion + private let buildVersion: String = AppVersion.normalizedBundleBuildVersion var body: some View { VStack(spacing: 14) { diff --git a/mac/Tests/CodeBurnMenubarTests/AppVersionTests.swift b/mac/Tests/CodeBurnMenubarTests/AppVersionTests.swift new file mode 100644 index 0000000..898f5e0 --- /dev/null +++ b/mac/Tests/CodeBurnMenubarTests/AppVersionTests.swift @@ -0,0 +1,19 @@ +import Testing +@testable import CodeBurnMenubar + +@Suite("AppVersion") +struct AppVersionTests { + @Test("display avoids duplicate v prefix") + func displayAvoidsDuplicatePrefix() { + #expect(AppVersion.display("0.9.8") == "v0.9.8") + #expect(AppVersion.display("v0.9.8") == "v0.9.8") + #expect(AppVersion.display("mac-v0.9.8") == "v0.9.8") + } + + @Test("bundle metadata stores unprefixed semver") + func normalizeBundleVersion() { + #expect(AppVersion.normalize("v0.9.8") == "0.9.8") + #expect(AppVersion.normalize("mac-v0.9.8") == "0.9.8") + #expect(AppVersion.normalize("dev") == "dev") + } +}