secretive/Sources/Secretive/Controllers/UpdaterCommunicationControl...

41 lines
1.3 KiB
Swift
Raw Normal View History

2022-02-12 06:52:45 +00:00
import Foundation
import Combine
import AppKit
import OSLog
import SecretKit
2022-02-12 07:31:03 +00:00
//import SecretiveUpdater
import ServiceManagement
2022-02-12 06:52:45 +00:00
class UpdaterCommunicationController: ObservableObject {
private(set) var updater: UpdaterProtocol? = nil
private var connection: NSXPCConnection? = nil
private var running = false
init() {
}
func configure() {
guard !running else { return }
2022-02-12 07:31:03 +00:00
// 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")
2022-02-12 06:52:45 +00:00
connection?.remoteObjectInterface = NSXPCInterface(with: UpdaterProtocol.self)
connection?.invalidationHandler = {
Logger().warning("XPC connection invalidated")
}
connection?.resume()
updater = connection?.remoteObjectProxyWithErrorHandler({ error in
Logger().error("\(String(describing: error))")
}) as? UpdaterProtocol
2022-02-12 07:31:03 +00:00
Task {
print(try await updater?.installUpdate(url: URL(string: "https://google.com")!))
}
2022-02-12 06:52:45 +00:00
running = true
}
}