From 535b5efe8e05297d63b42c16900c28f9a9f696e2 Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Thu, 10 Sep 2020 18:26:29 -0700 Subject: [PATCH] Changing update view. --- Secretive.xcodeproj/project.pbxproj | 4 ++ Secretive/Views/ContentView.swift | 54 ++++++++++++++------------ Secretive/Views/UpdateView.swift | 60 +++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 24 deletions(-) create mode 100644 Secretive/Views/UpdateView.swift diff --git a/Secretive.xcodeproj/project.pbxproj b/Secretive.xcodeproj/project.pbxproj index 6bc6521..2368731 100644 --- a/Secretive.xcodeproj/project.pbxproj +++ b/Secretive.xcodeproj/project.pbxproj @@ -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 = ""; }; + 50153E1F250AFCB200525160 /* UpdateView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdateView.swift; sourceTree = ""; }; 5018F54E24064786002EB505 /* Notifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notifier.swift; sourceTree = ""; }; 50524B432420969D008DBD97 /* OpenSSHWriterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenSSHWriterTests.swift; sourceTree = ""; }; 50571E0224393C2600F76F6C /* JustUpdatedChecker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JustUpdatedChecker.swift; sourceTree = ""; }; @@ -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 */, diff --git a/Secretive/Views/ContentView.swift b/Secretive/Views/ContentView.swift index f0412cc..59291ee 100644 --- a/Secretive/Views/ContentView.swift +++ b/Secretive/Views/ContentView.swift @@ -12,7 +12,8 @@ struct ContentView ToolbarItem { + func updateNotice() -> ToolbarItem { + 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 { // ToolbarItem { diff --git a/Secretive/Views/UpdateView.swift b/Secretive/Views/UpdateView.swift new file mode 100644 index 0000000..fafba04 --- /dev/null +++ b/Secretive/Views/UpdateView.swift @@ -0,0 +1,60 @@ +import SwiftUI +import Brief + +//struct UpdateView: 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 + } + +}