Quick prompting for stuff on debug/test builds (#296)

This commit is contained in:
Max Goedjen 2021-12-31 14:59:12 -08:00 committed by GitHub
parent 6eee29e1fa
commit f249932ff2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 48 additions and 31 deletions

View File

@ -4,19 +4,22 @@ import Combine
public protocol UpdaterProtocol: ObservableObject { public protocol UpdaterProtocol: ObservableObject {
var update: Release? { get } var update: Release? { get }
var testBuild: Bool { get }
} }
public class Updater: ObservableObject, UpdaterProtocol { public class Updater: ObservableObject, UpdaterProtocol {
@Published public var update: Release? @Published public var update: Release?
public let testBuild: Bool
private let osVersion: SemVer private let osVersion: SemVer
private let currentVersion: SemVer private let currentVersion: SemVer
public init(checkOnLaunch: Bool, osVersion: SemVer = SemVer(ProcessInfo.processInfo.operatingSystemVersion), currentVersion: SemVer = SemVer(Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "0.0.0")) { 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.osVersion = osVersion
self.currentVersion = currentVersion self.currentVersion = currentVersion
testBuild = currentVersion == SemVer("0.0.0")
if checkOnLaunch { if checkOnLaunch {
// Don't do a launch check if the user hasn't seen the setup prompt explaining updater yet. // Don't do a launch check if the user hasn't seen the setup prompt explaining updater yet.
checkForUpdates() checkForUpdates()

View File

@ -36,7 +36,7 @@ struct Secretive: App {
if agentStatusChecker.running && justUpdatedChecker.justUpdated { if agentStatusChecker.running && justUpdatedChecker.justUpdated {
// Relaunch the agent, since it'll be running from earlier update still // Relaunch the agent, since it'll be running from earlier update still
reinstallAgent() reinstallAgent()
} else if !agentStatusChecker.running { } else if !agentStatusChecker.running && !agentStatusChecker.developmentBuild {
forceLaunchAgent() forceLaunchAgent()
} }
} }

View File

@ -5,6 +5,7 @@ import SecretKit
protocol AgentStatusCheckerProtocol: ObservableObject { protocol AgentStatusCheckerProtocol: ObservableObject {
var running: Bool { get } var running: Bool { get }
var developmentBuild: Bool { get }
} }
class AgentStatusChecker: ObservableObject, AgentStatusCheckerProtocol { class AgentStatusChecker: ObservableObject, AgentStatusCheckerProtocol {
@ -36,6 +37,12 @@ class AgentStatusChecker: ObservableObject, AgentStatusCheckerProtocol {
return nil return nil
} }
// Whether Secretive is being run in an Xcode environment.
var developmentBuild: Bool {
Bundle.main.bundleURL.absoluteString.contains("/Library/Developer/Xcode")
}
} }

View File

@ -4,6 +4,7 @@ import Combine
class PreviewAgentStatusChecker: AgentStatusCheckerProtocol { class PreviewAgentStatusChecker: AgentStatusCheckerProtocol {
let running: Bool let running: Bool
let developmentBuild = false
init(running: Bool = true) { init(running: Bool = true) {
self.running = running self.running = running

View File

@ -5,6 +5,7 @@ import Brief
class PreviewUpdater: UpdaterProtocol { class PreviewUpdater: UpdaterProtocol {
let update: Release? let update: Release?
let testBuild = false
init(update: Update = .none) { init(update: Update = .none) {
switch update { switch update {

View File

@ -45,10 +45,15 @@ extension ContentView {
if update.critical { if update.critical {
text = "Critical Security Update Required" text = "Critical Security Update Required"
color = .red color = .red
} else {
if updater.testBuild {
text = "Test Build"
color = .blue
} else { } else {
text = "Update Available" text = "Update Available"
color = .orange color = .orange
} }
}
return ToolbarItem { return ToolbarItem {
AnyView( AnyView(
Button(action: { Button(action: {
@ -92,7 +97,7 @@ extension ContentView {
return ToolbarItem { return ToolbarItem {
AnyView( AnyView(
Group { Group {
if runningSetup || !hasRunSetup || !agentStatusChecker.running { if (runningSetup || !hasRunSetup || !agentStatusChecker.running) && !agentStatusChecker.developmentBuild {
Button(action: { Button(action: {
runningSetup = true runningSetup = true
}, label: { }, label: {