Changing update view.

This commit is contained in:
Max Goedjen 2020-09-10 18:26:29 -07:00
parent 6a24a66627
commit 535b5efe8e
No known key found for this signature in database
GPG Key ID: E58C21DD77B9B8E8
3 changed files with 94 additions and 24 deletions

View File

@ -8,6 +8,7 @@
/* Begin PBXBuildFile section */
50020BB024064869003D4025 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50020BAF24064869003D4025 /* AppDelegate.swift */; };
50153E20250AFCB200525160 /* UpdateView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50153E1F250AFCB200525160 /* UpdateView.swift */; };
5018F54F24064786002EB505 /* Notifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5018F54E24064786002EB505 /* Notifier.swift */; };
50524B442420969E008DBD97 /* OpenSSHWriterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50524B432420969D008DBD97 /* OpenSSHWriterTests.swift */; };
50571E0324393C2600F76F6C /* JustUpdatedChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50571E0224393C2600F76F6C /* JustUpdatedChecker.swift */; };
@ -204,6 +205,7 @@
/* Begin PBXFileReference section */
50020BAF24064869003D4025 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
50153E1F250AFCB200525160 /* UpdateView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdateView.swift; sourceTree = "<group>"; };
5018F54E24064786002EB505 /* Notifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notifier.swift; sourceTree = "<group>"; };
50524B432420969D008DBD97 /* OpenSSHWriterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenSSHWriterTests.swift; sourceTree = "<group>"; };
50571E0224393C2600F76F6C /* JustUpdatedChecker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JustUpdatedChecker.swift; sourceTree = "<group>"; };
@ -501,6 +503,7 @@
50B8550C24138C4F009958AC /* DeleteSecretView.swift */,
50BB046A2418AAAE00D6E079 /* EmptyStoreView.swift */,
506772C82425BB8500034DED /* NoStoresView.swift */,
50153E1F250AFCB200525160 /* UpdateView.swift */,
50C385A8240B636500AF2719 /* SetupView.swift */,
);
path = Views;
@ -920,6 +923,7 @@
508A58B3241ED2180069DC07 /* AgentStatusChecker.swift in Sources */,
50C385A52407A76D00AF2719 /* SecretDetailView.swift in Sources */,
5099A02423FD2AAA0062B6F2 /* CreateSecretView.swift in Sources */,
50153E20250AFCB200525160 /* UpdateView.swift in Sources */,
50571E0524393D1500F76F6C /* LaunchAgentController.swift in Sources */,
50B8550D24138C4F009958AC /* DeleteSecretView.swift in Sources */,
50BB046B2418AAAE00D6E079 /* EmptyStoreView.swift in Sources */,

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
}
}