Changing update view.

This commit is contained in:
Max Goedjen
2020-09-10 18:26:29 -07:00
parent 6a24a66627
commit 535b5efe8e
3 changed files with 94 additions and 24 deletions

View File

@@ -12,7 +12,8 @@ struct ContentView<UpdaterType: UpdaterProtocol, AgentStatusCheckerType: AgentSt
@State private var active: AnySecret.ID?
@State private var showingCreation = false
@State private var deletingSecret: AnySecret?
@State private var selectedUpdate: Release?
var body: some View {
VStack {
if storeList.anyAvailable {
@@ -74,7 +75,7 @@ struct ContentView<UpdaterType: UpdaterProtocol, AgentStatusCheckerType: AgentSt
.frame(minWidth: 640, minHeight: 320)
.toolbar {
// if updater.update != nil {
// updateNotice()
updateNotice()
// }
// if !agentStatusChecker.running {
// agentNotice()z
@@ -89,29 +90,34 @@ struct ContentView<UpdaterType: UpdaterProtocol, AgentStatusCheckerType: AgentSt
}
}
// func updateNotice() -> ToolbarItem<Void, some View> {
func updateNotice() -> ToolbarItem<Void, AnyView> {
let update = updater.update ?? Release(name: "", html_url: URL(string:"https://example.com")!, body: "")
// guard let update = updater.update else { fatalError() }
// let color: Color
// let text: String
// if update.critical {
// text = "Critical Security Update Required"
// color = .orange
// } else {
// text = "Update Available"
// color = .red
// }
// return ToolbarItem {
// Button(action: {
// NSWorkspace.shared.open(update.html_url)
// }, label: {
// Text(text)
// .font(.headline)
// .foregroundColor(.white)
// })
// .background(color)
// .cornerRadius(5)
// }
// }
let color: Color
let text: String
if update.critical {
text = "Critical Security Update Required"
color = .red
} else {
text = "Update Available"
color = .orange
}
return ToolbarItem {
AnyView(Button(action: {
self.selectedUpdate = update
}, label: {
Text(text)
.font(.headline)
.foregroundColor(.white)
})
.background(color)
.cornerRadius(5)
.popover(item: $selectedUpdate, attachmentAnchor: .point(.bottom), arrowEdge: .bottom) { update in
UpdateDetailView(update: update)
}
)
}
}
//
// func agentNotice() -> ToolbarItem<Void, AnyView> {
// ToolbarItem {

View File

@@ -0,0 +1,60 @@
import SwiftUI
import Brief
//struct UpdateView<UpdaterType: UpdaterProtocol>: View {
//
//
//}
struct UpdateDetailView: View {
private let update: Release
init(update: Release) {
self.update = update
}
var body: some View {
VStack {
Text("Secretive \(update.name)").font(.title)
GroupBox(label: Text("Release Notes")) {
ScrollView {
attributedBody
}
}
Button(action: {
NSWorkspace.shared.open(update.html_url)
}, label: {
Text("Update")
})
}
.padding()
.frame(maxWidth: 500)
}
var attributedBody: Text {
var text = Text("")
for line in update.body.split(whereSeparator: \.isNewline) {
let attributed: Text
let split = line.split(separator: " ")
let unprefixed = split.dropFirst().joined()
if let prefix = split.first {
switch prefix {
case "#":
attributed = Text(unprefixed).font(.title) + Text("\n")
case "##":
attributed = Text(unprefixed).font(.title2) + Text("\n")
case "###":
attributed = Text(unprefixed).font(.title3) + Text("\n")
default:
attributed = Text(line) + Text("\n\n")
}
} else {
attributed = Text(line) + Text("\n\n")
}
text = text + attributed
}
return text
}
}