Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[quick_actions] Update to Pigeon 20 #6961

Merged
merged 5 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/quick_actions/quick_actions_ios/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.1

* Updates to a newer version of Pigeon.

## 1.1.0

* Adds Swift Package Manager compatibility.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MockFlutterApi: IOSQuickActionsFlutterApiProtocol {
var launchActionCallback: ((String) -> Void)? = nil

func launchAction(
action actionArg: String, completion: @escaping (Result<Void, FlutterError>) -> Void
action actionArg: String, completion: @escaping (Result<Void, PigeonError>) -> Void
) {
self.launchActionCallback?(actionArg)
completion(.success(Void()))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Autogenerated from Pigeon (v12.0.1), do not edit directly.
// Autogenerated from Pigeon (v20.0.1), do not edit directly.
// See also: https://pub.dev/packages/pigeon

import Foundation
Expand All @@ -14,17 +14,36 @@ import Foundation
#error("Unsupported platform.")
#endif

extension FlutterError: Error {}
/// Error class for passing custom error details to Dart side.
final class PigeonError: Error {
let code: String
let message: String?
let details: Any?

private func isNullish(_ value: Any?) -> Bool {
return value is NSNull || value == nil
init(code: String, message: String?, details: Any?) {
self.code = code
self.message = message
self.details = details
}

var localizedDescription: String {
return
"PigeonError(code: \(code), message: \(message ?? "<nil>"), details: \(details ?? "<nil>")"
}
}

private func wrapResult(_ result: Any?) -> [Any?] {
return [result]
}

private func wrapError(_ error: Any) -> [Any?] {
if let pigeonError = error as? PigeonError {
return [
pigeonError.code,
pigeonError.message,
pigeonError.details,
]
}
if let flutterError = error as? FlutterError {
return [
flutterError.code,
Expand All @@ -39,6 +58,16 @@ 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: "")
}

private func isNullish(_ value: Any?) -> Bool {
return value is NSNull || value == nil
}

private func nilOrValue<T>(_ value: Any?) -> T? {
if value is NSNull { return nil }
return value as! T?
Expand All @@ -55,10 +84,11 @@ struct ShortcutItemMessage {
/// Name of native resource to be displayed as the icon for this item.
var icon: String? = nil

static func fromList(_ list: [Any?]) -> ShortcutItemMessage? {
let type = list[0] as! String
let localizedTitle = list[1] as! String
let icon: String? = nilOrValue(list[2])
// swift-format-ignore: AlwaysUseLowerCamelCase
static func fromList(_ __pigeon_list: [Any?]) -> ShortcutItemMessage? {
let type = __pigeon_list[0] as! String
let localizedTitle = __pigeon_list[1] as! String
let icon: String? = nilOrValue(__pigeon_list[2])

return ShortcutItemMessage(
type: type,
Expand All @@ -74,40 +104,40 @@ struct ShortcutItemMessage {
]
}
}
private class IOSQuickActionsApiCodecReader: FlutterStandardReader {
private class messagesPigeonCodecReader: FlutterStandardReader {
override func readValue(ofType type: UInt8) -> Any? {
switch type {
case 128:
case 129:
return ShortcutItemMessage.fromList(self.readValue() as! [Any?])
default:
return super.readValue(ofType: type)
}
}
}

private class IOSQuickActionsApiCodecWriter: FlutterStandardWriter {
private class messagesPigeonCodecWriter: FlutterStandardWriter {
override func writeValue(_ value: Any) {
if let value = value as? ShortcutItemMessage {
super.writeByte(128)
super.writeByte(129)
super.writeValue(value.toList())
} else {
super.writeValue(value)
}
}
}

private class IOSQuickActionsApiCodecReaderWriter: FlutterStandardReaderWriter {
private class messagesPigeonCodecReaderWriter: FlutterStandardReaderWriter {
override func reader(with data: Data) -> FlutterStandardReader {
return IOSQuickActionsApiCodecReader(data: data)
return messagesPigeonCodecReader(data: data)
}

override func writer(with data: NSMutableData) -> FlutterStandardWriter {
return IOSQuickActionsApiCodecWriter(data: data)
return messagesPigeonCodecWriter(data: data)
}
}

class IOSQuickActionsApiCodec: FlutterStandardMessageCodec {
static let shared = IOSQuickActionsApiCodec(readerWriter: IOSQuickActionsApiCodecReaderWriter())
class messagesPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable {
static let shared = messagesPigeonCodec(readerWriter: messagesPigeonCodecReaderWriter())
}

/// Generated protocol from Pigeon that represents a handler of messages from Flutter.
Expand All @@ -120,13 +150,17 @@ protocol IOSQuickActionsApi {

/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
class IOSQuickActionsApiSetup {
/// The codec used by IOSQuickActionsApi.
static var codec: FlutterStandardMessageCodec { IOSQuickActionsApiCodec.shared }
static var codec: FlutterStandardMessageCodec { messagesPigeonCodec.shared }
/// Sets up an instance of `IOSQuickActionsApi` to handle messages through the `binaryMessenger`.
static func setUp(binaryMessenger: FlutterBinaryMessenger, api: IOSQuickActionsApi?) {
static func setUp(
binaryMessenger: FlutterBinaryMessenger, api: IOSQuickActionsApi?,
messageChannelSuffix: String = ""
) {
let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : ""
/// Sets the dynamic shortcuts for the app.
let setShortcutItemsChannel = FlutterBasicMessageChannel(
name: "dev.flutter.pigeon.quick_actions_ios.IOSQuickActionsApi.setShortcutItems",
name:
"dev.flutter.pigeon.quick_actions_ios.IOSQuickActionsApi.setShortcutItems\(channelSuffix)",
binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
setShortcutItemsChannel.setMessageHandler { message, reply in
Expand All @@ -144,7 +178,8 @@ class IOSQuickActionsApiSetup {
}
/// Removes all dynamic shortcuts.
let clearShortcutItemsChannel = FlutterBasicMessageChannel(
name: "dev.flutter.pigeon.quick_actions_ios.IOSQuickActionsApi.clearShortcutItems",
name:
"dev.flutter.pigeon.quick_actions_ios.IOSQuickActionsApi.clearShortcutItems\(channelSuffix)",
binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
clearShortcutItemsChannel.setMessageHandler { _, reply in
Expand All @@ -164,22 +199,39 @@ class IOSQuickActionsApiSetup {
protocol IOSQuickActionsFlutterApiProtocol {
/// Sends a string representing a shortcut from the native platform to the app.
func launchAction(
action actionArg: String, completion: @escaping (Result<Void, FlutterError>) -> Void)
action actionArg: String, completion: @escaping (Result<Void, PigeonError>) -> Void)
}
class IOSQuickActionsFlutterApi: IOSQuickActionsFlutterApiProtocol {
private let binaryMessenger: FlutterBinaryMessenger
init(binaryMessenger: FlutterBinaryMessenger) {
private let messageChannelSuffix: String
init(binaryMessenger: FlutterBinaryMessenger, messageChannelSuffix: String = "") {
self.binaryMessenger = binaryMessenger
self.messageChannelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : ""
}
var codec: messagesPigeonCodec {
return messagesPigeonCodec.shared
}
/// Sends a string representing a shortcut from the native platform to the app.
func launchAction(
action actionArg: String, completion: @escaping (Result<Void, FlutterError>) -> Void
action actionArg: String, completion: @escaping (Result<Void, PigeonError>) -> Void
) {
let channelName: String =
"dev.flutter.pigeon.quick_actions_ios.IOSQuickActionsFlutterApi.launchAction\(messageChannelSuffix)"
let channel = FlutterBasicMessageChannel(
name: "dev.flutter.pigeon.quick_actions_ios.IOSQuickActionsFlutterApi.launchAction",
binaryMessenger: binaryMessenger)
channel.sendMessage([actionArg] as [Any?]) { _ in
completion(.success(Void()))
name: channelName, binaryMessenger: binaryMessenger, codec: codec)
channel.sendMessage([actionArg] as [Any?]) { response in
guard let listResponse = response as? [Any?] else {
completion(.failure(createConnectionError(withChannelName: channelName)))
return
}
if listResponse.count > 1 {
let code: String = listResponse[0] as! String
let message: String? = nilOrValue(listResponse[1])
let details: String? = nilOrValue(listResponse[2])
completion(.failure(PigeonError(code: code, message: message, details: details)))
} else {
completion(.success(Void()))
}
}
}
}
Loading