mirror of
https://github.com/maxgoedjen/secretive.git
synced 2026-03-07 02:07:22 +01:00
Changing update view.
This commit is contained in:
@@ -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 {
|
||||
|
||||
60
Secretive/Views/UpdateView.swift
Normal file
60
Secretive/Views/UpdateView.swift
Normal 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
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user