fix(mac): encode gateway params with protocol AnyCodable
This commit is contained in:
@@ -9,6 +9,9 @@ struct GatewayEvent: Codable {
|
|||||||
let seq: Int?
|
let seq: Int?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Avoid ambiguity with the app's own AnyCodable type.
|
||||||
|
private typealias ProtoAnyCodable = ClawdisProtocol.AnyCodable
|
||||||
|
|
||||||
extension Notification.Name {
|
extension Notification.Name {
|
||||||
static let gatewaySnapshot = Notification.Name("clawdis.gateway.snapshot")
|
static let gatewaySnapshot = Notification.Name("clawdis.gateway.snapshot")
|
||||||
static let gatewayEvent = Notification.Name("clawdis.gateway.event")
|
static let gatewayEvent = Notification.Name("clawdis.gateway.event")
|
||||||
@@ -203,14 +206,17 @@ private actor GatewayChannelActor {
|
|||||||
}
|
}
|
||||||
let id = UUID().uuidString
|
let id = UUID().uuidString
|
||||||
// Encode request using the generated models to avoid JSONSerialization/ObjC bridging pitfalls.
|
// Encode request using the generated models to avoid JSONSerialization/ObjC bridging pitfalls.
|
||||||
let paramsObject = params?.reduce(into: [String: AnyCodable]()) { dict, entry in
|
let paramsObject: ProtoAnyCodable? = params.map { entries in
|
||||||
dict[entry.key] = entry.value
|
let dict = entries.reduce(into: [String: ProtoAnyCodable]()) { dict, entry in
|
||||||
|
dict[entry.key] = ProtoAnyCodable(entry.value.value)
|
||||||
|
}
|
||||||
|
return ProtoAnyCodable(dict)
|
||||||
}
|
}
|
||||||
let frame = RequestFrame(
|
let frame = RequestFrame(
|
||||||
type: "req",
|
type: "req",
|
||||||
id: id,
|
id: id,
|
||||||
method: method,
|
method: method,
|
||||||
params: paramsObject.map { AnyCodable($0) })
|
params: paramsObject)
|
||||||
let data = try self.encoder.encode(frame)
|
let data = try self.encoder.encode(frame)
|
||||||
let response = try await withCheckedThrowingContinuation { (cont: CheckedContinuation<GatewayFrame, Error>) in
|
let response = try await withCheckedThrowingContinuation { (cont: CheckedContinuation<GatewayFrame, Error>) in
|
||||||
self.pending[id] = cont
|
self.pending[id] = cont
|
||||||
|
|||||||
Reference in New Issue
Block a user