From 851f9255d3895ae881aff5d2279217e94e381ab3 Mon Sep 17 00:00:00 2001 From: Diego Tori Date: Tue, 26 Mar 2024 13:14:57 -0400 Subject: [PATCH] Issue #18. Upgraded pigeon to latest version. Added custom error class name for Kotlin. --- .../plus/wakelock/Messages.g.kt | 10 +- .../ios/Classes/WakelockPlusPlugin.m | 2 +- wakelock_plus/ios/Classes/messages.g.h | 4 +- wakelock_plus/ios/Classes/messages.g.m | 13 +-- wakelock_plus/pigeons/messages.dart | 1 + wakelock_plus/pubspec.yaml | 4 +- .../lib/messages.g.dart | 96 +++++++++++-------- .../test/messages.g.dart | 63 ++++++------ 8 files changed, 108 insertions(+), 85 deletions(-) diff --git a/wakelock_plus/android/src/main/kotlin/dev/fluttercommunity/plus/wakelock/Messages.g.kt b/wakelock_plus/android/src/main/kotlin/dev/fluttercommunity/plus/wakelock/Messages.g.kt index 1e189d9..3044e0d 100644 --- a/wakelock_plus/android/src/main/kotlin/dev/fluttercommunity/plus/wakelock/Messages.g.kt +++ b/wakelock_plus/android/src/main/kotlin/dev/fluttercommunity/plus/wakelock/Messages.g.kt @@ -1,4 +1,4 @@ -// Autogenerated from Pigeon (v10.1.0), do not edit directly. +// Autogenerated from Pigeon (v17.2.0), do not edit directly. // See also: https://pub.dev/packages/pigeon @@ -15,7 +15,7 @@ private fun wrapResult(result: Any?): List { } private fun wrapError(exception: Throwable): List { - if (exception is FlutterError) { + if (exception is WakelockPlusFlutterError) { return listOf( exception.code, exception.message, @@ -36,7 +36,7 @@ private fun wrapError(exception: Throwable): List { * @property message The error message. * @property details The error details. Must be a datatype supported by the api codec. */ -class FlutterError ( +class WakelockPlusFlutterError ( val code: String, override val message: String? = null, val details: Any? = null @@ -133,7 +133,7 @@ interface WakelockPlusApi { @Suppress("UNCHECKED_CAST") fun setUp(binaryMessenger: BinaryMessenger, api: WakelockPlusApi?) { run { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.WakelockPlusApi.toggle", codec) + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.toggle", codec) if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List @@ -152,7 +152,7 @@ interface WakelockPlusApi { } } run { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.WakelockPlusApi.isEnabled", codec) + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.isEnabled", codec) if (api != null) { channel.setMessageHandler { _, reply -> var wrapped: List diff --git a/wakelock_plus/ios/Classes/WakelockPlusPlugin.m b/wakelock_plus/ios/Classes/WakelockPlusPlugin.m index 24965bb..9532863 100644 --- a/wakelock_plus/ios/Classes/WakelockPlusPlugin.m +++ b/wakelock_plus/ios/Classes/WakelockPlusPlugin.m @@ -11,7 +11,7 @@ @interface WakelockPlusPlugin () @implementation WakelockPlusPlugin + (void)registerWithRegistrar:(NSObject*)registrar { WakelockPlusPlugin* instance = [[WakelockPlusPlugin alloc] init]; - FLTWakelockPlusApiSetup(registrar.messenger, instance); + SetUpFLTWakelockPlusApi(registrar.messenger, instance); } - (void)toggleMsg:(FLTToggleMessage*)input error:(FlutterError**)error { diff --git a/wakelock_plus/ios/Classes/messages.g.h b/wakelock_plus/ios/Classes/messages.g.h index 38cca3a..43cb0e4 100644 --- a/wakelock_plus/ios/Classes/messages.g.h +++ b/wakelock_plus/ios/Classes/messages.g.h @@ -1,4 +1,4 @@ -// Autogenerated from Pigeon (v10.1.0), do not edit directly. +// Autogenerated from Pigeon (v17.2.0), do not edit directly. // See also: https://pub.dev/packages/pigeon #import @@ -34,6 +34,6 @@ NSObject *FLTWakelockPlusApiGetCodec(void); - (nullable FLTIsEnabledMessage *)isEnabledWithError:(FlutterError *_Nullable *_Nonnull)error; @end -extern void FLTWakelockPlusApiSetup(id binaryMessenger, NSObject *_Nullable api); +extern void SetUpFLTWakelockPlusApi(id binaryMessenger, NSObject *_Nullable api); NS_ASSUME_NONNULL_END diff --git a/wakelock_plus/ios/Classes/messages.g.m b/wakelock_plus/ios/Classes/messages.g.m index df93009..ab04a8f 100644 --- a/wakelock_plus/ios/Classes/messages.g.m +++ b/wakelock_plus/ios/Classes/messages.g.m @@ -1,4 +1,4 @@ -// Autogenerated from Pigeon (v10.1.0), do not edit directly. +// Autogenerated from Pigeon (v17.2.0), do not edit directly. // See also: https://pub.dev/packages/pigeon #import "messages.g.h" @@ -21,6 +21,7 @@ } return @[ result ?: [NSNull null] ]; } + static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) { id result = array[key]; return (result == [NSNull null]) ? nil : result; @@ -54,7 +55,7 @@ + (nullable FLTToggleMessage *)nullableFromList:(NSArray *)list { } - (NSArray *)toList { return @[ - (self.enable ?: [NSNull null]), + self.enable ?: [NSNull null], ]; } @end @@ -75,7 +76,7 @@ + (nullable FLTIsEnabledMessage *)nullableFromList:(NSArray *)list { } - (NSArray *)toList { return @[ - (self.enabled ?: [NSNull null]), + self.enabled ?: [NSNull null], ]; } @end @@ -132,11 +133,11 @@ - (FlutterStandardReader *)readerWithData:(NSData *)data { return sSharedObject; } -void FLTWakelockPlusApiSetup(id binaryMessenger, NSObject *api) { +void SetUpFLTWakelockPlusApi(id binaryMessenger, NSObject *api) { { FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.WakelockPlusApi.toggle" + initWithName:@"dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.toggle" binaryMessenger:binaryMessenger codec:FLTWakelockPlusApiGetCodec()]; if (api) { @@ -155,7 +156,7 @@ void FLTWakelockPlusApiSetup(id binaryMessenger, NSObjec { FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.WakelockPlusApi.isEnabled" + initWithName:@"dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.isEnabled" binaryMessenger:binaryMessenger codec:FLTWakelockPlusApiGetCodec()]; if (api) { diff --git a/wakelock_plus/pigeons/messages.dart b/wakelock_plus/pigeons/messages.dart index 7d32730..d1bcbfb 100644 --- a/wakelock_plus/pigeons/messages.dart +++ b/wakelock_plus/pigeons/messages.dart @@ -18,6 +18,7 @@ class IsEnabledMessage { objcOptions: ObjcOptions( prefix: 'FLT', ), + kotlinOptions: KotlinOptions(errorClassName: "WakelockPlusFlutterError"), kotlinOut: 'android/src/main/kotlin/dev/fluttercommunity/plus/wakelock/Messages.g.kt', )) diff --git a/wakelock_plus/pubspec.yaml b/wakelock_plus/pubspec.yaml index b0eddf8..b007a8a 100644 --- a/wakelock_plus/pubspec.yaml +++ b/wakelock_plus/pubspec.yaml @@ -31,8 +31,8 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter - flutter_lints: ^2.0.1 - pigeon: ^10.1.0 # dart run pigeon --input "pigeons/messages.dart" + flutter_lints: ^3.0.1 + pigeon: ^17.2.0 # dart run pigeon --input "pigeons/messages.dart" # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec diff --git a/wakelock_plus_platform_interface/lib/messages.g.dart b/wakelock_plus_platform_interface/lib/messages.g.dart index 00d1c54..ccf117c 100644 --- a/wakelock_plus_platform_interface/lib/messages.g.dart +++ b/wakelock_plus_platform_interface/lib/messages.g.dart @@ -1,6 +1,6 @@ -// Autogenerated from Pigeon (v10.1.0), do not edit directly. +// Autogenerated from Pigeon (v17.2.0), do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; @@ -8,6 +8,23 @@ import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; +PlatformException _createConnectionError(String channelName) { + return PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel: "$channelName".', + ); +} + +List wrapResponse({Object? result, PlatformException? error, bool empty = false}) { + if (empty) { + return []; + } + if (error == null) { + return [result]; + } + return [error.code, error.message, error.details]; +} + /// Message for toggling the wakelock on the platform side. class ToggleMessage { ToggleMessage({ @@ -70,9 +87,9 @@ class _WakelockPlusApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: + case 128: return IsEnabledMessage.decode(readValue(buffer)!); - case 129: + case 129: return ToggleMessage.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); @@ -85,27 +102,27 @@ class WakelockPlusApi { /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. WakelockPlusApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; - - static const MessageCodec codec = _WakelockPlusApiCodec(); - - Future toggle(ToggleMessage arg_msg) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.WakelockPlusApi.toggle', codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_msg]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + : __pigeon_binaryMessenger = binaryMessenger; + final BinaryMessenger? __pigeon_binaryMessenger; + + static const MessageCodec pigeonChannelCodec = _WakelockPlusApiCodec(); + + Future toggle(ToggleMessage msg) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.toggle'; + final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([msg]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); } else { return; @@ -113,28 +130,29 @@ class WakelockPlusApi { } Future isEnabled() async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.WakelockPlusApi.isEnabled', codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + const String __pigeon_channelName = 'dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.isEnabled'; + final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], ); - } else if (replyList[0] == null) { + } else if (__pigeon_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as IsEnabledMessage?)!; + return (__pigeon_replyList[0] as IsEnabledMessage?)!; } } } diff --git a/wakelock_plus_platform_interface/test/messages.g.dart b/wakelock_plus_platform_interface/test/messages.g.dart index 8a93d04..edd6475 100644 --- a/wakelock_plus_platform_interface/test/messages.g.dart +++ b/wakelock_plus_platform_interface/test/messages.g.dart @@ -1,6 +1,6 @@ -// Autogenerated from Pigeon (v10.1.0), do not edit directly. +// Autogenerated from Pigeon (v17.2.0), do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import, no_leading_underscores_for_local_identifiers // ignore_for_file: avoid_relative_lib_imports import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; @@ -28,9 +28,9 @@ class _TestWakelockPlusApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: + case 128: return IsEnabledMessage.decode(readValue(buffer)!); - case 129: + case 129: return ToggleMessage.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); @@ -39,52 +39,55 @@ class _TestWakelockPlusApiCodec extends StandardMessageCodec { } abstract class TestWakelockPlusApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec codec = _TestWakelockPlusApiCodec(); + static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => TestDefaultBinaryMessengerBinding.instance; + static const MessageCodec pigeonChannelCodec = _TestWakelockPlusApiCodec(); void toggle(ToggleMessage msg); IsEnabledMessage isEnabled(); - static void setup(TestWakelockPlusApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setup(TestWakelockPlusApi? api, {BinaryMessenger? binaryMessenger}) { { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.WakelockPlusApi.toggle', codec, + final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + 'dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.toggle', pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WakelockPlusApi.toggle was null.'); + 'Argument for dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.toggle was null.'); final List args = (message as List?)!; final ToggleMessage? arg_msg = (args[0] as ToggleMessage?); assert(arg_msg != null, - 'Argument for dev.flutter.pigeon.WakelockPlusApi.toggle was null, expected non-null ToggleMessage.'); - api.toggle(arg_msg!); - return []; + 'Argument for dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.toggle was null, expected non-null ToggleMessage.'); + try { + api.toggle(arg_msg!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse(error: PlatformException(code: 'error', message: e.toString())); + } }); } } { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.WakelockPlusApi.isEnabled', codec, + final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + 'dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.isEnabled', pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - // ignore message - final IsEnabledMessage output = api.isEnabled(); - return [output]; + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, (Object? message) async { + try { + final IsEnabledMessage output = api.isEnabled(); + return [output]; + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse(error: PlatformException(code: 'error', message: e.toString())); + } }); } }