import SwiftUI /// The same single action is presented as a compact version badge or a settings button. struct UpdateAction: View { let phase: ReleaseUpdates.Phase let version: ReleaseUpdates.Version? var compact = false let action: () -> Void var body: some View { if let url = version?.infoURL, phase == .available { Link(destination: url) { content("updates.releasePage", symbol: "arrow.up.right") } } else { Button(action: action) { switch phase { case .available: content("updates.download", symbol: "arrow.down.circle.fill") case .ready: content("updates.restart", symbol: "arrow.clockwise.circle.fill") case .checking: content("updates.checking", symbol: "magnifyingglass") case .downloading: content("updates.downloading", symbol: "arrow.down") case .extracting: content("updates.preparing", symbol: "shippingbox") case .restarting: content("updates.restarting", symbol: "arrow.clockwise") case .failed: content("updates.retry", symbol: "arrow.clockwise") case .idle, .current: content("updates.check", symbol: "arrow.clockwise") } } .disabled([.checking, .downloading, .extracting, .restarting].contains(phase)) } } private func content(_ title: LocalizedStringKey, symbol: String) -> some View { HStack(spacing: 3) { Image(systemName: symbol) if compact, let version { Text(verbatim: "v" + version.display) } else { Text(title) } } .accessibilityElement(children: .ignore) .accessibilityLabel(Text(title)) .accessibilityValue(Text(verbatim: version?.label ?? "")) .help(Text(title)) } }