diff --git a/wakelock/CHANGELOG.md b/wakelock/CHANGELOG.md index 9ab121a5..8423c9e9 100644 --- a/wakelock/CHANGELOG.md +++ b/wakelock/CHANGELOG.md @@ -1,3 +1,9 @@ +## 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. diff --git a/wakelock/android/src/main/java/creativemaybeno/wakelock/Messages.java b/wakelock/android/src/main/java/creativemaybeno/wakelock/Messages.java index 8a006016..966355dc 100644 --- a/wakelock/android/src/main/java/creativemaybeno/wakelock/Messages.java +++ b/wakelock/android/src/main/java/creativemaybeno/wakelock/Messages.java @@ -1,4 +1,4 @@ -// 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 @@ 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 static class ToggleMessage { public Boolean getEnable() { return enable; } public void setEnable(Boolean setterArg) { this.enable = setterArg; } - HashMap toMap() { - HashMap toMapResult = new HashMap<>(); + Map toMap() { + Map toMapResult = new HashMap<>(); toMapResult.put("enable", enable); return toMapResult; } - static ToggleMessage fromMap(HashMap map) { + static ToggleMessage fromMap(Map map) { ToggleMessage fromMapResult = new ToggleMessage(); Object enable = map.get("enable"); fromMapResult.enable = (Boolean)enable; @@ -38,12 +39,12 @@ public static class IsEnabledMessage { public Boolean getEnabled() { return enabled; } public void setEnabled(Boolean setterArg) { this.enabled = setterArg; } - HashMap toMap() { - HashMap toMapResult = new HashMap<>(); + Map toMap() { + Map toMapResult = new HashMap<>(); toMapResult.put("enabled", enabled); return toMapResult; } - static IsEnabledMessage fromMap(HashMap map) { + static IsEnabledMessage fromMap(Map map) { IsEnabledMessage fromMapResult = new IsEnabledMessage(); Object enabled = map.get("enabled"); fromMapResult.enabled = (Boolean)enabled; @@ -56,21 +57,21 @@ public interface WakelockApi { 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 channel = new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.WakelockApi.toggle", new StandardMessageCodec()); if (api != null) { channel.setMessageHandler((message, reply) -> { - HashMap wrapped = new HashMap<>(); + Map wrapped = new HashMap<>(); try { @SuppressWarnings("ConstantConditions") - ToggleMessage input = ToggleMessage.fromMap((HashMap)message); + ToggleMessage input = ToggleMessage.fromMap((Map)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 @@ static void setup(BinaryMessenger binaryMessenger, WakelockApi api) { new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.WakelockApi.isEnabled", new StandardMessageCodec()); if (api != null) { channel.setMessageHandler((message, reply) -> { - HashMap wrapped = new HashMap<>(); + Map 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 @@ static void setup(BinaryMessenger binaryMessenger, WakelockApi api) { } } } - private static HashMap wrapError(Exception exception) { - HashMap errorMap = new HashMap<>(); + private static Map wrapError(Throwable exception) { + Map errorMap = new HashMap<>(); errorMap.put("message", exception.toString()); errorMap.put("code", exception.getClass().getSimpleName()); errorMap.put("details", null); diff --git a/wakelock/android/src/main/kotlin/creativemaybeno/wakelock/Wakelock.kt b/wakelock/android/src/main/kotlin/creativemaybeno/wakelock/Wakelock.kt index c2af2b72..c06a50df 100644 --- a/wakelock/android/src/main/kotlin/creativemaybeno/wakelock/Wakelock.kt +++ b/wakelock/android/src/main/kotlin/creativemaybeno/wakelock/Wakelock.kt @@ -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 } } diff --git a/wakelock/ios/Classes/messages.h b/wakelock/ios/Classes/messages.h index 26c90caf..f93e1f7d 100644 --- a/wakelock/ios/Classes/messages.h +++ b/wakelock/ios/Classes/messages.h @@ -1,4 +1,4 @@ -// 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 @protocol FlutterBinaryMessenger; diff --git a/wakelock/ios/Classes/messages.m b/wakelock/ios/Classes/messages.m index d1d31e9b..a6eec747 100644 --- a/wakelock/ios/Classes/messages.m +++ b/wakelock/ios/Classes/messages.m @@ -1,4 +1,4 @@ -// 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 @@ -7,19 +7,19 @@ #error File requires ARC to be enabled. #endif -static NSDictionary* wrapResult(NSDictionary *result, FlutterError *error) { +static NSDictionary* 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 binaryMessenger, id-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: diff --git a/wakelock/test/wakelock_test.dart b/wakelock/test/wakelock_test.dart index cebe142d..f09a3a86 100644 --- a/wakelock/test/wakelock_test.dart +++ b/wakelock/test/wakelock_test.dart @@ -1,77 +1,9 @@ -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 = []; - 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', () {}); }