From 3d905a22eea64cc9406beeee5be30565a88be0ad Mon Sep 17 00:00:00 2001 From: creativecreatorormaybenot Date: Sat, 6 Mar 2021 22:00:33 +0000 Subject: [PATCH] Integrate wakelock_windows into wakelock (#101) * Integrate wakelock_windows into wakelock * Fix wakelock_web --- README.md | 13 ++++--- analysis_options.yaml | 4 +- wakelock/CHANGELOG.md | 4 ++ wakelock/README.md | 2 +- wakelock/ios/wakelock.podspec | 4 +- wakelock/lib/wakelock.dart | 42 ++++++++++++++------- wakelock/pubspec.yaml | 12 +++--- wakelock_macos/macos/wakelock_macos.podspec | 4 +- 8 files changed, 54 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index f2c740f0..4a5c6012 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Wakelock [![GitHub stars](https://img.shields.io/github/stars/creativecreatorormaybenot/wakelock.svg)](https://github.com/creativecreatorormaybenot/wakelock) [![Pub version](https://img.shields.io/pub/v/wakelock.svg)](https://pub.dev/packages/wakelock) [![Twitter Follow](https://img.shields.io/twitter/follow/creativemaybeno?label=Follow&style=social)](https://twitter.com/creativemaybeno) -Wakelock is Flutter plugin that allows you to keep the device screen awake, i.e. prevent the screen from sleeping. +Wakelock is Flutter plugin that allows you to keep the device screen awake, i.e. prevent the screen +from sleeping. ## Supported platforms @@ -10,7 +11,7 @@ Wakelock is Flutter plugin that allows you to keep the device screen awake, i.e. | iOS | ✅ | | Web | ✅ | | macOS | ✅ | -| Windows | planned | +| Windows | ✅ | | Linux | planned | ## Getting started @@ -32,6 +33,7 @@ The packages in this repo are the following: | [`wakelock_macos`](https://github.com/creativecreatorormaybenot/wakelock/tree/master/wakelock_macos) | macOS implementation | | [`wakelock_platform_interface`](https://github.com/creativecreatorormaybenot/wakelock/tree/master/wakelock_platform_interface) | Basic API definition & message handling | | [`wakelock_web`](https://github.com/creativecreatorormaybenot/wakelock/tree/master/wakelock_web) | Web implementation | +| [`wakelock_web`](https://github.com/creativecreatorormaybenot/wakelock/tree/master/wakelock_windows) | Windows implementation | ## Contributing @@ -40,7 +42,8 @@ If you want to contribute to this plugin, follow the [contributing guide](https: ## Origin Originally, this plugin was based on [`screen`](https://pub.dev/packages/screen). -Specifically, the wakelock functionality was extracted into this plugin due to lack of maintenance by the author of the `screen` plugin. +Specifically, the wakelock functionality was extracted into this plugin due to lack of maintenance +by the author of the `screen` plugin. -Today, the `wakelock` plugin has been completely refreshed (using latest Flutter standards and platform integration) with added support -for web & macOS. +Today, the `wakelock` plugin has been completely refreshed (using latest Flutter standards and +platform integration) with added support for web, Windows, & macOS. diff --git a/analysis_options.yaml b/analysis_options.yaml index 3ca77a63..3947fc24 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -2,4 +2,6 @@ include: package:pedantic/analysis_options.yaml linter: rules: - - public_member_api_docs + public_member_api_docs: true + # 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. + unsafe_html: false diff --git a/wakelock/CHANGELOG.md b/wakelock/CHANGELOG.md index 6d8aba6d..8c00b0a8 100644 --- a/wakelock/CHANGELOG.md +++ b/wakelock/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.5.0 + +* Added Windows support 🚀 + ## 0.4.0 * Bumped to stable null safety release. diff --git a/wakelock/README.md b/wakelock/README.md index 916ee1fb..495a2fb1 100644 --- a/wakelock/README.md +++ b/wakelock/README.md @@ -15,7 +15,7 @@ Essentially, this allows you to keep the device awake, i.e. prevent the device f | iOS | ✅ | | Web | ✅ | | macOS | ✅ | -| Windows | planned | +| Windows | ✅ | | Linux | planned | ## Usage diff --git a/wakelock/ios/wakelock.podspec b/wakelock/ios/wakelock.podspec index a53670b4..cb5bca94 100644 --- a/wakelock/ios/wakelock.podspec +++ b/wakelock/ios/wakelock.podspec @@ -5,9 +5,9 @@ Pod::Spec.new do |s| s.name = 'wakelock' s.version = '0.0.1' - 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.' + 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.' s.description = <<-DESC -Plugin that allows you to keep the device screen awake, i.e. prevent the screen from sleeping on Android, iOS, macOS, and web. +Plugin that allows you to keep the device screen awake, i.e. prevent the screen from sleeping on Android, iOS, macOS, Windows, and web. DESC s.homepage = 'http://example.com' s.license = { :file => '../LICENSE' } diff --git a/wakelock/lib/wakelock.dart b/wakelock/lib/wakelock.dart index f46dfa97..bfa77700 100644 --- a/wakelock/lib/wakelock.dart +++ b/wakelock/lib/wakelock.dart @@ -3,6 +3,7 @@ import 'dart:io'; import 'package:flutter/foundation.dart'; import 'package:wakelock_macos/wakelock_macos.dart'; import 'package:wakelock_platform_interface/wakelock_platform_interface.dart'; +import 'package:wakelock_windows/wakelock_windows.dart'; /// The [WakelockPlatformInterface] that is used by [Wakelock]. /// @@ -12,20 +13,33 @@ import 'package:wakelock_platform_interface/wakelock_platform_interface.dart'; /// test the `pigeon` method channel implementation. Therefore, we want to /// override this in tests that run on macOS (where there is no actual device). @visibleForTesting -var wakelockPlatformInstance = !kIsWeb && - // Assigning the macOS platform instance like this is not optimal. - // Ideally, we would use the default method channel instance on macOS, - // however, it is not yet entirely clear how to integrate with pigeon. - // This should just work fine and the io reference should be tree shaken - // on web. - Platform.isMacOS - ? WakelockMacOS() -// This does not feel like the correct way to assign the Windows -// implementation, however, the platform channels do not have to be used -// thanks to the win32 package. See https://github.com/flutter/flutter/issues/52267. -// : (!kIsWeb && Platform.isWindows) -// ? WakelockWindows() - : WakelockPlatformInterface.instance; +var wakelockPlatformInstance = _defaultPlatformInstance; + +/// Workaround for configuring platform instances until https://github.com/flutter/flutter/issues/52267 +/// arrives on stable. +WakelockPlatformInterface get _defaultPlatformInstance { + // We want to return early on web as the platform checks are unsupported on + // web. + if (kIsWeb) return WakelockPlatformInterface.instance; + + if (Platform.isMacOS) { + // Assigning the macOS platform instance like this is not optimal. + // Ideally, we would use the default method channel instance on macOS, + // however, it is not yet entirely clear how to integrate with pigeon. + // This should just work fine and the io reference should be tree shaken + // on web. + return WakelockMacOS(); + } + + if (Platform.isWindows) { + // This does not feel like the correct way to assign the Windows + // implementation, however, the platform channels do not have to be used + // thanks to the win32 package. See https://github.com/flutter/flutter/issues/52267. + return WakelockWindows(); + } + + return WakelockPlatformInterface.instance; +} /// Class providing all wakelock functionality using static members. /// diff --git a/wakelock/pubspec.yaml b/wakelock/pubspec.yaml index 0b064560..00c7fedc 100644 --- a/wakelock/pubspec.yaml +++ b/wakelock/pubspec.yaml @@ -2,12 +2,12 @@ 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.4.0 +version: 0.5.0 homepage: https://github.com/creativecreatorormaybenot/wakelock/tree/master/wakelock environment: - sdk: '>=2.12.0-259.9.beta <3.0.0' - flutter: '>=1.24.0-0' + sdk: '>=2.12.0 <3.0.0' + flutter: '>=2.0.0' dependencies: flutter: @@ -16,7 +16,7 @@ dependencies: meta: ^1.2.0 wakelock_macos: ^0.1.0 -# wakelock_windows: ^0.1.0 + wakelock_windows: ^0.1.0 wakelock_platform_interface: ^0.2.0 wakelock_web: ^0.2.0 @@ -37,7 +37,7 @@ flutter: pluginClass: WakelockPlugin macos: default_package: wakelock_macos -# windows: -# default_package: wakelock_windows + windows: + default_package: wakelock_windows web: default_package: wakelock_web diff --git a/wakelock_macos/macos/wakelock_macos.podspec b/wakelock_macos/macos/wakelock_macos.podspec index e0c5867c..00dc7480 100644 --- a/wakelock_macos/macos/wakelock_macos.podspec +++ b/wakelock_macos/macos/wakelock_macos.podspec @@ -4,9 +4,9 @@ Pod::Spec.new do |s| s.name = 'wakelock_macos' s.version = '0.0.1' - 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.' + 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.' s.description = <<-DESC - Plugin that allows you to keep the device screen awake, i.e. prevent the screen from sleeping on Android, iOS, macOS, and web. + Plugin that allows you to keep the device screen awake, i.e. prevent the screen from sleeping on Android, iOS, macOS, Windows, and web. DESC s.homepage = 'https://github.com/creativecreatorormaybenot/wakelock/tree/master/packages/wakelock_macos' s.license = { :type => 'BSD', :file => '../LICENSE' }