| 1 | #if os(macOS) |
| 2 | import SwiftUI |
| 3 | |
| 4 | /// One quiet line about a quiet updater's pending update, for an app's home screen. |
| 5 | /// Empty when nothing is pending or while the app is busy, so it can sit in a layout |
| 6 | /// permanently. Place it where a person rests, never over work in progress. |
| 7 | public struct NativeUpdateNotice: View { |
| 8 | private let updater: NativeUpdater |
| 9 | |
| 10 | public init(updater: NativeUpdater) { self.updater = updater } |
| 11 | |
| 12 | public var body: some View { |
| 13 | if updater.canInstallPendingUpdate { |
| 14 | HStack(alignment: .firstTextBaseline, spacing: 8) { |
| 15 | Label { message } icon: { Image(systemName: "arrow.down.circle") } |
| 16 | .foregroundStyle(.secondary) |
| 17 | Button(action: updater.installPendingUpdate) { action } |
| 18 | .buttonStyle(.borderless) |
| 19 | } |
| 20 | .font(.callout) |
| 21 | .accessibilityElement(children: .contain) |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | private var app: String { NativeUpdateCommands.appName } |
| 26 | |
| 27 | private var message: Text { |
| 28 | switch updater.pendingUpdate { |
| 29 | case .ready(let version): Text("\(app) \(version) is ready.", bundle: NativeUpdateCommands.resources) |
| 30 | case .available(let version): Text("\(app) \(version) is available.", bundle: NativeUpdateCommands.resources) |
| 31 | case .none: Text(verbatim: "") |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | private var action: Text { |
| 36 | if case .ready = updater.pendingUpdate { |
| 37 | return Text("Restart to Update", bundle: NativeUpdateCommands.resources) |
| 38 | } |
| 39 | return Text("Update…", bundle: NativeUpdateCommands.resources) |
| 40 | } |
| 41 | } |
| 42 | #endif |
| 43 | |