From f249932ff2989fa4e9a57c0f5f91b8e636e9d9b6 Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Fri, 31 Dec 2021 14:59:12 -0800 Subject: [PATCH] Quick prompting for stuff on debug/test builds (#296) --- Brief/Updater.swift | 5 +- Secretive/App.swift | 2 +- .../Controllers/AgentStatusChecker.swift | 7 +++ .../PreviewAgentStatusChecker.swift | 1 + .../Preview Content/PreviewUpdater.swift | 1 + Secretive/Views/ContentView.swift | 63 ++++++++++--------- 6 files changed, 48 insertions(+), 31 deletions(-) diff --git a/Brief/Updater.swift b/Brief/Updater.swift index 1d75a09..ded6b7a 100644 --- a/Brief/Updater.swift +++ b/Brief/Updater.swift @@ -4,12 +4,14 @@ import Combine public protocol UpdaterProtocol: ObservableObject { var update: Release? { get } - + var testBuild: Bool { get } } public class Updater: ObservableObject, UpdaterProtocol { @Published public var update: Release? + + public let testBuild: Bool private let osVersion: SemVer private let currentVersion: SemVer @@ -17,6 +19,7 @@ public class Updater: ObservableObject, UpdaterProtocol { public init(checkOnLaunch: Bool, osVersion: SemVer = SemVer(ProcessInfo.processInfo.operatingSystemVersion), currentVersion: SemVer = SemVer(Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "0.0.0")) { self.osVersion = osVersion self.currentVersion = currentVersion + testBuild = currentVersion == SemVer("0.0.0") if checkOnLaunch { // Don't do a launch check if the user hasn't seen the setup prompt explaining updater yet. checkForUpdates() diff --git a/Secretive/App.swift b/Secretive/App.swift index e12712d..afcc61b 100644 --- a/Secretive/App.swift +++ b/Secretive/App.swift @@ -36,7 +36,7 @@ struct Secretive: App { if agentStatusChecker.running && justUpdatedChecker.justUpdated { // Relaunch the agent, since it'll be running from earlier update still reinstallAgent() - } else if !agentStatusChecker.running { + } else if !agentStatusChecker.running && !agentStatusChecker.developmentBuild { forceLaunchAgent() } } diff --git a/Secretive/Controllers/AgentStatusChecker.swift b/Secretive/Controllers/AgentStatusChecker.swift index c8c0465..8f0602e 100644 --- a/Secretive/Controllers/AgentStatusChecker.swift +++ b/Secretive/Controllers/AgentStatusChecker.swift @@ -5,6 +5,7 @@ import SecretKit protocol AgentStatusCheckerProtocol: ObservableObject { var running: Bool { get } + var developmentBuild: Bool { get } } class AgentStatusChecker: ObservableObject, AgentStatusCheckerProtocol { @@ -36,6 +37,12 @@ class AgentStatusChecker: ObservableObject, AgentStatusCheckerProtocol { return nil } + + // Whether Secretive is being run in an Xcode environment. + var developmentBuild: Bool { + Bundle.main.bundleURL.absoluteString.contains("/Library/Developer/Xcode") + } + } diff --git a/Secretive/Preview Content/PreviewAgentStatusChecker.swift b/Secretive/Preview Content/PreviewAgentStatusChecker.swift index b2554d7..e893155 100644 --- a/Secretive/Preview Content/PreviewAgentStatusChecker.swift +++ b/Secretive/Preview Content/PreviewAgentStatusChecker.swift @@ -4,6 +4,7 @@ import Combine class PreviewAgentStatusChecker: AgentStatusCheckerProtocol { let running: Bool + let developmentBuild = false init(running: Bool = true) { self.running = running diff --git a/Secretive/Preview Content/PreviewUpdater.swift b/Secretive/Preview Content/PreviewUpdater.swift index 5ca16f0..a993d87 100644 --- a/Secretive/Preview Content/PreviewUpdater.swift +++ b/Secretive/Preview Content/PreviewUpdater.swift @@ -5,6 +5,7 @@ import Brief class PreviewUpdater: UpdaterProtocol { let update: Release? + let testBuild = false init(update: Update = .none) { switch update { diff --git a/Secretive/Views/ContentView.swift b/Secretive/Views/ContentView.swift index bc76728..33cb202 100644 --- a/Secretive/Views/ContentView.swift +++ b/Secretive/Views/ContentView.swift @@ -46,8 +46,13 @@ extension ContentView { text = "Critical Security Update Required" color = .red } else { - text = "Update Available" - color = .orange + if updater.testBuild { + text = "Test Build" + color = .blue + } else { + text = "Update Available" + color = .orange + } } return ToolbarItem { AnyView( @@ -58,11 +63,11 @@ extension ContentView { .font(.headline) .foregroundColor(.white) }) - .background(color) - .cornerRadius(5) - .popover(item: $selectedUpdate, attachmentAnchor: .point(.bottom), arrowEdge: .bottom) { update in - UpdateDetailView(update: update) - } + .background(color) + .cornerRadius(5) + .popover(item: $selectedUpdate, attachmentAnchor: .point(.bottom), arrowEdge: .bottom) { update in + UpdateDetailView(update: update) + } ) } } @@ -78,11 +83,11 @@ extension ContentView { }, label: { Image(systemName: "plus") }) - .popover(isPresented: $showingCreation, attachmentAnchor: .point(.bottom), arrowEdge: .bottom) { - if let modifiable = storeList.modifiableStore { - CreateSecretView(store: modifiable, showing: $showingCreation) + .popover(isPresented: $showingCreation, attachmentAnchor: .point(.bottom), arrowEdge: .bottom) { + if let modifiable = storeList.modifiableStore { + CreateSecretView(store: modifiable, showing: $showingCreation) + } } - } ) } @@ -92,7 +97,7 @@ extension ContentView { return ToolbarItem { AnyView( Group { - if runningSetup || !hasRunSetup || !agentStatusChecker.running { + if (runningSetup || !hasRunSetup || !agentStatusChecker.running) && !agentStatusChecker.developmentBuild { Button(action: { runningSetup = true }, label: { @@ -106,15 +111,15 @@ extension ContentView { .font(.headline) .foregroundColor(.white) }) - .background(Color.orange) - .cornerRadius(5) + .background(Color.orange) + .cornerRadius(5) } else { EmptyView() } } - .sheet(isPresented: $runningSetup) { - SetupView(visible: $runningSetup, setupComplete: $hasRunSetup) - } + .sheet(isPresented: $runningSetup) { + SetupView(visible: $runningSetup, setupComplete: $hasRunSetup) + } ) } } @@ -135,19 +140,19 @@ extension ContentView { .font(.headline) .foregroundColor(.white) }) - .background(Color.orange) - .cornerRadius(5) - .popover(isPresented: $showingAppPathNotice, attachmentAnchor: .point(.bottom), arrowEdge: .bottom) { - VStack { - Image(systemName: "exclamationmark.triangle") - .resizable() - .aspectRatio(contentMode: .fit) - .frame(width: 64) - Text("Secretive needs to be in your Applications folder to work properly. Please move it and relaunch.") - .frame(maxWidth: 300) + .background(Color.orange) + .cornerRadius(5) + .popover(isPresented: $showingAppPathNotice, attachmentAnchor: .point(.bottom), arrowEdge: .bottom) { + VStack { + Image(systemName: "exclamationmark.triangle") + .resizable() + .aspectRatio(contentMode: .fit) + .frame(width: 64) + Text("Secretive needs to be in your Applications folder to work properly. Please move it and relaunch.") + .frame(maxWidth: 300) + } + .padding() } - .padding() - } ) } }