| 1 | import AppKit |
| 2 | import Foundation |
| 3 | |
| 4 | // Where the running app came from, for the About panel. The short git SHA is |
| 5 | // stamped into the built Info.plist by the "Stamp git SHA" phase in |
| 6 | // ios/project.yml — NOT baked in at compile time: a Swift compilation |
| 7 | // condition (`#if GIT_SHA`) is a flag, not a value, so it can't carry the |
| 8 | // string, and CFBundleVersion is off-limits because Sparkle orders updates by |
| 9 | // it. The stamp is absent in a checkout without .git (a source tarball), and |
| 10 | // then the panel is simply the stock one. |
| 11 | enum BuildInfo { |
| 12 | /// Short SHA of the commit the app was built from, `-dirty` when the tree |
| 13 | /// had uncommitted changes. Nil when the build had no git to ask. |
| 14 | static let gitSHA: String? = { |
| 15 | let sha = Bundle.main.infoDictionary?["GitSHA"] as? String |
| 16 | return (sha?.isEmpty ?? true) ? nil : sha |
| 17 | }() |
| 18 | |
| 19 | /// The bundle's display name — "Eleven", or "Eleven Dev" for a dev alt, so |
| 20 | /// the menu item names the app you're actually looking at. |
| 21 | static var appName: String { |
| 22 | let info = Bundle.main.infoDictionary |
| 23 | return info?["CFBundleDisplayName"] as? String |
| 24 | ?? info?["CFBundleName"] as? String |
| 25 | ?? "Eleven" |
| 26 | } |
| 27 | |
| 28 | /// Options for the standard About panel. The SHA rides in `.version` — the |
| 29 | /// parenthetical next to the marketing version — so it reads "Version 1.0 |
| 30 | /// (2 · a1b2c3d)" with no custom window to maintain. |
| 31 | static var aboutPanelOptions: [NSApplication.AboutPanelOptionKey: Any] { |
| 32 | guard let sha = gitSHA else { return [:] } |
| 33 | let build = Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? "" |
| 34 | return [.version: build.isEmpty ? sha : "\(build) · \(sha)"] |
| 35 | } |
| 36 | |
| 37 | static func showAboutPanel() { |
| 38 | NSApp.activate(ignoringOtherApps: true) |
| 39 | NSApp.orderFrontStandardAboutPanel(options: aboutPanelOptions) |
| 40 | } |
| 41 | } |
| 42 | |