Committed by
GitHub
Publish Windows implementation (#98)
* Publish Windows implementation * Adjusts CHANGELOG.md * Update workflow names * Add badges * Fix checks
Showing
17 changed files
with
90 additions
and
68 deletions
| @@ -16,16 +16,13 @@ on: | @@ -16,16 +16,13 @@ on: | ||
| 16 | 16 | ||
| 17 | jobs: | 17 | jobs: |
| 18 | analyze: | 18 | analyze: |
| 19 | - timeout-minutes: 7 | ||
| 20 | - runs-on: ${{ matrix.os }} | ||
| 21 | - name: Analysis of ${{ matrix.package }} (${{ matrix.channel }}; ${{ matrix.os }}) | 19 | + timeout-minutes: 11 |
| 20 | + runs-on: ubuntu-latest | ||
| 21 | + name: ${{ matrix.package }} analysis on ${{ matrix.channel }} | ||
| 22 | strategy: | 22 | strategy: |
| 23 | matrix: | 23 | matrix: |
| 24 | - os: | ||
| 25 | - - ubuntu-latest | ||
| 26 | channel: | 24 | channel: |
| 27 | - # Do not check stable until NNBD is on stable. | ||
| 28 | - #- 'stable' | 25 | + - 'stable' |
| 29 | - 'beta' | 26 | - 'beta' |
| 30 | - 'dev' | 27 | - 'dev' |
| 31 | package: | 28 | package: |
| @@ -33,6 +30,7 @@ jobs: | @@ -33,6 +30,7 @@ jobs: | ||
| 33 | - 'wakelock_macos' | 30 | - 'wakelock_macos' |
| 34 | - 'wakelock_platform_interface' | 31 | - 'wakelock_platform_interface' |
| 35 | - 'wakelock_web' | 32 | - 'wakelock_web' |
| 33 | + - 'wakelock_windows' | ||
| 36 | fail-fast: false | 34 | fail-fast: false |
| 37 | 35 | ||
| 38 | steps: | 36 | steps: |
| @@ -49,16 +47,15 @@ jobs: | @@ -49,16 +47,15 @@ jobs: | ||
| 49 | working-directory: ${{ matrix.package }} | 47 | working-directory: ${{ matrix.package }} |
| 50 | 48 | ||
| 51 | test: | 49 | test: |
| 52 | - timeout-minutes: 14 | 50 | + timeout-minutes: 16 |
| 53 | runs-on: macos-latest | 51 | runs-on: macos-latest |
| 54 | - name: Testing of ${{ matrix.package }} (${{ matrix.channel }}) | 52 | + name: ${{ matrix.package }} testing on ${{ matrix.channel }} |
| 55 | strategy: | 53 | strategy: |
| 56 | matrix: | 54 | matrix: |
| 57 | device: | 55 | device: |
| 58 | - - 'iPhone 12 Pro Max (14.2)' | 56 | + - 'iPhone 12 Pro Max (14.4)' |
| 59 | channel: | 57 | channel: |
| 60 | - # Do not check stable until NNBD is on stable. | ||
| 61 | - #- 'stable' | 58 | + - 'stable' |
| 62 | - 'beta' | 59 | - 'beta' |
| 63 | - 'dev' | 60 | - 'dev' |
| 64 | package: | 61 | package: |
| @@ -67,6 +64,7 @@ jobs: | @@ -67,6 +64,7 @@ jobs: | ||
| 67 | - 'wakelock_platform_interface' | 64 | - 'wakelock_platform_interface' |
| 68 | # Web tests do not work for now. | 65 | # Web tests do not work for now. |
| 69 | # - 'wakelock_web' | 66 | # - 'wakelock_web' |
| 67 | + - 'wakelock_windows' | ||
| 70 | fail-fast: false | 68 | fail-fast: false |
| 71 | 69 | ||
| 72 | steps: | 70 | steps: |
| @@ -18,7 +18,7 @@ jobs: | @@ -18,7 +18,7 @@ jobs: | ||
| 18 | configure: | 18 | configure: |
| 19 | timeout-minutes: 9 | 19 | timeout-minutes: 9 |
| 20 | runs-on: ubuntu-latest | 20 | runs-on: ubuntu-latest |
| 21 | - name: Configuration of ${{ matrix.package }} | 21 | + name: ${{ matrix.package }} configuration |
| 22 | strategy: | 22 | strategy: |
| 23 | matrix: | 23 | matrix: |
| 24 | package: | 24 | package: |
| @@ -26,6 +26,7 @@ jobs: | @@ -26,6 +26,7 @@ jobs: | ||
| 26 | - 'wakelock_macos' | 26 | - 'wakelock_macos' |
| 27 | - 'wakelock_platform_interface' | 27 | - 'wakelock_platform_interface' |
| 28 | - 'wakelock_web' | 28 | - 'wakelock_web' |
| 29 | + - 'wakelock_windows' | ||
| 29 | fail-fast: false | 30 | fail-fast: false |
| 30 | 31 | ||
| 31 | steps: | 32 | steps: |
| @@ -9,7 +9,7 @@ jobs: | @@ -9,7 +9,7 @@ jobs: | ||
| 9 | pana: | 9 | pana: |
| 10 | timeout-minutes: 9 | 10 | timeout-minutes: 9 |
| 11 | runs-on: ubuntu-latest | 11 | runs-on: ubuntu-latest |
| 12 | - name: Configuration of ${{ matrix.package }} | 12 | + name: ${{ matrix.package }} configuration |
| 13 | strategy: | 13 | strategy: |
| 14 | matrix: | 14 | matrix: |
| 15 | package: | 15 | package: |
| @@ -17,6 +17,7 @@ jobs: | @@ -17,6 +17,7 @@ jobs: | ||
| 17 | - 'wakelock_macos' | 17 | - 'wakelock_macos' |
| 18 | - 'wakelock_platform_interface' | 18 | - 'wakelock_platform_interface' |
| 19 | - 'wakelock_web' | 19 | - 'wakelock_web' |
| 20 | + - 'wakelock_windows' | ||
| 20 | fail-fast: false | 21 | fail-fast: false |
| 21 | 22 | ||
| 22 | steps: | 23 | steps: |
| @@ -30,7 +31,7 @@ jobs: | @@ -30,7 +31,7 @@ jobs: | ||
| 30 | needs: pana | 31 | needs: pana |
| 31 | timeout-minutes: 4 | 32 | timeout-minutes: 4 |
| 32 | runs-on: ubuntu-latest | 33 | runs-on: ubuntu-latest |
| 33 | - name: Publishing of ${{ matrix.package }} | 34 | + name: ${{ matrix.package }} publishing |
| 34 | strategy: | 35 | strategy: |
| 35 | matrix: | 36 | matrix: |
| 36 | package: | 37 | package: |
| @@ -38,6 +39,7 @@ jobs: | @@ -38,6 +39,7 @@ jobs: | ||
| 38 | - 'wakelock_macos' | 39 | - 'wakelock_macos' |
| 39 | - 'wakelock_platform_interface' | 40 | - 'wakelock_platform_interface' |
| 40 | - 'wakelock_web' | 41 | - 'wakelock_web' |
| 42 | + - 'wakelock_windows' | ||
| 41 | fail-fast: false | 43 | fail-fast: false |
| 42 | 44 | ||
| 43 | steps: | 45 | steps: |
| @@ -7,7 +7,7 @@ void main() { | @@ -7,7 +7,7 @@ void main() { | ||
| 7 | 7 | ||
| 8 | /// Example app widget demonstrating how to use the wakelock plugin. | 8 | /// Example app widget demonstrating how to use the wakelock plugin. |
| 9 | /// | 9 | /// |
| 10 | -/// The example implementation is located inside [OutlineButton.onPressed] | 10 | +/// The example implementation is located inside [OutlinedButton.onPressed] |
| 11 | /// callback functions and a [FutureBuilder]. | 11 | /// callback functions and a [FutureBuilder]. |
| 12 | class WakelockExampleApp extends StatefulWidget { | 12 | class WakelockExampleApp extends StatefulWidget { |
| 13 | @override | 13 | @override |
| @@ -29,7 +29,7 @@ class _WakelockExampleAppState extends State<WakelockExampleApp> { | @@ -29,7 +29,7 @@ class _WakelockExampleAppState extends State<WakelockExampleApp> { | ||
| 29 | const Spacer( | 29 | const Spacer( |
| 30 | flex: 3, | 30 | flex: 3, |
| 31 | ), | 31 | ), |
| 32 | - OutlineButton( | 32 | + OutlinedButton( |
| 33 | onPressed: () { | 33 | onPressed: () { |
| 34 | // The following code will enable the wakelock on the device | 34 | // The following code will enable the wakelock on the device |
| 35 | // using the wakelock plugin. | 35 | // using the wakelock plugin. |
| @@ -41,7 +41,7 @@ class _WakelockExampleAppState extends State<WakelockExampleApp> { | @@ -41,7 +41,7 @@ class _WakelockExampleAppState extends State<WakelockExampleApp> { | ||
| 41 | child: const Text('enable wakelock'), | 41 | child: const Text('enable wakelock'), |
| 42 | ), | 42 | ), |
| 43 | const Spacer(), | 43 | const Spacer(), |
| 44 | - OutlineButton( | 44 | + OutlinedButton( |
| 45 | onPressed: () { | 45 | onPressed: () { |
| 46 | // The following code will disable the wakelock on the device | 46 | // The following code will disable the wakelock on the device |
| 47 | // using the wakelock plugin. | 47 | // using the wakelock plugin. |
| @@ -32,7 +32,7 @@ dev_dependencies: | @@ -32,7 +32,7 @@ dev_dependencies: | ||
| 32 | integration_test: ^1.0.1 | 32 | integration_test: ^1.0.1 |
| 33 | test: any | 33 | test: any |
| 34 | 34 | ||
| 35 | - pedantic: ^1.10.0 | 35 | + pedantic: ^1.11.0 |
| 36 | 36 | ||
| 37 | dependency_overrides: | 37 | dependency_overrides: |
| 38 | # We override the platform dependencies of wakelock here because we use the example app for | 38 | # We override the platform dependencies of wakelock here because we use the example app for |
| @@ -40,9 +40,9 @@ dependency_overrides: | @@ -40,9 +40,9 @@ dependency_overrides: | ||
| 40 | # current platform implementations. | 40 | # current platform implementations. |
| 41 | wakelock_macos: | 41 | wakelock_macos: |
| 42 | path: ../../wakelock_macos | 42 | path: ../../wakelock_macos |
| 43 | - wakelock_windows: | ||
| 44 | - path: ../../wakelock_windows | ||
| 45 | wakelock_platform_interface: | 43 | wakelock_platform_interface: |
| 46 | path: ../../wakelock_platform_interface | 44 | path: ../../wakelock_platform_interface |
| 47 | wakelock_web: | 45 | wakelock_web: |
| 48 | path: ../../wakelock_web | 46 | path: ../../wakelock_web |
| 47 | + wakelock_windows: | ||
| 48 | + path: ../../wakelock_windows |
| @@ -21,10 +21,12 @@ var wakelockPlatformInstance = !kIsWeb && | @@ -21,10 +21,12 @@ var wakelockPlatformInstance = !kIsWeb && | ||
| 21 | // on web. | 21 | // on web. |
| 22 | Platform.isMacOS | 22 | Platform.isMacOS |
| 23 | ? WakelockMacOS() | 23 | ? WakelockMacOS() |
| 24 | - // This doesn't feel like the correct way to assign the windows implementation, | ||
| 25 | - // but platform channels aren't used due to the win32 package. | ||
| 26 | - // See this issue for details: https://github.com/flutter/flutter/issues/52267. | ||
| 27 | - : (!kIsWeb && Platform.isWindows ? WakelockWindows() : WakelockPlatformInterface.instance); | 24 | + // This doesn't feel like the correct way to assign the windows implementation, |
| 25 | + // but platform channels aren't used due to the win32 package. | ||
| 26 | + // See this issue for details: https://github.com/flutter/flutter/issues/52267. | ||
| 27 | + : (!kIsWeb && Platform.isWindows | ||
| 28 | + ? WakelockWindows() | ||
| 29 | + : WakelockPlatformInterface.instance); | ||
| 28 | 30 | ||
| 29 | /// Class providing all wakelock functionality using static members. | 31 | /// Class providing all wakelock functionality using static members. |
| 30 | /// | 32 | /// |
| 1 | name: wakelock_macos | 1 | name: wakelock_macos |
| 2 | -description: macOS platform implementation of the wakelock_platform_interface for the wakelock plugin. | 2 | +description: >-2 |
| 3 | + macOS platform implementation of the wakelock_platform_interface for the wakelock plugin. | ||
| 3 | version: 0.1.0 | 4 | version: 0.1.0 |
| 4 | homepage: https://github.com/creativecreatorormaybenot/wakelock/tree/master/wakelock_macos | 5 | homepage: https://github.com/creativecreatorormaybenot/wakelock/tree/master/wakelock_macos |
| 5 | 6 | ||
| @@ -19,10 +20,7 @@ dev_dependencies: | @@ -19,10 +20,7 @@ dev_dependencies: | ||
| 19 | flutter_test: | 20 | flutter_test: |
| 20 | sdk: flutter | 21 | sdk: flutter |
| 21 | 22 | ||
| 22 | - pedantic: ^1.10.0 | ||
| 23 | - | ||
| 24 | - wakelock: | ||
| 25 | - path: ../wakelock | 23 | + pedantic: ^1.11.0 |
| 26 | 24 | ||
| 27 | flutter: | 25 | flutter: |
| 28 | plugin: | 26 | plugin: |
| 1 | BSD 3-Clause License | 1 | BSD 3-Clause License |
| 2 | 2 | ||
| 3 | -Copyright (c) 2020-2021, creativecreatorormaybenot | 3 | +Copyright (c) 2021, creativecreatorormaybenot |
| 4 | All rights reserved. | 4 | All rights reserved. |
| 5 | 5 | ||
| 6 | Redistribution and use in source and binary forms, with or without | 6 | Redistribution and use in source and binary forms, with or without |
| 7 | modification, are permitted provided that the following conditions are met: | 7 | modification, are permitted provided that the following conditions are met: |
| 8 | 8 | ||
| 9 | 1. Redistributions of source code must retain the above copyright notice, this | 9 | 1. Redistributions of source code must retain the above copyright notice, this |
| 10 | -list of conditions and the following disclaimer. | 10 | + list of conditions and the following disclaimer. |
| 11 | 11 | ||
| 12 | 2. Redistributions in binary form must reproduce the above copyright notice, | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, |
| 13 | -this list of conditions and the following disclaimer in the documentation | ||
| 14 | -and/or other materials provided with the distribution. | 13 | + this list of conditions and the following disclaimer in the documentation |
| 14 | + and/or other materials provided with the distribution. | ||
| 15 | 15 | ||
| 16 | 3. Neither the name of the copyright holder nor the names of its | 16 | 3. Neither the name of the copyright holder nor the names of its |
| 17 | -contributors may be used to endorse or promote products derived from | ||
| 18 | -this software without specific prior written permission. | 17 | + contributors may be used to endorse or promote products derived from |
| 18 | + this software without specific prior written permission. | ||
| 19 | 19 | ||
| 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 1 | -# wakelock_windows | 1 | +# wakelock_windows [](https://pub.dev/packages/wakelock_windows) [](https://github.com/creativecreatorormaybenot/wakelock) [](https://twitter.com/creativemaybeno) |
| 2 | 2 | ||
| 3 | Windows platform implementation of the `wakelock_platform_interface` for the | 3 | Windows platform implementation of the `wakelock_platform_interface` for the |
| 4 | [wakelock plugin][wakelock GitHub]. | 4 | [wakelock plugin][wakelock GitHub]. |
| 5 | 5 | ||
| 6 | ## Getting started | 6 | ## Getting started |
| 7 | 7 | ||
| 8 | -If you want to use the wakelock plugin on Windows, see the [main `wakelock` plugin package](https://pub.dev/packages/wakelock). | 8 | +If you want to use the wakelock plugin on Windows, see the |
| 9 | +[main `wakelock` plugin package][wakelock Pub]. | ||
| 9 | 10 | ||
| 10 | ## Implementation | 11 | ## Implementation |
| 11 | 12 | ||
| 12 | -Note that the implementation does not use a `MethodChannel` implementation as relies on the win32 package. | 13 | +Note that the implementation does not use a `MethodChannel` implementation as it relies on the |
| 14 | +[win32 package][win32 Pub]. | ||
| 15 | + | ||
| 16 | +[wakelock GitHub]: https://github.com/creativecreatorormaybenot/wakelock | ||
| 17 | +[wakelock Pub]: https://pub.dev/packages/wakelock | ||
| 18 | +[win32 Pub]: https://pub.dev/packages/win32 |
| @@ -3,37 +3,42 @@ import 'dart:async'; | @@ -3,37 +3,42 @@ import 'dart:async'; | ||
| 3 | import 'package:wakelock_platform_interface/wakelock_platform_interface.dart'; | 3 | import 'package:wakelock_platform_interface/wakelock_platform_interface.dart'; |
| 4 | import 'package:win32/win32.dart'; | 4 | import 'package:win32/win32.dart'; |
| 5 | 5 | ||
| 6 | +/// Informs the system that the state being set should remain in effect until | ||
| 7 | +/// the next call that uses ES_CONTINUOUS and one of the other state flags is | ||
| 8 | +/// cleared. | ||
| 9 | +/// | ||
| 10 | +/// See https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate#parameters. | ||
| 6 | const _ES_CONTINUOUS = 0x80000000; | 11 | const _ES_CONTINUOUS = 0x80000000; |
| 7 | -const _ES_DISPLAY_REQUIRED = 0x00000002; | ||
| 8 | - | ||
| 9 | 12 | ||
| 10 | -/// The windows implementation of the [WakelockPlatformInterface]. | 13 | +/// Forces the display to be on by resetting the display idle timer. |
| 11 | /// | 14 | /// |
| 12 | -/// This class implements the `wakelock` plugin functionality for windows using | ||
| 13 | -/// SetThreadExecutionState from win32 api. | ||
| 14 | -/// | ||
| 15 | -/// https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate#parameters | 15 | +/// See https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate#parameters. |
| 16 | +const _ES_DISPLAY_REQUIRED = 0x00000002; | ||
| 17 | + | ||
| 18 | +/// The Windows implementation of the [WakelockPlatformInterface]. | ||
| 16 | /// | 19 | /// |
| 20 | +/// This class implements the `wakelock` plugin functionality for Windows using | ||
| 21 | +/// the `SetThreadExecutionState` win32 API (see https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate). | ||
| 17 | class WakelockWindows extends WakelockPlatformInterface { | 22 | class WakelockWindows extends WakelockPlatformInterface { |
| 18 | - bool _isEnabled = false; | 23 | + var _enabled = false; |
| 19 | 24 | ||
| 20 | @override | 25 | @override |
| 21 | Future<void> toggle({required bool enable}) async { | 26 | Future<void> toggle({required bool enable}) async { |
| 22 | - int response; | 27 | + final int response; |
| 23 | if (enable) { | 28 | if (enable) { |
| 24 | response = SetThreadExecutionState(_ES_CONTINUOUS | _ES_DISPLAY_REQUIRED); | 29 | response = SetThreadExecutionState(_ES_CONTINUOUS | _ES_DISPLAY_REQUIRED); |
| 25 | } else { | 30 | } else { |
| 26 | response = SetThreadExecutionState(_ES_CONTINUOUS); | 31 | response = SetThreadExecutionState(_ES_CONTINUOUS); |
| 27 | } | 32 | } |
| 28 | 33 | ||
| 29 | - // SetThreadExecutionState returns 0 if the operation failed | 34 | + // SetThreadExecutionState returns 0 if the operation failed. |
| 30 | if (response != 0) { | 35 | if (response != 0) { |
| 31 | - _isEnabled = enable; | 36 | + _enabled = enable; |
| 32 | } | 37 | } |
| 33 | } | 38 | } |
| 34 | 39 | ||
| 35 | @override | 40 | @override |
| 36 | - Future<bool> get enabled async => _isEnabled; | 41 | + Future<bool> get enabled async => _enabled; |
| 37 | 42 | ||
| 38 | @override | 43 | @override |
| 39 | bool get isMock => false; | 44 | bool get isMock => false; |
| 1 | name: wakelock_windows | 1 | name: wakelock_windows |
| 2 | -description: Windows platform implementation of the wakelock_platform_interface for the wakelock plugin. | 2 | +description: >-2 |
| 3 | + Windows platform implementation of the wakelock_platform_interface for the wakelock plugin. | ||
| 3 | version: 0.1.0 | 4 | version: 0.1.0 |
| 4 | 5 | ||
| 5 | environment: | 6 | environment: |
| 6 | - sdk: ">=2.12.0 <3.0.0" | ||
| 7 | - flutter: ">=2.0.0" | 7 | + sdk: '>=2.12.0 <3.0.0' |
| 8 | + flutter: '>=2.0.0' | ||
| 8 | 9 | ||
| 9 | dependencies: | 10 | dependencies: |
| 10 | flutter: | 11 | flutter: |
| 11 | sdk: flutter | 12 | sdk: flutter |
| 13 | + | ||
| 12 | wakelock_platform_interface: ^0.2.0 | 14 | wakelock_platform_interface: ^0.2.0 |
| 13 | win32: ^2.0.0 | 15 | win32: ^2.0.0 |
| 14 | 16 | ||
| @@ -16,4 +18,6 @@ dev_dependencies: | @@ -16,4 +18,6 @@ dev_dependencies: | ||
| 16 | flutter_test: | 18 | flutter_test: |
| 17 | sdk: flutter | 19 | sdk: flutter |
| 18 | 20 | ||
| 19 | - pedantic: ^1.10.0 | 21 | + pedantic: ^1.11.0 |
| 22 | + | ||
| 23 | +# todo: use dartPluginClass declaration once that lands on stable (https://github.com/flutter/flutter/issues/52267_ |
| 1 | +import 'package:flutter_test/flutter_test.dart'; | ||
| 2 | + | ||
| 3 | +void main() { | ||
| 4 | + // There are currently no unit tests for the Windows implementation as | ||
| 5 | + // testing for Windows is currently done using the integration tests in | ||
| 6 | + // wakelock/example. | ||
| 7 | + // This means that every change to the wakelock_windows package should be | ||
| 8 | + // tested using a local dependency in the wakelock example integration test | ||
| 9 | + // before being published. For that, we use dependency overrides in the | ||
| 10 | + // example app. | ||
| 11 | + test('stub', () { | ||
| 12 | + final acceptUnitTestingDefeat = true; | ||
| 13 | + expect(acceptUnitTestingDefeat, isTrue); | ||
| 14 | + }); | ||
| 15 | +} |
-
Please register or login to post a comment