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