This commit is contained in:
Max Goedjen
2022-02-16 22:02:57 -08:00
parent ba1c4c1563
commit 93b51f9e9b
9 changed files with 52 additions and 100 deletions

View File

@@ -29,19 +29,12 @@ struct Secretive: App {
.environmentObject(UpdateChecker(checkOnLaunch: hasRunSetup))
.environmentObject(agentStatusChecker)
.onAppear {
updaterController.configure()
updaterController.installUpdate(url: URL(string: "https://github.com/maxgoedjen/secretive/releases/download/v2.1.1/Secretive.zip")!)
if !hasRunSetup {
showingSetup = true
}
}
.onReceive(NotificationCenter.default.publisher(for: NSApplication.didBecomeActiveNotification)) { _ in
Task {
do {
let path = try await updaterController.updater?.installUpdate(url: URL(string: "https://github.com/maxgoedjen/secretive/releases/download/v2.1.1/Secretive.zip")!)
} catch {
print(error)
}
}
guard hasRunSetup else { return }
agentStatusChecker.check()
if agentStatusChecker.running && justUpdatedChecker.justUpdated {

View File

@@ -15,12 +15,11 @@ class UpdaterCommunicationController: ObservableObject {
init() {
}
func configure() {
func installUpdate(url: URL) {
guard !running else { return }
// TODO: Set disabled on launch. Only enable when I have an update to install.
let x = SMLoginItemSetEnabled("Z72PRUAWF6.com.maxgoedjen.SecretiveUpdater" as CFString, false)
let y = SMLoginItemSetEnabled("Z72PRUAWF6.com.maxgoedjen.SecretiveUpdater" as CFString, true)
connection = NSXPCConnection(machServiceName: "Z72PRUAWF6.com.maxgoedjen.SecretiveUpdater")
_ = SMLoginItemSetEnabled(Bundle.main.updaterBundleID as CFString, false)
SMLoginItemSetEnabled(Bundle.main.updaterBundleID as CFString, true)
connection = NSXPCConnection(machServiceName: Bundle.main.updaterBundleID)
connection?.remoteObjectInterface = NSXPCInterface(with: UpdaterProtocol.self)
connection?.invalidationHandler = {
Logger().warning("XPC connection invalidated")
@@ -29,10 +28,12 @@ class UpdaterCommunicationController: ObservableObject {
updater = connection?.remoteObjectProxyWithErrorHandler({ error in
Logger().error("\(String(describing: error))")
}) as? UpdaterProtocol
Task {
print(try await updater?.installUpdate(url: URL(string: "https://google.com")!))
}
running = true
let existingURL = Bundle.main.bundleURL
Task {
let result = try await updater?.installUpdate(url: url, to: existingURL)
print(result)
}
}
}

View File

@@ -4,4 +4,5 @@ import Foundation
extension Bundle {
public var agentBundleID: String {(self.bundleIdentifier?.replacingOccurrences(of: "Host", with: "SecretAgent"))!}
public var hostBundleID: String {(self.bundleIdentifier?.replacingOccurrences(of: "SecretAgent", with: "Host"))!}
public var updaterBundleID: String { "Z72PRUAWF6.com.maxgoedjen.SecretiveUpdater" }
}