mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-12-20 17:22:08 +03:00
Fixed channel deserialisation in iOS (#8386)
* Fixed channel * Change file
This commit is contained in:
parent
803c3a794d
commit
5848b4e8e9
5
.changes/fix-ios-channel.md
Normal file
5
.changes/fix-ios-channel.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"tauri": 'patch:enhance'
|
||||||
|
---
|
||||||
|
|
||||||
|
Fixed the deserialisation of a `Channel` in iOS.
|
@ -9,7 +9,7 @@ let channelDataKey = CodingUserInfoKey(rawValue: "sendChannelData")!
|
|||||||
|
|
||||||
public class Channel: Decodable {
|
public class Channel: Decodable {
|
||||||
public let id: UInt64
|
public let id: UInt64
|
||||||
let handler: (String) -> Void
|
let handler: (UInt64, String) -> Void
|
||||||
|
|
||||||
public required init(from decoder: Decoder) throws {
|
public required init(from decoder: Decoder) throws {
|
||||||
let container = try decoder.singleValueContainer()
|
let container = try decoder.singleValueContainer()
|
||||||
@ -30,7 +30,7 @@ public class Channel: Decodable {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let handler = decoder.userInfo[channelDataKey] as? (String) -> Void else {
|
guard let handler = decoder.userInfo[channelDataKey] as? (UInt64, String) -> Void else {
|
||||||
throw DecodingError.dataCorruptedError(
|
throw DecodingError.dataCorruptedError(
|
||||||
in: container,
|
in: container,
|
||||||
debugDescription: "missing userInfo for Channel handler. This is a Tauri issue"
|
debugDescription: "missing userInfo for Channel handler. This is a Tauri issue"
|
||||||
@ -54,12 +54,12 @@ public class Channel: Decodable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func send(_ data: JsonValue) {
|
public func send(_ data: JsonValue) {
|
||||||
handler(serialize(data))
|
handler(id, serialize(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
public func send<T: Encodable>(_ data: T) throws {
|
public func send<T: Encodable>(_ data: T) throws {
|
||||||
let json = try JSONEncoder().encode(data)
|
let json = try JSONEncoder().encode(data)
|
||||||
handler(String(decoding: json, as: UTF8.self))
|
handler(id, String(decoding: json, as: UTF8.self))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user