diff --git a/HyperWindow/Functions.swift b/HyperWindow/Functions.swift index 0ef509f..2a3a678 100644 --- a/HyperWindow/Functions.swift +++ b/HyperWindow/Functions.swift @@ -120,14 +120,14 @@ func isTrusted(prompt: Bool) -> Bool { } +func formattedVersion(shortVersion: String, bundleVersion: String, short: Bool = false) -> String { + short ? shortVersion : "\(shortVersion) (\(bundleVersion))" +} + func appVersion(short: Bool = false) -> String { let shortVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "-" - if short { - return shortVersion - } else { - let bundleVersion = Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? "-" - return "\(shortVersion) (\(bundleVersion))" - } + let bundleVersion = Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? "-" + return formattedVersion(shortVersion: shortVersion, bundleVersion: bundleVersion, short: short) } func settingsVersion(infoDictionary: [String: Any] = Bundle.main.infoDictionary ?? [:]) -> String { diff --git a/HyperWindowTests/PreferencesControllerTests.swift b/HyperWindowTests/PreferencesControllerTests.swift index 6acb8da..fc4acb2 100644 --- a/HyperWindowTests/PreferencesControllerTests.swift +++ b/HyperWindowTests/PreferencesControllerTests.swift @@ -156,6 +156,11 @@ final class PreferencesControllerTests: XCTestCase { XCTAssertTrue(controls.allSatisfy { contentView.convert($0.bounds, from: $0).maxX <= contentView.bounds.maxX }) } + func testFormattedVersionFormatsShortAndFullVersions() { + XCTAssertEqual(formattedVersion(shortVersion: "1.2.3", bundleVersion: "42", short: true), "1.2.3") + XCTAssertEqual(formattedVersion(shortVersion: "1.2.3", bundleVersion: "42"), "1.2.3 (42)") + } + func testSettingsVersionIncludesCommitForUntaggedBuild() { let version = settingsVersion(infoDictionary: [ "CFBundleShortVersionString": "1.2.3",