Skip to content

Commit

Permalink
Fixed channel deserialisation in iOS (tauri-apps#8386)
Browse files Browse the repository at this point in the history
* Fixed channel

* Change file
  • Loading branch information
guillemcordoba authored Dec 14, 2023
1 parent 803c3a7 commit 5848b4e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-ios-channel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": 'patch:enhance'
---

Fixed the deserialisation of a `Channel` in iOS.
8 changes: 4 additions & 4 deletions core/tauri/mobile/ios-api/Sources/Tauri/Channel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let channelDataKey = CodingUserInfoKey(rawValue: "sendChannelData")!

public class Channel: Decodable {
public let id: UInt64
let handler: (String) -> Void
let handler: (UInt64, String) -> Void

public required init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
Expand All @@ -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(
in: container,
debugDescription: "missing userInfo for Channel handler. This is a Tauri issue"
Expand All @@ -54,12 +54,12 @@ public class Channel: Decodable {
}

public func send(_ data: JsonValue) {
handler(serialize(data))
handler(id, serialize(data))
}

public func send<T: Encodable>(_ data: T) throws {
let json = try JSONEncoder().encode(data)
handler(String(decoding: json, as: UTF8.self))
handler(id, String(decoding: json, as: UTF8.self))
}

}

0 comments on commit 5848b4e

Please sign in to comment.