creativecreatorormaybenot
Committed by GitHub

Update generated messages (#115)

* Migrate platform_interface to pigeon 0.2.1

* Format

* Fix Analysis

* Update SDK version constraints

* Update generated messages

* Add empty test
## 0.5.2
* Updated generated message handling.
* Updated generated messages in the platform interface, which fixed calling `setMockMessageHandler`.
* Updated `wakelock_` dependencies with updated Dart SDK constraints (`>=2.12.0`).
## 0.5.1+1
* Added Podspec to the `wakelock` package to avoid build issues on macOS.
... ...
// Autogenerated from Pigeon (v0.1.14), do not edit directly.
// Autogenerated from Pigeon (v0.2.1), do not edit directly.
// See also: https://pub.dev/packages/pigeon
package creativemaybeno.wakelock;
... ... @@ -6,11 +6,12 @@ package creativemaybeno.wakelock;
import io.flutter.plugin.common.BasicMessageChannel;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.StandardMessageCodec;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
/** Generated class from Pigeon. */
@SuppressWarnings("unused")
@SuppressWarnings({"unused", "unchecked", "CodeBlock2Expr", "RedundantSuppression"})
public class Messages {
/** Generated class from Pigeon that represents data sent in messages. */
... ... @@ -19,12 +20,12 @@ public class Messages {
public Boolean getEnable() { return enable; }
public void setEnable(Boolean setterArg) { this.enable = setterArg; }
HashMap toMap() {
HashMap<String, Object> toMapResult = new HashMap<>();
Map<String, Object> toMap() {
Map<String, Object> toMapResult = new HashMap<>();
toMapResult.put("enable", enable);
return toMapResult;
}
static ToggleMessage fromMap(HashMap map) {
static ToggleMessage fromMap(Map<String, Object> map) {
ToggleMessage fromMapResult = new ToggleMessage();
Object enable = map.get("enable");
fromMapResult.enable = (Boolean)enable;
... ... @@ -38,12 +39,12 @@ public class Messages {
public Boolean getEnabled() { return enabled; }
public void setEnabled(Boolean setterArg) { this.enabled = setterArg; }
HashMap toMap() {
HashMap<String, Object> toMapResult = new HashMap<>();
Map<String, Object> toMap() {
Map<String, Object> toMapResult = new HashMap<>();
toMapResult.put("enabled", enabled);
return toMapResult;
}
static IsEnabledMessage fromMap(HashMap map) {
static IsEnabledMessage fromMap(Map<String, Object> map) {
IsEnabledMessage fromMapResult = new IsEnabledMessage();
Object enabled = map.get("enabled");
fromMapResult.enabled = (Boolean)enabled;
... ... @@ -56,21 +57,21 @@ public class Messages {
void toggle(ToggleMessage arg);
IsEnabledMessage isEnabled();
/** Sets up an instance of `WakelockApi` to handle messages through the `binaryMessenger` */
/** Sets up an instance of `WakelockApi` to handle messages through the `binaryMessenger`. */
static void setup(BinaryMessenger binaryMessenger, WakelockApi api) {
{
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.WakelockApi.toggle", new StandardMessageCodec());
if (api != null) {
channel.setMessageHandler((message, reply) -> {
HashMap<String, HashMap> wrapped = new HashMap<>();
Map<String, Object> wrapped = new HashMap<>();
try {
@SuppressWarnings("ConstantConditions")
ToggleMessage input = ToggleMessage.fromMap((HashMap)message);
ToggleMessage input = ToggleMessage.fromMap((Map<String, Object>)message);
api.toggle(input);
wrapped.put("result", null);
}
catch (Exception exception) {
catch (Error | RuntimeException exception) {
wrapped.put("error", wrapError(exception));
}
reply.reply(wrapped);
... ... @@ -84,12 +85,12 @@ public class Messages {
new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.WakelockApi.isEnabled", new StandardMessageCodec());
if (api != null) {
channel.setMessageHandler((message, reply) -> {
HashMap<String, HashMap> wrapped = new HashMap<>();
Map<String, Object> wrapped = new HashMap<>();
try {
IsEnabledMessage output = api.isEnabled();
wrapped.put("result", output.toMap());
}
catch (Exception exception) {
catch (Error | RuntimeException exception) {
wrapped.put("error", wrapError(exception));
}
reply.reply(wrapped);
... ... @@ -100,8 +101,8 @@ public class Messages {
}
}
}
private static HashMap wrapError(Exception exception) {
HashMap<String, Object> errorMap = new HashMap<>();
private static Map<String, Object> wrapError(Throwable exception) {
Map<String, Object> errorMap = new HashMap<>();
errorMap.put("message", exception.toString());
errorMap.put("code", exception.getClass().getSimpleName());
errorMap.put("details", null);
... ...
... ... @@ -20,7 +20,7 @@ internal class Wakelock {
val activity = this.activity!!
val enabled = this.enabled
if (message.getEnable()!!) {
if (message.enable!!) {
if (!enabled) activity.window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
} else if (enabled) {
activity.window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
... ... @@ -33,7 +33,7 @@ internal class Wakelock {
}
val msg = IsEnabledMessage()
msg.setEnabled(enabled)
msg.enabled = enabled
return msg
}
}
... ...
// Autogenerated from Pigeon (v0.1.14), do not edit directly.
// Autogenerated from Pigeon (v0.2.1), do not edit directly.
// See also: https://pub.dev/packages/pigeon
#import <Foundation/Foundation.h>
@protocol FlutterBinaryMessenger;
... ...
// Autogenerated from Pigeon (v0.1.14), do not edit directly.
// Autogenerated from Pigeon (v0.2.1), do not edit directly.
// See also: https://pub.dev/packages/pigeon
#import "messages.h"
#import <Flutter/Flutter.h>
... ... @@ -7,19 +7,19 @@
#error File requires ARC to be enabled.
#endif
static NSDictionary* wrapResult(NSDictionary *result, FlutterError *error) {
static NSDictionary<NSString*, id>* wrapResult(NSDictionary *result, FlutterError *error) {
NSDictionary *errorDict = (NSDictionary *)[NSNull null];
if (error) {
errorDict = [NSDictionary dictionaryWithObjectsAndKeys:
(error.code ? error.code : [NSNull null]), @"code",
(error.message ? error.message : [NSNull null]), @"message",
(error.details ? error.details : [NSNull null]), @"details",
nil];
errorDict = @{
@"code": (error.code ? error.code : [NSNull null]),
@"message": (error.message ? error.message : [NSNull null]),
@"details": (error.details ? error.details : [NSNull null]),
};
}
return [NSDictionary dictionaryWithObjectsAndKeys:
(result ? result : [NSNull null]), @"result",
errorDict, @"error",
nil];
return @{
@"result": (result ? result : [NSNull null]),
@"error": errorDict,
};
}
@interface FLTToggleMessage ()
... ... @@ -67,8 +67,8 @@ void FLTWakelockApiSetup(id<FlutterBinaryMessenger> binaryMessenger, id<FLTWakel
binaryMessenger:binaryMessenger];
if (api) {
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
FlutterError *error;
FLTToggleMessage *input = [FLTToggleMessage fromMap:message];
FlutterError *error;
[api toggle:input error:&error];
callback(wrapResult(nil, error));
}];
... ...
// This is fine because it is a dev dependency.
// See https://github.com/flutter/flutter/issues/71360.
// @dart=2.9
import 'package:pigeon/java_generator.dart';
import 'package:pigeon/objc_generator.dart';
import 'package:pigeon/pigeon.dart';
/// Message for toggling the wakelock on the platform side.
class ToggleMessage {
bool enable;
bool? enable;
}
/// Message for reporting the wakelock state from the platform side.
class IsEnabledMessage {
bool enabled;
bool? enabled;
}
@HostApi(dartHostTestHandler: 'TestWakelockApi')
... ... @@ -23,9 +22,12 @@ abstract class WakelockApi {
void configurePigeon(PigeonOptions options) {
options
..dartOut = '../wakelock_platform_interface/lib/messages.dart'
..dartTestOut = '../wakelock_platform_interface/test/messages.dart'
..objcHeaderOut = 'ios/Classes/messages.h'
..objcSourceOut = 'ios/Classes/messages.m'
..objcOptions.prefix = 'FLT'
..objcOptions = ObjcOptions()
..objcOptions?.prefix = 'FLT'
..javaOut = 'android/src/main/java/creativemaybeno/wakelock/Messages.java'
..javaOptions.package = 'creativemaybeno.wakelock';
..javaOptions = JavaOptions()
..javaOptions?.package = 'creativemaybeno.wakelock';
}
... ...
... ... @@ -2,7 +2,7 @@ name: wakelock
description: >-2
Plugin that allows you to keep the device screen awake, i.e. prevent the screen from sleeping on
Android, iOS, macOS, Windows, and web.
version: 0.5.1+1
version: 0.5.2
homepage: https://github.com/creativecreatorormaybenot/wakelock/tree/master/wakelock
environment:
... ... @@ -15,9 +15,9 @@ dependencies:
meta: ^1.2.0
wakelock_macos: ^0.1.0
wakelock_platform_interface: ^0.2.0
wakelock_web: ^0.2.0
wakelock_macos: ^0.1.0+1
wakelock_platform_interface: ^0.2.1+1
wakelock_web: ^0.2.0+1
wakelock_windows: ^0.1.0
dev_dependencies:
... ... @@ -25,7 +25,7 @@ dev_dependencies:
sdk: flutter
pedantic: ^1.11.0
pigeon: ^0.1.15
pigeon: ^0.2.1 # flutter pub run pigeon --input "pigeons/messages.dart"
flutter:
plugin:
... ...
import 'dart:io';
import 'package:flutter_test/flutter_test.dart';
import 'package:wakelock/wakelock.dart';
import 'package:wakelock_platform_interface/messages.dart';
import 'package:wakelock_platform_interface/wakelock_platform_interface.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
group('$Wakelock', () {
late FakeWakelockApi fakeWakelock;
setUpAll(() {
if (Platform.isMacOS) {
// See the member documentation for the reason behind this.
// todo(creativecreatorormaybenot): remove this once macOS is migrated
// todo| to pigeon.
wakelockPlatformInstance = WakelockPlatformInterface.instance;
}
fakeWakelock = FakeWakelockApi();
});
test('enable', () async {
await Wakelock.enable();
expect(fakeWakelock.calls.last, 'toggle');
expect(fakeWakelock.toggleMessage.enable, isTrue);
});
test('disable', () async {
await Wakelock.disable();
expect(fakeWakelock.calls.last, 'toggle');
expect(fakeWakelock.toggleMessage.enable, isFalse);
});
test('toggle', () async {
await Wakelock.toggle(enable: false);
expect(fakeWakelock.calls.last, 'toggle');
expect(fakeWakelock.toggleMessage.enable, isFalse);
await Wakelock.toggle(enable: true);
expect(fakeWakelock.calls.last, 'toggle');
expect(fakeWakelock.toggleMessage.enable, isTrue);
});
test('enabled', () async {
expect(Wakelock.enabled, completion(isTrue));
expect(fakeWakelock.calls.last, 'isEnabled');
});
});
}
class FakeWakelockApi extends TestWakelockApi {
FakeWakelockApi() {
TestWakelockApi.setup(this);
}
final calls = <String>[];
late ToggleMessage toggleMessage;
@override
IsEnabledMessage isEnabled() {
calls.add('isEnabled');
return IsEnabledMessage()..enabled = true;
}
@override
void toggle(ToggleMessage message) {
calls.add('toggle');
toggleMessage = message;
;
}
// There are no unit tests here as the API in this package only forwards the
// calls to the platform interface (unit tested) → platform implementations.
// Instead, this is all tested via e2e tests in the integration tests in the
// example app.
test('no unit tests', () {});
}
... ...