Committed by
GitHub
Integrate wakelock_windows into wakelock (#101)
* Integrate wakelock_windows into wakelock * Fix wakelock_web
Showing
8 changed files
with
49 additions
and
26 deletions
| 1 | # Wakelock [](https://github.com/creativecreatorormaybenot/wakelock) [](https://pub.dev/packages/wakelock) [](https://twitter.com/creativemaybeno) | 1 | # Wakelock [](https://github.com/creativecreatorormaybenot/wakelock) [](https://pub.dev/packages/wakelock) [](https://twitter.com/creativemaybeno) |
| 2 | 2 | ||
| 3 | -Wakelock is Flutter plugin that allows you to keep the device screen awake, i.e. prevent the screen from sleeping. | 3 | +Wakelock is Flutter plugin that allows you to keep the device screen awake, i.e. prevent the screen |
| 4 | +from sleeping. | ||
| 4 | 5 | ||
| 5 | ## Supported platforms | 6 | ## Supported platforms |
| 6 | 7 | ||
| @@ -10,7 +11,7 @@ Wakelock is Flutter plugin that allows you to keep the device screen awake, i.e. | @@ -10,7 +11,7 @@ Wakelock is Flutter plugin that allows you to keep the device screen awake, i.e. | ||
| 10 | | iOS | ✅ | | 11 | | iOS | ✅ | |
| 11 | | Web | ✅ | | 12 | | Web | ✅ | |
| 12 | | macOS | ✅ | | 13 | | macOS | ✅ | |
| 13 | -| Windows | planned | | 14 | +| Windows | ✅ | |
| 14 | | Linux | planned | | 15 | | Linux | planned | |
| 15 | 16 | ||
| 16 | ## Getting started | 17 | ## Getting started |
| @@ -32,6 +33,7 @@ The packages in this repo are the following: | @@ -32,6 +33,7 @@ The packages in this repo are the following: | ||
| 32 | | [`wakelock_macos`](https://github.com/creativecreatorormaybenot/wakelock/tree/master/wakelock_macos) | macOS implementation | | 33 | | [`wakelock_macos`](https://github.com/creativecreatorormaybenot/wakelock/tree/master/wakelock_macos) | macOS implementation | |
| 33 | | [`wakelock_platform_interface`](https://github.com/creativecreatorormaybenot/wakelock/tree/master/wakelock_platform_interface) | Basic API definition & message handling | | 34 | | [`wakelock_platform_interface`](https://github.com/creativecreatorormaybenot/wakelock/tree/master/wakelock_platform_interface) | Basic API definition & message handling | |
| 34 | | [`wakelock_web`](https://github.com/creativecreatorormaybenot/wakelock/tree/master/wakelock_web) | Web implementation | | 35 | | [`wakelock_web`](https://github.com/creativecreatorormaybenot/wakelock/tree/master/wakelock_web) | Web implementation | |
| 36 | +| [`wakelock_web`](https://github.com/creativecreatorormaybenot/wakelock/tree/master/wakelock_windows) | Windows implementation | | ||
| 35 | 37 | ||
| 36 | ## Contributing | 38 | ## Contributing |
| 37 | 39 | ||
| @@ -40,7 +42,8 @@ If you want to contribute to this plugin, follow the [contributing guide](https: | @@ -40,7 +42,8 @@ If you want to contribute to this plugin, follow the [contributing guide](https: | ||
| 40 | ## Origin | 42 | ## Origin |
| 41 | 43 | ||
| 42 | Originally, this plugin was based on [`screen`](https://pub.dev/packages/screen). | 44 | Originally, this plugin was based on [`screen`](https://pub.dev/packages/screen). |
| 43 | -Specifically, the wakelock functionality was extracted into this plugin due to lack of maintenance by the author of the `screen` plugin. | 45 | +Specifically, the wakelock functionality was extracted into this plugin due to lack of maintenance |
| 46 | +by the author of the `screen` plugin. | ||
| 44 | 47 | ||
| 45 | -Today, the `wakelock` plugin has been completely refreshed (using latest Flutter standards and platform integration) with added support | ||
| 46 | -for web & macOS. | 48 | +Today, the `wakelock` plugin has been completely refreshed (using latest Flutter standards and |
| 49 | +platform integration) with added support for web, Windows, & macOS. |
| @@ -2,4 +2,6 @@ include: package:pedantic/analysis_options.yaml | @@ -2,4 +2,6 @@ include: package:pedantic/analysis_options.yaml | ||
| 2 | 2 | ||
| 3 | linter: | 3 | linter: |
| 4 | rules: | 4 | rules: |
| 5 | - - public_member_api_docs | 5 | + public_member_api_docs: true |
| 6 | + # Ignoring unsafe_html as we need to import a JS script in wakelock_web and because of https://github.com/dart-lang/sdk/issues/45230. | ||
| 7 | + unsafe_html: false |
| @@ -15,7 +15,7 @@ Essentially, this allows you to keep the device awake, i.e. prevent the device f | @@ -15,7 +15,7 @@ Essentially, this allows you to keep the device awake, i.e. prevent the device f | ||
| 15 | | iOS | ✅ | | 15 | | iOS | ✅ | |
| 16 | | Web | ✅ | | 16 | | Web | ✅ | |
| 17 | | macOS | ✅ | | 17 | | macOS | ✅ | |
| 18 | -| Windows | planned | | 18 | +| Windows | ✅ | |
| 19 | | Linux | planned | | 19 | | Linux | planned | |
| 20 | 20 | ||
| 21 | ## Usage | 21 | ## Usage |
| @@ -5,9 +5,9 @@ | @@ -5,9 +5,9 @@ | ||
| 5 | Pod::Spec.new do |s| | 5 | Pod::Spec.new do |s| |
| 6 | s.name = 'wakelock' | 6 | s.name = 'wakelock' |
| 7 | s.version = '0.0.1' | 7 | s.version = '0.0.1' |
| 8 | - s.summary = 'Plugin that allows you to keep the device screen awake, i.e. prevent the screen from sleeping on Android, iOS, macOS, and web.' | 8 | + s.summary = 'Plugin that allows you to keep the device screen awake, i.e. prevent the screen from sleeping on Android, iOS, macOS, Windows, and web.' |
| 9 | s.description = <<-DESC | 9 | s.description = <<-DESC |
| 10 | -Plugin that allows you to keep the device screen awake, i.e. prevent the screen from sleeping on Android, iOS, macOS, and web. | 10 | +Plugin that allows you to keep the device screen awake, i.e. prevent the screen from sleeping on Android, iOS, macOS, Windows, and web. |
| 11 | DESC | 11 | DESC |
| 12 | s.homepage = 'http://example.com' | 12 | s.homepage = 'http://example.com' |
| 13 | s.license = { :file => '../LICENSE' } | 13 | s.license = { :file => '../LICENSE' } |
| @@ -3,6 +3,7 @@ import 'dart:io'; | @@ -3,6 +3,7 @@ import 'dart:io'; | ||
| 3 | import 'package:flutter/foundation.dart'; | 3 | import 'package:flutter/foundation.dart'; |
| 4 | import 'package:wakelock_macos/wakelock_macos.dart'; | 4 | import 'package:wakelock_macos/wakelock_macos.dart'; |
| 5 | import 'package:wakelock_platform_interface/wakelock_platform_interface.dart'; | 5 | import 'package:wakelock_platform_interface/wakelock_platform_interface.dart'; |
| 6 | +import 'package:wakelock_windows/wakelock_windows.dart'; | ||
| 6 | 7 | ||
| 7 | /// The [WakelockPlatformInterface] that is used by [Wakelock]. | 8 | /// The [WakelockPlatformInterface] that is used by [Wakelock]. |
| 8 | /// | 9 | /// |
| @@ -12,20 +13,33 @@ import 'package:wakelock_platform_interface/wakelock_platform_interface.dart'; | @@ -12,20 +13,33 @@ import 'package:wakelock_platform_interface/wakelock_platform_interface.dart'; | ||
| 12 | /// test the `pigeon` method channel implementation. Therefore, we want to | 13 | /// test the `pigeon` method channel implementation. Therefore, we want to |
| 13 | /// override this in tests that run on macOS (where there is no actual device). | 14 | /// override this in tests that run on macOS (where there is no actual device). |
| 14 | @visibleForTesting | 15 | @visibleForTesting |
| 15 | -var wakelockPlatformInstance = !kIsWeb && | 16 | +var wakelockPlatformInstance = _defaultPlatformInstance; |
| 17 | + | ||
| 18 | +/// Workaround for configuring platform instances until https://github.com/flutter/flutter/issues/52267 | ||
| 19 | +/// arrives on stable. | ||
| 20 | +WakelockPlatformInterface get _defaultPlatformInstance { | ||
| 21 | + // We want to return early on web as the platform checks are unsupported on | ||
| 22 | + // web. | ||
| 23 | + if (kIsWeb) return WakelockPlatformInterface.instance; | ||
| 24 | + | ||
| 25 | + if (Platform.isMacOS) { | ||
| 16 | // Assigning the macOS platform instance like this is not optimal. | 26 | // Assigning the macOS platform instance like this is not optimal. |
| 17 | // Ideally, we would use the default method channel instance on macOS, | 27 | // Ideally, we would use the default method channel instance on macOS, |
| 18 | // however, it is not yet entirely clear how to integrate with pigeon. | 28 | // however, it is not yet entirely clear how to integrate with pigeon. |
| 19 | // This should just work fine and the io reference should be tree shaken | 29 | // This should just work fine and the io reference should be tree shaken |
| 20 | // on web. | 30 | // on web. |
| 21 | - Platform.isMacOS | ||
| 22 | - ? WakelockMacOS() | ||
| 23 | -// This does not feel like the correct way to assign the Windows | ||
| 24 | -// implementation, however, the platform channels do not have to be used | ||
| 25 | -// thanks to the win32 package. See https://github.com/flutter/flutter/issues/52267. | ||
| 26 | -// : (!kIsWeb && Platform.isWindows) | ||
| 27 | -// ? WakelockWindows() | ||
| 28 | - : WakelockPlatformInterface.instance; | 31 | + return WakelockMacOS(); |
| 32 | + } | ||
| 33 | + | ||
| 34 | + if (Platform.isWindows) { | ||
| 35 | + // This does not feel like the correct way to assign the Windows | ||
| 36 | + // implementation, however, the platform channels do not have to be used | ||
| 37 | + // thanks to the win32 package. See https://github.com/flutter/flutter/issues/52267. | ||
| 38 | + return WakelockWindows(); | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + return WakelockPlatformInterface.instance; | ||
| 42 | +} | ||
| 29 | 43 | ||
| 30 | /// Class providing all wakelock functionality using static members. | 44 | /// Class providing all wakelock functionality using static members. |
| 31 | /// | 45 | /// |
| @@ -2,12 +2,12 @@ name: wakelock | @@ -2,12 +2,12 @@ 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.4.0 | 5 | +version: 0.5.0 |
| 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: |
| 9 | - sdk: '>=2.12.0-259.9.beta <3.0.0' | ||
| 10 | - flutter: '>=1.24.0-0' | 9 | + sdk: '>=2.12.0 <3.0.0' |
| 10 | + flutter: '>=2.0.0' | ||
| 11 | 11 | ||
| 12 | dependencies: | 12 | dependencies: |
| 13 | flutter: | 13 | flutter: |
| @@ -16,7 +16,7 @@ dependencies: | @@ -16,7 +16,7 @@ dependencies: | ||
| 16 | meta: ^1.2.0 | 16 | meta: ^1.2.0 |
| 17 | 17 | ||
| 18 | wakelock_macos: ^0.1.0 | 18 | wakelock_macos: ^0.1.0 |
| 19 | -# wakelock_windows: ^0.1.0 | 19 | + wakelock_windows: ^0.1.0 |
| 20 | wakelock_platform_interface: ^0.2.0 | 20 | wakelock_platform_interface: ^0.2.0 |
| 21 | wakelock_web: ^0.2.0 | 21 | wakelock_web: ^0.2.0 |
| 22 | 22 | ||
| @@ -37,7 +37,7 @@ flutter: | @@ -37,7 +37,7 @@ flutter: | ||
| 37 | pluginClass: WakelockPlugin | 37 | pluginClass: WakelockPlugin |
| 38 | macos: | 38 | macos: |
| 39 | default_package: wakelock_macos | 39 | default_package: wakelock_macos |
| 40 | -# windows: | ||
| 41 | -# default_package: wakelock_windows | 40 | + windows: |
| 41 | + default_package: wakelock_windows | ||
| 42 | web: | 42 | web: |
| 43 | default_package: wakelock_web | 43 | default_package: wakelock_web |
| @@ -4,9 +4,9 @@ | @@ -4,9 +4,9 @@ | ||
| 4 | Pod::Spec.new do |s| | 4 | Pod::Spec.new do |s| |
| 5 | s.name = 'wakelock_macos' | 5 | s.name = 'wakelock_macos' |
| 6 | s.version = '0.0.1' | 6 | s.version = '0.0.1' |
| 7 | - s.summary = 'Plugin that allows you to keep the device screen awake, i.e. prevent the screen from sleeping on Android, iOS, macOS, and web.' | 7 | + s.summary = 'Plugin that allows you to keep the device screen awake, i.e. prevent the screen from sleeping on Android, iOS, macOS, Windows, and web.' |
| 8 | s.description = <<-DESC | 8 | s.description = <<-DESC |
| 9 | - Plugin that allows you to keep the device screen awake, i.e. prevent the screen from sleeping on Android, iOS, macOS, and web. | 9 | + Plugin that allows you to keep the device screen awake, i.e. prevent the screen from sleeping on Android, iOS, macOS, Windows, and web. |
| 10 | DESC | 10 | DESC |
| 11 | s.homepage = 'https://github.com/creativecreatorormaybenot/wakelock/tree/master/packages/wakelock_macos' | 11 | s.homepage = 'https://github.com/creativecreatorormaybenot/wakelock/tree/master/packages/wakelock_macos' |
| 12 | s.license = { :type => 'BSD', :file => '../LICENSE' } | 12 | s.license = { :type => 'BSD', :file => '../LICENSE' } |
-
Please register or login to post a comment