Add GitHub update checker and installer

This commit is contained in:
世界
2026-03-30 23:02:42 +08:00
parent 6b790c7a80
commit 63d1d0fe3f
15 changed files with 1663 additions and 2 deletions
+34
View File
@@ -45,7 +45,41 @@ public class HTTPClient {
}
}
public func writeTo(_ url: String?, path: String, progress: ((Int64, Int64) -> Void)? = nil) throws {
#if DEBUG
precondition(!Thread.isMainThread, "HTTPClient.writeTo(...) must not be called on the main thread")
#endif
let request = client.newRequest()!
request.setUserAgent(HTTPClient.userAgent)
try request.setURL(url)
let response = try request.execute()
if let progress {
let handler = WriteToProgressHandler(progress)
try response.writeTo(withProgress: path, handler: handler)
} else {
try response.write(to: path)
}
}
public static func writeToAsync(_ url: String?, path: String, progress: ((Int64, Int64) -> Void)? = nil) async throws {
try await BlockingIO.run {
try HTTPClient().writeTo(url, path: path, progress: progress)
}
}
deinit {
client.close()
}
}
private class WriteToProgressHandler: NSObject, LibboxHTTPResponseWriteToProgressHandlerProtocol {
private let handler: (Int64, Int64) -> Void
init(_ handler: @escaping (Int64, Int64) -> Void) {
self.handler = handler
}
func update(_ progress: Int64, total: Int64) {
handler(progress, total)
}
}