XPC to agent working

This commit is contained in:
Max Goedjen
2022-02-11 23:31:03 -08:00
parent b41c036ea0
commit ba1c4c1563
24 changed files with 1038 additions and 110 deletions

View File

@@ -24,9 +24,9 @@ struct Secretive: App {
@SceneBuilder var body: some Scene {
WindowGroup {
ContentView<Updater, AgentStatusChecker>(showingCreation: $showingCreation, runningSetup: $showingSetup, hasRunSetup: $hasRunSetup)
ContentView<UpdateChecker, AgentStatusChecker>(showingCreation: $showingCreation, runningSetup: $showingSetup, hasRunSetup: $hasRunSetup)
.environmentObject(storeList)
.environmentObject(Updater(checkOnLaunch: hasRunSetup))
.environmentObject(UpdateChecker(checkOnLaunch: hasRunSetup))
.environmentObject(agentStatusChecker)
.onAppear {
updaterController.configure()

View File

@@ -3,7 +3,8 @@ import Combine
import AppKit
import OSLog
import SecretKit
import SecretiveUpdater
//import SecretiveUpdater
import ServiceManagement
class UpdaterCommunicationController: ObservableObject {
@@ -16,7 +17,10 @@ class UpdaterCommunicationController: ObservableObject {
func configure() {
guard !running else { return }
connection = NSXPCConnection(serviceName: "com.maxgoedjen.SecretiveUpdater")
// 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")
connection?.remoteObjectInterface = NSXPCInterface(with: UpdaterProtocol.self)
connection?.invalidationHandler = {
Logger().warning("XPC connection invalidated")
@@ -25,6 +29,9 @@ 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
}

View File

@@ -2,7 +2,7 @@ import Foundation
import Combine
import Brief
class PreviewUpdater: UpdaterProtocol {
class PreviewUpdater: UpdateCheckerProtocol {
let update: Release?
let testBuild = false

View File

@@ -4,6 +4,10 @@
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.application-groups</key>
<array>
<string>$(TeamIdentifierPrefix)com.maxgoedjen.Secretive</string>
</array>
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
<key>com.apple.security.network.client</key>

View File

@@ -4,7 +4,7 @@ import SecureEnclaveSecretKit
import SmartCardSecretKit
import Brief
struct ContentView<UpdaterType: UpdaterProtocol, AgentStatusCheckerType: AgentStatusCheckerProtocol>: View {
struct ContentView<UpdaterType: UpdateCheckerProtocol, AgentStatusCheckerType: AgentStatusCheckerProtocol>: View {
@Binding var showingCreation: Bool
@Binding var runningSetup: Bool

View File

@@ -1,7 +1,7 @@
import SwiftUI
import Brief
struct UpdateDetailView<UpdaterType: Updater>: View {
struct UpdateDetailView<UpdaterType: UpdateChecker>: View {
@EnvironmentObject var updater: UpdaterType