mirror of
https://github.com/maxgoedjen/secretive.git
synced 2025-09-20 03:10:57 +00:00
Cleanup.
This commit is contained in:
parent
eaef1e801b
commit
fd0686be0c
@ -31,11 +31,15 @@ public final class XPCServiceDelegate: NSObject, NSXPCListenerDelegate {
|
||||
let encoded = try JSONEncoder().encode(result)
|
||||
reply(encoded, nil)
|
||||
} catch {
|
||||
if let error = error as? Codable & Error {
|
||||
reply(nil, NSError(error))
|
||||
} else {
|
||||
reply(nil, error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func process(_ data: Data, with reply: @Sendable @escaping (Data?, (any Error)?) -> Void) {
|
||||
_process(data, reply)
|
||||
@ -43,3 +47,24 @@ public final class XPCServiceDelegate: NSObject, NSXPCListenerDelegate {
|
||||
|
||||
|
||||
}
|
||||
|
||||
extension NSError {
|
||||
|
||||
private enum Constants {
|
||||
static let domain = "com.maxgoedjen.secretive.xpcwrappers"
|
||||
static let code = -1
|
||||
static let dataKey = "underlying"
|
||||
}
|
||||
|
||||
@nonobjc convenience init<ErrorType: Codable & Error>(_ error: ErrorType) {
|
||||
let encoded = try? JSONEncoder().encode(error)
|
||||
self.init(domain: Constants.domain, code: Constants.code, userInfo: [Constants.dataKey: encoded as Any])
|
||||
}
|
||||
|
||||
@nonobjc public func underlying<ErrorType: Codable & Error>(as errorType: ErrorType.Type) -> ErrorType? {
|
||||
guard domain == Constants.domain && code == Constants.code, let data = userInfo[Constants.dataKey] as? Data else { return nil }
|
||||
return try? JSONDecoder().decode(ErrorType.self, from: data)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -32,14 +32,16 @@ public struct XPCTypedSession<ResponseType: Codable & Sendable, ErrorType: Error
|
||||
}
|
||||
let decoded = try JSONDecoder().decode(ResponseType.self, from: data)
|
||||
continuation.resume(returning: decoded)
|
||||
} catch let error as ErrorType {
|
||||
continuation.resume(throwing: error)
|
||||
} catch {
|
||||
if let typed = (error as NSError).underlying(as: ErrorType.self) {
|
||||
continuation.resume(throwing: typed)
|
||||
} else {
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public func complete() {
|
||||
|
@ -5,8 +5,6 @@ import Brief
|
||||
|
||||
final class SecretiveUpdater: NSObject, XPCProtocol {
|
||||
|
||||
private let logger = Logger(subsystem: "com.maxgoedjen.secretive.ReleasesDownloader", category: "ReleasesDownloader")
|
||||
|
||||
enum Constants {
|
||||
static let updateURL = URL(string: "https://api.github.com/repos/maxgoedjen/secretive/releases")!
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user