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,7 +31,11 @@ public final class XPCServiceDelegate: NSObject, NSXPCListenerDelegate {
|
|||||||
let encoded = try JSONEncoder().encode(result)
|
let encoded = try JSONEncoder().encode(result)
|
||||||
reply(encoded, nil)
|
reply(encoded, nil)
|
||||||
} catch {
|
} catch {
|
||||||
reply(nil, error)
|
if let error = error as? Codable & Error {
|
||||||
|
reply(nil, NSError(error))
|
||||||
|
} else {
|
||||||
|
reply(nil, error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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,10 +32,12 @@ public struct XPCTypedSession<ResponseType: Codable & Sendable, ErrorType: Error
|
|||||||
}
|
}
|
||||||
let decoded = try JSONDecoder().decode(ResponseType.self, from: data)
|
let decoded = try JSONDecoder().decode(ResponseType.self, from: data)
|
||||||
continuation.resume(returning: decoded)
|
continuation.resume(returning: decoded)
|
||||||
} catch let error as ErrorType {
|
|
||||||
continuation.resume(throwing: error)
|
|
||||||
} catch {
|
} catch {
|
||||||
continuation.resume(throwing: error)
|
if let typed = (error as NSError).underlying(as: ErrorType.self) {
|
||||||
|
continuation.resume(throwing: typed)
|
||||||
|
} else {
|
||||||
|
continuation.resume(throwing: error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,6 @@ import Brief
|
|||||||
|
|
||||||
final class SecretiveUpdater: NSObject, XPCProtocol {
|
final class SecretiveUpdater: NSObject, XPCProtocol {
|
||||||
|
|
||||||
private let logger = Logger(subsystem: "com.maxgoedjen.secretive.ReleasesDownloader", category: "ReleasesDownloader")
|
|
||||||
|
|
||||||
enum Constants {
|
enum Constants {
|
||||||
static let updateURL = URL(string: "https://api.github.com/repos/maxgoedjen/secretive/releases")!
|
static let updateURL = URL(string: "https://api.github.com/repos/maxgoedjen/secretive/releases")!
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user