XPC updater POC

This commit is contained in:
Max Goedjen
2025-09-05 19:20:53 -07:00
parent 558ae15b2d
commit 029a4939fa
8 changed files with 385 additions and 25 deletions

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>XPCService</key>
<dict>
<key>ServiceType</key>
<string>Application</string>
</dict>
</dict>
</plist>

View File

@@ -0,0 +1,27 @@
import Foundation
import Brief
final class ReleasesDownloader: NSObject, ReleasesDownloaderProtocol {
@objc func downloadReleases(with reply: @escaping (Data?, (any Error)?) -> Void) {
Task {
do {
let (data, _) = try await URLSession.shared.data(from: Constants.updateURL)
let releases = try JSONDecoder().decode([Release].self, from: data)
print(releases)
let jsonOut = try JSONEncoder().encode(releases)
reply(jsonOut, nil)
} catch {
reply(nil, error)
}
}
}
}
extension ReleasesDownloader {
enum Constants {
static let updateURL = URL(string: "https://api.github.com/repos/maxgoedjen/secretive/releases")!
}
}

View File

@@ -0,0 +1,18 @@
import Foundation
import Brief
class ServiceDelegate: NSObject, NSXPCListenerDelegate {
func listener(_ listener: NSXPCListener, shouldAcceptNewConnection newConnection: NSXPCConnection) -> Bool {
newConnection.exportedInterface = NSXPCInterface(with: (any ReleasesDownloaderProtocol).self)
let exportedObject = ReleasesDownloader()
newConnection.exportedObject = exportedObject
newConnection.resume()
return true
}
}
let delegate = ServiceDelegate()
let listener = NSXPCListener.service()
listener.delegate = delegate
listener.resume()