11// Copyright 2013 The Flutter Authors. All rights reserved.
22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
4- // Autogenerated from Pigeon (v12 .0.1), do not edit directly.
4+ // Autogenerated from Pigeon (v20 .0.1), do not edit directly.
55// See also: https://pub.dev/packages/pigeon
66
77import Foundation
@@ -14,17 +14,36 @@ import Foundation
1414 #error("Unsupported platform.")
1515#endif
1616
17- extension FlutterError : Error { }
17+ /// Error class for passing custom error details to Dart side.
18+ final class PigeonError : Error {
19+ let code : String
20+ let message : String ?
21+ let details : Any ?
1822
19- private func isNullish( _ value: Any ? ) -> Bool {
20- return value is NSNull || value == nil
23+ init ( code: String , message: String ? , details: Any ? ) {
24+ self . code = code
25+ self . message = message
26+ self . details = details
27+ }
28+
29+ var localizedDescription : String {
30+ return
31+ " PigeonError(code: \( code) , message: \( message ?? " <nil> " ) , details: \( details ?? " <nil> " ) "
32+ }
2133}
2234
2335private func wrapResult( _ result: Any ? ) -> [ Any ? ] {
2436 return [ result]
2537}
2638
2739private func wrapError( _ error: Any ) -> [ Any ? ] {
40+ if let pigeonError = error as? PigeonError {
41+ return [
42+ pigeonError. code,
43+ pigeonError. message,
44+ pigeonError. details,
45+ ]
46+ }
2847 if let flutterError = error as? FlutterError {
2948 return [
3049 flutterError. code,
@@ -39,6 +58,16 @@ private func wrapError(_ error: Any) -> [Any?] {
3958 ]
4059}
4160
61+ private func createConnectionError( withChannelName channelName: String ) -> PigeonError {
62+ return PigeonError (
63+ code: " channel-error " , message: " Unable to establish connection on channel: ' \( channelName) '. " ,
64+ details: " " )
65+ }
66+
67+ private func isNullish( _ value: Any ? ) -> Bool {
68+ return value is NSNull || value == nil
69+ }
70+
4271private func nilOrValue< T> ( _ value: Any ? ) -> T ? {
4372 if value is NSNull { return nil }
4473 return value as! T ?
@@ -55,10 +84,11 @@ struct ShortcutItemMessage {
5584 /// Name of native resource to be displayed as the icon for this item.
5685 var icon : String ? = nil
5786
58- static func fromList( _ list: [ Any ? ] ) -> ShortcutItemMessage ? {
59- let type = list [ 0 ] as! String
60- let localizedTitle = list [ 1 ] as! String
61- let icon : String ? = nilOrValue ( list [ 2 ] )
87+ // swift-format-ignore: AlwaysUseLowerCamelCase
88+ static func fromList( _ __pigeon_list: [ Any ? ] ) -> ShortcutItemMessage ? {
89+ let type = __pigeon_list [ 0 ] as! String
90+ let localizedTitle = __pigeon_list [ 1 ] as! String
91+ let icon : String ? = nilOrValue ( __pigeon_list [ 2 ] )
6292
6393 return ShortcutItemMessage (
6494 type: type,
@@ -74,40 +104,40 @@ struct ShortcutItemMessage {
74104 ]
75105 }
76106}
77- private class IOSQuickActionsApiCodecReader : FlutterStandardReader {
107+ private class messagesPigeonCodecReader : FlutterStandardReader {
78108 override func readValue( ofType type: UInt8 ) -> Any ? {
79109 switch type {
80- case 128 :
110+ case 129 :
81111 return ShortcutItemMessage . fromList ( self . readValue ( ) as! [ Any ? ] )
82112 default :
83113 return super. readValue ( ofType: type)
84114 }
85115 }
86116}
87117
88- private class IOSQuickActionsApiCodecWriter : FlutterStandardWriter {
118+ private class messagesPigeonCodecWriter : FlutterStandardWriter {
89119 override func writeValue( _ value: Any ) {
90120 if let value = value as? ShortcutItemMessage {
91- super. writeByte ( 128 )
121+ super. writeByte ( 129 )
92122 super. writeValue ( value. toList ( ) )
93123 } else {
94124 super. writeValue ( value)
95125 }
96126 }
97127}
98128
99- private class IOSQuickActionsApiCodecReaderWriter : FlutterStandardReaderWriter {
129+ private class messagesPigeonCodecReaderWriter : FlutterStandardReaderWriter {
100130 override func reader( with data: Data ) -> FlutterStandardReader {
101- return IOSQuickActionsApiCodecReader ( data: data)
131+ return messagesPigeonCodecReader ( data: data)
102132 }
103133
104134 override func writer( with data: NSMutableData ) -> FlutterStandardWriter {
105- return IOSQuickActionsApiCodecWriter ( data: data)
135+ return messagesPigeonCodecWriter ( data: data)
106136 }
107137}
108138
109- class IOSQuickActionsApiCodec : FlutterStandardMessageCodec {
110- static let shared = IOSQuickActionsApiCodec ( readerWriter: IOSQuickActionsApiCodecReaderWriter ( ) )
139+ class messagesPigeonCodec : FlutterStandardMessageCodec , @ unchecked Sendable {
140+ static let shared = messagesPigeonCodec ( readerWriter: messagesPigeonCodecReaderWriter ( ) )
111141}
112142
113143/// Generated protocol from Pigeon that represents a handler of messages from Flutter.
@@ -120,13 +150,17 @@ protocol IOSQuickActionsApi {
120150
121151/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
122152class IOSQuickActionsApiSetup {
123- /// The codec used by IOSQuickActionsApi.
124- static var codec : FlutterStandardMessageCodec { IOSQuickActionsApiCodec . shared }
153+ static var codec : FlutterStandardMessageCodec { messagesPigeonCodec. shared }
125154 /// Sets up an instance of `IOSQuickActionsApi` to handle messages through the `binaryMessenger`.
126- static func setUp( binaryMessenger: FlutterBinaryMessenger , api: IOSQuickActionsApi ? ) {
155+ static func setUp(
156+ binaryMessenger: FlutterBinaryMessenger , api: IOSQuickActionsApi ? ,
157+ messageChannelSuffix: String = " "
158+ ) {
159+ let channelSuffix = messageChannelSuffix. count > 0 ? " . \( messageChannelSuffix) " : " "
127160 /// Sets the dynamic shortcuts for the app.
128161 let setShortcutItemsChannel = FlutterBasicMessageChannel (
129- name: " dev.flutter.pigeon.quick_actions_ios.IOSQuickActionsApi.setShortcutItems " ,
162+ name:
163+ " dev.flutter.pigeon.quick_actions_ios.IOSQuickActionsApi.setShortcutItems \( channelSuffix) " ,
130164 binaryMessenger: binaryMessenger, codec: codec)
131165 if let api = api {
132166 setShortcutItemsChannel. setMessageHandler { message, reply in
@@ -144,7 +178,8 @@ class IOSQuickActionsApiSetup {
144178 }
145179 /// Removes all dynamic shortcuts.
146180 let clearShortcutItemsChannel = FlutterBasicMessageChannel (
147- name: " dev.flutter.pigeon.quick_actions_ios.IOSQuickActionsApi.clearShortcutItems " ,
181+ name:
182+ " dev.flutter.pigeon.quick_actions_ios.IOSQuickActionsApi.clearShortcutItems \( channelSuffix) " ,
148183 binaryMessenger: binaryMessenger, codec: codec)
149184 if let api = api {
150185 clearShortcutItemsChannel. setMessageHandler { _, reply in
@@ -164,22 +199,39 @@ class IOSQuickActionsApiSetup {
164199protocol IOSQuickActionsFlutterApiProtocol {
165200 /// Sends a string representing a shortcut from the native platform to the app.
166201 func launchAction(
167- action actionArg: String , completion: @escaping ( Result < Void , FlutterError > ) -> Void )
202+ action actionArg: String , completion: @escaping ( Result < Void , PigeonError > ) -> Void )
168203}
169204class IOSQuickActionsFlutterApi : IOSQuickActionsFlutterApiProtocol {
170205 private let binaryMessenger : FlutterBinaryMessenger
171- init ( binaryMessenger: FlutterBinaryMessenger ) {
206+ private let messageChannelSuffix : String
207+ init ( binaryMessenger: FlutterBinaryMessenger , messageChannelSuffix: String = " " ) {
172208 self . binaryMessenger = binaryMessenger
209+ self . messageChannelSuffix = messageChannelSuffix. count > 0 ? " . \( messageChannelSuffix) " : " "
210+ }
211+ var codec : messagesPigeonCodec {
212+ return messagesPigeonCodec. shared
173213 }
174214 /// Sends a string representing a shortcut from the native platform to the app.
175215 func launchAction(
176- action actionArg: String , completion: @escaping ( Result < Void , FlutterError > ) -> Void
216+ action actionArg: String , completion: @escaping ( Result < Void , PigeonError > ) -> Void
177217 ) {
218+ let channelName : String =
219+ " dev.flutter.pigeon.quick_actions_ios.IOSQuickActionsFlutterApi.launchAction \( messageChannelSuffix) "
178220 let channel = FlutterBasicMessageChannel (
179- name: " dev.flutter.pigeon.quick_actions_ios.IOSQuickActionsFlutterApi.launchAction " ,
180- binaryMessenger: binaryMessenger)
181- channel. sendMessage ( [ actionArg] as [ Any ? ] ) { _ in
182- completion ( . success( Void ( ) ) )
221+ name: channelName, binaryMessenger: binaryMessenger, codec: codec)
222+ channel. sendMessage ( [ actionArg] as [ Any ? ] ) { response in
223+ guard let listResponse = response as? [ Any ? ] else {
224+ completion ( . failure( createConnectionError ( withChannelName: channelName) ) )
225+ return
226+ }
227+ if listResponse. count > 1 {
228+ let code : String = listResponse [ 0 ] as! String
229+ let message : String ? = nilOrValue ( listResponse [ 1 ] )
230+ let details : String ? = nilOrValue ( listResponse [ 2 ] )
231+ completion ( . failure( PigeonError ( code: code, message: message, details: details) ) )
232+ } else {
233+ completion ( . success( Void ( ) ) )
234+ }
183235 }
184236 }
185237}
0 commit comments