mirror of
https://github.com/maxgoedjen/secretive.git
synced 2026-03-07 02:07:22 +01:00
XPC updater POC
This commit is contained in:
11
Sources/ReleasesDownloader/Info.plist
Normal file
11
Sources/ReleasesDownloader/Info.plist
Normal 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>
|
||||
27
Sources/ReleasesDownloader/ReleasesDownloader.swift
Normal file
27
Sources/ReleasesDownloader/ReleasesDownloader.swift
Normal 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")!
|
||||
}
|
||||
|
||||
}
|
||||
18
Sources/ReleasesDownloader/main.swift
Normal file
18
Sources/ReleasesDownloader/main.swift
Normal 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()
|
||||
Reference in New Issue
Block a user