feat(updates): 使用 Sparkle 从发布 ZIP 下载并重启更新
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
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))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user