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

Issue #18 #35

Merged
merged 2 commits into from
Mar 27, 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
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -15,7 +15,7 @@ private fun wrapResult(result: Any?): List<Any?> {
}

private fun wrapError(exception: Throwable): List<Any?> {
if (exception is FlutterError) {
if (exception is WakelockPlusFlutterError) {
return listOf(
exception.code,
exception.message,
Expand All @@ -36,7 +36,7 @@ private fun wrapError(exception: Throwable): List<Any?> {
* @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
Expand Down Expand Up @@ -133,7 +133,7 @@ interface WakelockPlusApi {
@Suppress("UNCHECKED_CAST")
fun setUp(binaryMessenger: BinaryMessenger, api: WakelockPlusApi?) {
run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.WakelockPlusApi.toggle", codec)
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.toggle", codec)
if (api != null) {
channel.setMessageHandler { message, reply ->
val args = message as List<Any?>
Expand All @@ -152,7 +152,7 @@ interface WakelockPlusApi {
}
}
run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.WakelockPlusApi.isEnabled", codec)
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.isEnabled", codec)
if (api != null) {
channel.setMessageHandler { _, reply ->
var wrapped: List<Any?>
Expand Down
2 changes: 1 addition & 1 deletion wakelock_plus/ios/Classes/WakelockPlusPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ @interface WakelockPlusPlugin () <FLTWakelockPlusApi>
@implementation WakelockPlusPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
WakelockPlusPlugin* instance = [[WakelockPlusPlugin alloc] init];
FLTWakelockPlusApiSetup(registrar.messenger, instance);
SetUpFLTWakelockPlusApi(registrar.messenger, instance);
}

- (void)toggleMsg:(FLTToggleMessage*)input error:(FlutterError**)error {
Expand Down
4 changes: 2 additions & 2 deletions wakelock_plus/ios/Classes/messages.g.h
Original file line number Diff line number Diff line change
@@ -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 <Foundation/Foundation.h>
Expand Down Expand Up @@ -34,6 +34,6 @@ NSObject<FlutterMessageCodec> *FLTWakelockPlusApiGetCodec(void);
- (nullable FLTIsEnabledMessage *)isEnabledWithError:(FlutterError *_Nullable *_Nonnull)error;
@end

extern void FLTWakelockPlusApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<FLTWakelockPlusApi> *_Nullable api);
extern void SetUpFLTWakelockPlusApi(id<FlutterBinaryMessenger> binaryMessenger, NSObject<FLTWakelockPlusApi> *_Nullable api);

NS_ASSUME_NONNULL_END
13 changes: 7 additions & 6 deletions wakelock_plus/ios/Classes/messages.g.m
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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;
Expand Down Expand Up @@ -54,7 +55,7 @@ + (nullable FLTToggleMessage *)nullableFromList:(NSArray *)list {
}
- (NSArray *)toList {
return @[
(self.enable ?: [NSNull null]),
self.enable ?: [NSNull null],
];
}
@end
Expand All @@ -75,7 +76,7 @@ + (nullable FLTIsEnabledMessage *)nullableFromList:(NSArray *)list {
}
- (NSArray *)toList {
return @[
(self.enabled ?: [NSNull null]),
self.enabled ?: [NSNull null],
];
}
@end
Expand Down Expand Up @@ -132,11 +133,11 @@ - (FlutterStandardReader *)readerWithData:(NSData *)data {
return sSharedObject;
}

void FLTWakelockPlusApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<FLTWakelockPlusApi> *api) {
void SetUpFLTWakelockPlusApi(id<FlutterBinaryMessenger> binaryMessenger, NSObject<FLTWakelockPlusApi> *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) {
Expand All @@ -155,7 +156,7 @@ void FLTWakelockPlusApiSetup(id<FlutterBinaryMessenger> 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) {
Expand Down
1 change: 1 addition & 0 deletions wakelock_plus/pigeons/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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',
))
Expand Down
4 changes: 2 additions & 2 deletions wakelock_plus/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
98 changes: 61 additions & 37 deletions wakelock_plus_platform_interface/lib/messages.g.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
// 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;

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<Object?> wrapResponse(
{Object? result, PlatformException? error, bool empty = false}) {
if (empty) {
return <Object?>[];
}
if (error == null) {
return <Object?>[result];
}
return <Object?>[error.code, error.message, error.details];
}

/// Message for toggling the wakelock on the platform side.
class ToggleMessage {
ToggleMessage({
Expand Down Expand Up @@ -85,56 +103,62 @@ 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<Object?> codec = _WakelockPlusApiCodec();

Future<void> toggle(ToggleMessage arg_msg) async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.WakelockPlusApi.toggle', codec,
binaryMessenger: _binaryMessenger);
final List<Object?>? replyList =
await channel.send(<Object?>[arg_msg]) as List<Object?>?;
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<Object?> pigeonChannelCodec =
_WakelockPlusApiCodec();

Future<void> toggle(ToggleMessage msg) async {
const String __pigeon_channelName =
'dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.toggle';
final BasicMessageChannel<Object?> __pigeon_channel =
BasicMessageChannel<Object?>(
__pigeon_channelName,
pigeonChannelCodec,
binaryMessenger: __pigeon_binaryMessenger,
);
final List<Object?>? __pigeon_replyList =
await __pigeon_channel.send(<Object?>[msg]) as List<Object?>?;
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;
}
}

Future<IsEnabledMessage> isEnabled() async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.WakelockPlusApi.isEnabled', codec,
binaryMessenger: _binaryMessenger);
final List<Object?>? replyList = await channel.send(null) as List<Object?>?;
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<Object?> __pigeon_channel =
BasicMessageChannel<Object?>(
__pigeon_channelName,
pigeonChannelCodec,
binaryMessenger: __pigeon_binaryMessenger,
);
final List<Object?>? __pigeon_replyList =
await __pigeon_channel.send(null) as List<Object?>?;
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?)!;
}
}
}
54 changes: 36 additions & 18 deletions wakelock_plus_platform_interface/test/messages.g.dart
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -41,7 +41,8 @@ class _TestWakelockPlusApiCodec extends StandardMessageCodec {
abstract class TestWakelockPlusApi {
static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding =>
TestDefaultBinaryMessengerBinding.instance;
static const MessageCodec<Object?> codec = _TestWakelockPlusApiCodec();
static const MessageCodec<Object?> pigeonChannelCodec =
_TestWakelockPlusApiCodec();

void toggle(ToggleMessage msg);

Expand All @@ -50,41 +51,58 @@ abstract class TestWakelockPlusApi {
static void setup(TestWakelockPlusApi? api,
{BinaryMessenger? binaryMessenger}) {
{
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.WakelockPlusApi.toggle', codec,
final BasicMessageChannel<Object?> __pigeon_channel = BasicMessageChannel<
Object?>(
'dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.toggle',
pigeonChannelCodec,
binaryMessenger: binaryMessenger);
if (api == null) {
_testBinaryMessengerBinding!.defaultBinaryMessenger
.setMockDecodedMessageHandler<Object?>(channel, null);
.setMockDecodedMessageHandler<Object?>(__pigeon_channel, null);
} else {
_testBinaryMessengerBinding!.defaultBinaryMessenger
.setMockDecodedMessageHandler<Object?>(channel,
.setMockDecodedMessageHandler<Object?>(__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<Object?> args = (message as List<Object?>?)!;
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 <Object?>[];
'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<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.WakelockPlusApi.isEnabled', codec,
final BasicMessageChannel<Object?> __pigeon_channel = BasicMessageChannel<
Object?>(
'dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.isEnabled',
pigeonChannelCodec,
binaryMessenger: binaryMessenger);
if (api == null) {
_testBinaryMessengerBinding!.defaultBinaryMessenger
.setMockDecodedMessageHandler<Object?>(channel, null);
.setMockDecodedMessageHandler<Object?>(__pigeon_channel, null);
} else {
_testBinaryMessengerBinding!.defaultBinaryMessenger
.setMockDecodedMessageHandler<Object?>(channel,
.setMockDecodedMessageHandler<Object?>(__pigeon_channel,
(Object? message) async {
// ignore message
final IsEnabledMessage output = api.isEnabled();
return <Object?>[output];
try {
final IsEnabledMessage output = api.isEnabled();
return <Object?>[output];
} on PlatformException catch (e) {
return wrapResponse(error: e);
} catch (e) {
return wrapResponse(
error: PlatformException(code: 'error', message: e.toString()));
}
});
}
}
Expand Down
Loading