secretive/Sources/Secretive/Views/UpdateView.swift

62 lines
1.9 KiB
Swift
Raw Permalink Normal View History

2020-09-22 06:12:50 +00:00
import SwiftUI
import Brief
struct UpdateDetailView<UpdaterType: Updater>: View {
@EnvironmentObject var updater: UpdaterType
let update: Release
var body: some View {
VStack {
Text("update_version_name_\(update.name)").font(.title)
GroupBox(label: Text("update_release_notes_title")) {
2020-09-22 06:12:50 +00:00
ScrollView {
attributedBody
}
}
HStack {
if !update.critical {
Button("update_ignore_button") {
2020-09-22 06:12:50 +00:00
updater.ignore(release: update)
}
Spacer()
}
Button("update_update_button") {
2020-09-22 06:12:50 +00:00
NSWorkspace.shared.open(update.html_url)
}
.keyboardShortcut(.defaultAction)
}
}
.padding()
.frame(maxWidth: 500)
}
var attributedBody: Text {
var text = Text(verbatim: "")
2020-09-22 06:12:50 +00:00
for line in update.body.split(whereSeparator: \.isNewline) {
let attributed: Text
let split = line.split(separator: " ")
let unprefixed = split.dropFirst().joined(separator: " ")
2020-09-22 06:12:50 +00:00
if let prefix = split.first {
switch prefix {
case "#":
attributed = Text(unprefixed).font(.title) + Text(verbatim: "\n")
2020-09-22 06:12:50 +00:00
case "##":
attributed = Text(unprefixed).font(.title2) + Text(verbatim: "\n")
2020-09-22 06:12:50 +00:00
case "###":
attributed = Text(unprefixed).font(.title3) + Text(verbatim: "\n")
2020-09-22 06:12:50 +00:00
default:
attributed = Text(line) + Text(verbatim: "\n\n")
2020-09-22 06:12:50 +00:00
}
} else {
attributed = Text(line) + Text(verbatim: "\n\n")
2020-09-22 06:12:50 +00:00
}
text = text + attributed
}
return text
}
}