#if os(macOS) import SwiftUI /// One quiet line about a quiet updater's pending update, for an app's home screen. /// Empty when nothing is pending or while the app is busy, so it can sit in a layout /// permanently. Place it where a person rests, never over work in progress. public struct NativeUpdateNotice: View { private let updater: NativeUpdater public init(updater: NativeUpdater) { self.updater = updater } public var body: some View { if updater.canInstallPendingUpdate { HStack(alignment: .firstTextBaseline, spacing: 8) { Label { message } icon: { Image(systemName: "arrow.down.circle") } .foregroundStyle(.secondary) Button(action: updater.installPendingUpdate) { action } .buttonStyle(.borderless) } .font(.callout) .accessibilityElement(children: .contain) } } private var app: String { NativeUpdateCommands.appName } private var message: Text { switch updater.pendingUpdate { case .ready(let version): Text("\(app) \(version) is ready.", bundle: NativeUpdateCommands.resources) case .available(let version): Text("\(app) \(version) is available.", bundle: NativeUpdateCommands.resources) case .none: Text(verbatim: "") } } private var action: Text { if case .ready = updater.pendingUpdate { return Text("Restart to Update", bundle: NativeUpdateCommands.resources) } return Text("Update…", bundle: NativeUpdateCommands.resources) } } #endif