Skip to content

Commit

Permalink
issue(123867): format patch
Browse files Browse the repository at this point in the history
  • Loading branch information
feduke-nukem committed Dec 23, 2024
1 parent 7e81a6c commit 1fcc484
Show file tree
Hide file tree
Showing 9 changed files with 5,625 additions and 1,925 deletions.
2 changes: 1 addition & 1 deletion packages/pigeon/example/app/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private class PigeonApiImplementation: ExampleHostApi {
try? await Task.sleep(nanoseconds: 2_000_000_000)

if message.code == Code.one {
throw PigeonError(code: "code", message: "message", details: "details")
throw PigeonError(code: "code", message: "message", details: "details")
}

return true
Expand Down
21 changes: 11 additions & 10 deletions packages/pigeon/example/app/ios/Runner/EventChannelMessages.g.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ protocol PlatformEvent {
struct IntEvent: PlatformEvent {
var data: Int64


// swift-format-ignore: AlwaysUseLowerCamelCase
static func fromList(_ pigeonVar_list: [Any?]) -> IntEvent? {
let data = pigeonVar_list[0] as! Int64
Expand All @@ -53,7 +52,6 @@ struct IntEvent: PlatformEvent {
struct StringEvent: PlatformEvent {
var data: String


// swift-format-ignore: AlwaysUseLowerCamelCase
static func fromList(_ pigeonVar_list: [Any?]) -> StringEvent? {
let data = pigeonVar_list[0] as! String
Expand Down Expand Up @@ -107,11 +105,12 @@ private class EventChannelMessagesPigeonCodecReaderWriter: FlutterStandardReader
}

class EventChannelMessagesPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable {
static let shared = EventChannelMessagesPigeonCodec(readerWriter: EventChannelMessagesPigeonCodecReaderWriter())
static let shared = EventChannelMessagesPigeonCodec(
readerWriter: EventChannelMessagesPigeonCodecReaderWriter())
}

var eventChannelMessagesPigeonMethodCodec = FlutterStandardMethodCodec(readerWriter: EventChannelMessagesPigeonCodecReaderWriter());

var eventChannelMessagesPigeonMethodCodec = FlutterStandardMethodCodec(
readerWriter: EventChannelMessagesPigeonCodecReaderWriter())

private class PigeonStreamHandler<ReturnType>: NSObject, FlutterStreamHandler {
private let wrapper: PigeonEventChannelWrapper<ReturnType>
Expand Down Expand Up @@ -163,16 +162,18 @@ class PigeonEventSink<ReturnType> {
}

class StreamEventsStreamHandler: PigeonEventChannelWrapper<PlatformEvent> {
static func register(with messenger: FlutterBinaryMessenger,
instanceName: String = "",
streamHandler: StreamEventsStreamHandler) {
static func register(
with messenger: FlutterBinaryMessenger,
instanceName: String = "",
streamHandler: StreamEventsStreamHandler
) {
var channelName = "dev.flutter.pigeon.pigeon_example_package.EventChannelMethods.streamEvents"
if !instanceName.isEmpty {
channelName += ".\(instanceName)"
}
let internalStreamHandler = PigeonStreamHandler<PlatformEvent>(wrapper: streamHandler)
let channel = FlutterEventChannel(name: channelName, binaryMessenger: messenger, codec: eventChannelMessagesPigeonMethodCodec)
let channel = FlutterEventChannel(
name: channelName, binaryMessenger: messenger, codec: eventChannelMessagesPigeonMethodCodec)
channel.setStreamHandler(internalStreamHandler)
}
}

49 changes: 35 additions & 14 deletions packages/pigeon/example/app/ios/Runner/Messages.g.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class PigeonError: Error {
var localizedDescription: String {
return
"PigeonError(code: \(code), message: \(message ?? "<nil>"), details: \(details ?? "<nil>")"
}
}
}

private func wrapResult(_ result: Any?) -> [Any?] {
Expand Down Expand Up @@ -59,7 +59,9 @@ private func wrapError(_ error: Any) -> [Any?] {
}

private func createConnectionError(withChannelName channelName: String) -> PigeonError {
return PigeonError(code: "channel-error", message: "Unable to establish connection on channel: '\(channelName)'.", details: "")
return PigeonError(
code: "channel-error", message: "Unable to establish connection on channel: '\(channelName)'.",
details: "")
}

private func isNullish(_ value: Any?) -> Bool {
Expand All @@ -83,7 +85,6 @@ struct MessageData {
var code: Code
var data: [String: String]


// swift-format-ignore: AlwaysUseLowerCamelCase
static func fromList(_ pigeonVar_list: [Any?]) -> MessageData? {
let name: String? = nilOrValue(pigeonVar_list[0])
Expand Down Expand Up @@ -153,7 +154,6 @@ class MessagesPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable {
static let shared = MessagesPigeonCodec(readerWriter: MessagesPigeonCodecReaderWriter())
}


/// Generated protocol from Pigeon that represents a handler of messages from Flutter.
protocol ExampleHostApi {
func getHostLanguage() throws -> String
Expand All @@ -166,9 +166,14 @@ protocol ExampleHostApi {
class ExampleHostApiSetup {
static var codec: FlutterStandardMessageCodec { MessagesPigeonCodec.shared }
/// Sets up an instance of `ExampleHostApi` to handle messages through the `binaryMessenger`.
static func setUp(binaryMessenger: FlutterBinaryMessenger, api: ExampleHostApi?, messageChannelSuffix: String = "") {
static func setUp(
binaryMessenger: FlutterBinaryMessenger, api: ExampleHostApi?, messageChannelSuffix: String = ""
) {
let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : ""
let getHostLanguageChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.getHostLanguage\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
let getHostLanguageChannel = FlutterBasicMessageChannel(
name:
"dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.getHostLanguage\(channelSuffix)",
binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
getHostLanguageChannel.setMessageHandler { _, reply in
do {
Expand All @@ -181,7 +186,9 @@ class ExampleHostApiSetup {
} else {
getHostLanguageChannel.setMessageHandler(nil)
}
let addChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.add\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
let addChannel = FlutterBasicMessageChannel(
name: "dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.add\(channelSuffix)",
binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
addChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
Expand All @@ -197,7 +204,9 @@ class ExampleHostApiSetup {
} else {
addChannel.setMessageHandler(nil)
}
let sendMessageChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.sendMessage\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
let sendMessageChannel = FlutterBasicMessageChannel(
name: "dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.sendMessage\(channelSuffix)",
binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
sendMessageChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
Expand All @@ -214,7 +223,10 @@ class ExampleHostApiSetup {
} else {
sendMessageChannel.setMessageHandler(nil)
}
let sendMessageModernAsyncChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.sendMessageModernAsync\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
let sendMessageModernAsyncChannel = FlutterBasicMessageChannel(
name:
"dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.sendMessageModernAsync\(channelSuffix)",
binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
sendMessageModernAsyncChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
Expand All @@ -239,7 +251,8 @@ class ExampleHostApiSetup {
}
/// Generated protocol from Pigeon that represents Flutter messages that can be called from Swift.
protocol MessageFlutterApiProtocol {
func flutterMethod(aString aStringArg: String?, completion: @escaping (Result<String, PigeonError>) -> Void)
func flutterMethod(
aString aStringArg: String?, completion: @escaping (Result<String, PigeonError>) -> Void)
}
class MessageFlutterApi: MessageFlutterApiProtocol {
private let binaryMessenger: FlutterBinaryMessenger
Expand All @@ -251,9 +264,13 @@ class MessageFlutterApi: MessageFlutterApiProtocol {
var codec: MessagesPigeonCodec {
return MessagesPigeonCodec.shared
}
func flutterMethod(aString aStringArg: String?, completion: @escaping (Result<String, PigeonError>) -> Void) {
let channelName: String = "dev.flutter.pigeon.pigeon_example_package.MessageFlutterApi.flutterMethod\(messageChannelSuffix)"
let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec)
func flutterMethod(
aString aStringArg: String?, completion: @escaping (Result<String, PigeonError>) -> Void
) {
let channelName: String =
"dev.flutter.pigeon.pigeon_example_package.MessageFlutterApi.flutterMethod\(messageChannelSuffix)"
let channel = FlutterBasicMessageChannel(
name: channelName, binaryMessenger: binaryMessenger, codec: codec)
channel.sendMessage([aStringArg] as [Any?]) { response in
guard let listResponse = response as? [Any?] else {
completion(.failure(createConnectionError(withChannelName: channelName)))
Expand All @@ -265,7 +282,11 @@ class MessageFlutterApi: MessageFlutterApiProtocol {
let details: String? = nilOrValue(listResponse[2])
completion(.failure(PigeonError(code: code, message: message, details: details)))
} else if listResponse[0] == nil {
completion(.failure(PigeonError(code: "null-error", message: "Flutter api returned null value for non-null return value.", details: "")))
completion(
.failure(
PigeonError(
code: "null-error",
message: "Flutter api returned null value for non-null return value.", details: "")))
} else {
let result = listResponse[0] as! String
completion(.success(result))
Expand Down
Loading

0 comments on commit 1fcc484

Please sign in to comment.