1
1
// Copyright 2013 The Flutter Authors. All rights reserved.
2
2
// Use of this source code is governed by a BSD-style license that can be
3
3
// 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.
5
5
// See also: https://pub.dev/packages/pigeon
6
6
7
7
import Foundation
@@ -14,17 +14,36 @@ import Foundation
14
14
#error("Unsupported platform.")
15
15
#endif
16
16
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 ?
18
22
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
+ }
21
33
}
22
34
23
35
private func wrapResult( _ result: Any ? ) -> [ Any ? ] {
24
36
return [ result]
25
37
}
26
38
27
39
private 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
+ }
28
47
if let flutterError = error as? FlutterError {
29
48
return [
30
49
flutterError. code,
@@ -39,6 +58,16 @@ private func wrapError(_ error: Any) -> [Any?] {
39
58
]
40
59
}
41
60
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
+
42
71
private func nilOrValue< T> ( _ value: Any ? ) -> T ? {
43
72
if value is NSNull { return nil }
44
73
return value as! T ?
@@ -55,10 +84,11 @@ struct ShortcutItemMessage {
55
84
/// Name of native resource to be displayed as the icon for this item.
56
85
var icon : String ? = nil
57
86
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 ] )
62
92
63
93
return ShortcutItemMessage (
64
94
type: type,
@@ -74,40 +104,40 @@ struct ShortcutItemMessage {
74
104
]
75
105
}
76
106
}
77
- private class IOSQuickActionsApiCodecReader : FlutterStandardReader {
107
+ private class messagesPigeonCodecReader : FlutterStandardReader {
78
108
override func readValue( ofType type: UInt8 ) -> Any ? {
79
109
switch type {
80
- case 128 :
110
+ case 129 :
81
111
return ShortcutItemMessage . fromList ( self . readValue ( ) as! [ Any ? ] )
82
112
default :
83
113
return super. readValue ( ofType: type)
84
114
}
85
115
}
86
116
}
87
117
88
- private class IOSQuickActionsApiCodecWriter : FlutterStandardWriter {
118
+ private class messagesPigeonCodecWriter : FlutterStandardWriter {
89
119
override func writeValue( _ value: Any ) {
90
120
if let value = value as? ShortcutItemMessage {
91
- super. writeByte ( 128 )
121
+ super. writeByte ( 129 )
92
122
super. writeValue ( value. toList ( ) )
93
123
} else {
94
124
super. writeValue ( value)
95
125
}
96
126
}
97
127
}
98
128
99
- private class IOSQuickActionsApiCodecReaderWriter : FlutterStandardReaderWriter {
129
+ private class messagesPigeonCodecReaderWriter : FlutterStandardReaderWriter {
100
130
override func reader( with data: Data ) -> FlutterStandardReader {
101
- return IOSQuickActionsApiCodecReader ( data: data)
131
+ return messagesPigeonCodecReader ( data: data)
102
132
}
103
133
104
134
override func writer( with data: NSMutableData ) -> FlutterStandardWriter {
105
- return IOSQuickActionsApiCodecWriter ( data: data)
135
+ return messagesPigeonCodecWriter ( data: data)
106
136
}
107
137
}
108
138
109
- class IOSQuickActionsApiCodec : FlutterStandardMessageCodec {
110
- static let shared = IOSQuickActionsApiCodec ( readerWriter: IOSQuickActionsApiCodecReaderWriter ( ) )
139
+ class messagesPigeonCodec : FlutterStandardMessageCodec , @ unchecked Sendable {
140
+ static let shared = messagesPigeonCodec ( readerWriter: messagesPigeonCodecReaderWriter ( ) )
111
141
}
112
142
113
143
/// Generated protocol from Pigeon that represents a handler of messages from Flutter.
@@ -120,13 +150,17 @@ protocol IOSQuickActionsApi {
120
150
121
151
/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
122
152
class IOSQuickActionsApiSetup {
123
- /// The codec used by IOSQuickActionsApi.
124
- static var codec : FlutterStandardMessageCodec { IOSQuickActionsApiCodec . shared }
153
+ static var codec : FlutterStandardMessageCodec { messagesPigeonCodec. shared }
125
154
/// 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) " : " "
127
160
/// Sets the dynamic shortcuts for the app.
128
161
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) " ,
130
164
binaryMessenger: binaryMessenger, codec: codec)
131
165
if let api = api {
132
166
setShortcutItemsChannel. setMessageHandler { message, reply in
@@ -144,7 +178,8 @@ class IOSQuickActionsApiSetup {
144
178
}
145
179
/// Removes all dynamic shortcuts.
146
180
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) " ,
148
183
binaryMessenger: binaryMessenger, codec: codec)
149
184
if let api = api {
150
185
clearShortcutItemsChannel. setMessageHandler { _, reply in
@@ -164,22 +199,39 @@ class IOSQuickActionsApiSetup {
164
199
protocol IOSQuickActionsFlutterApiProtocol {
165
200
/// Sends a string representing a shortcut from the native platform to the app.
166
201
func launchAction(
167
- action actionArg: String , completion: @escaping ( Result < Void , FlutterError > ) -> Void )
202
+ action actionArg: String , completion: @escaping ( Result < Void , PigeonError > ) -> Void )
168
203
}
169
204
class IOSQuickActionsFlutterApi : IOSQuickActionsFlutterApiProtocol {
170
205
private let binaryMessenger : FlutterBinaryMessenger
171
- init ( binaryMessenger: FlutterBinaryMessenger ) {
206
+ private let messageChannelSuffix : String
207
+ init ( binaryMessenger: FlutterBinaryMessenger , messageChannelSuffix: String = " " ) {
172
208
self . binaryMessenger = binaryMessenger
209
+ self . messageChannelSuffix = messageChannelSuffix. count > 0 ? " . \( messageChannelSuffix) " : " "
210
+ }
211
+ var codec : messagesPigeonCodec {
212
+ return messagesPigeonCodec. shared
173
213
}
174
214
/// Sends a string representing a shortcut from the native platform to the app.
175
215
func launchAction(
176
- action actionArg: String , completion: @escaping ( Result < Void , FlutterError > ) -> Void
216
+ action actionArg: String , completion: @escaping ( Result < Void , PigeonError > ) -> Void
177
217
) {
218
+ let channelName : String =
219
+ " dev.flutter.pigeon.quick_actions_ios.IOSQuickActionsFlutterApi.launchAction \( messageChannelSuffix) "
178
220
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
+ }
183
235
}
184
236
}
185
237
}
0 commit comments