顾海波

【需求】移除win

# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
# IntelliJ related
*.iml
*.ipr
*.iws
.idea/
# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/
# Flutter/Dart/Pub related
**/doc/api/
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
build/
# Android related
**/android/**/gradle-wrapper.jar
**/android/.gradle
**/android/captures/
**/android/gradlew
**/android/gradlew.bat
**/android/local.properties
**/android/**/GeneratedPluginRegistrant.java
# iOS/XCode related
**/ios/**/*.mode1v3
**/ios/**/*.mode2v3
**/ios/**/*.moved-aside
**/ios/**/*.pbxuser
**/ios/**/*.perspectivev3
**/ios/**/*sync/
**/ios/**/.sconsign.dblite
**/ios/**/.tags*
**/ios/**/.vagrant/
**/ios/**/DerivedData/
**/ios/**/Icon?
**/ios/**/Pods/
**/ios/**/.symlinks/
**/ios/**/profile
**/ios/**/xcuserdata
**/ios/.generated/
**/ios/Flutter/App.framework
**/ios/Flutter/Flutter.framework
**/ios/Flutter/Flutter.podspec
**/ios/Flutter/Generated.xcconfig
**/ios/Flutter/app.flx
**/ios/Flutter/app.zip
**/ios/Flutter/flutter_assets/
**/ios/Flutter/flutter_export_environment.sh
**/ios/ServiceDefinitions.json
**/ios/Runner/GeneratedPluginRegistrant.*
# Exceptions to above rules.
!**/ios/**/default.mode1v3
!**/ios/**/default.mode2v3
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
## 0.2.0
* Bumped to depend on latest platform interface.
## 0.1.0+2
* Upgraded lints.
## 0.1.0+1
* Updated GitHub references to use `main` instead of `master`.
## 0.1.0
* Initial release
BSD 3-Clause License
Copyright (c) 2021-2024, creativecreatorormaybenot
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# wakelock_windows [![Pub version](https://img.shields.io/pub/v/wakelock_windows.svg)](https://pub.dev/packages/wakelock_windows) [![GitHub stars](https://img.shields.io/github/stars/creativecreatorormaybenot/wakelock.svg)](https://github.com/creativecreatorormaybenot/wakelock) [![Twitter Follow](https://img.shields.io/twitter/follow/creativemaybeno?label=Follow&style=social)](https://twitter.com/creativemaybeno)
Windows platform implementation of the `wakelock_platform_interface` for the
[wakelock plugin][wakelock GitHub].
## Getting started
If you want to use the wakelock plugin on Windows, see the
[main `wakelock` plugin package][wakelock Pub].
## Implementation
Note that the implementation does not use a `MethodChannel` implementation as it relies on the
[win32 package][win32 Pub].
[wakelock GitHub]: https://github.com/creativecreatorormaybenot/wakelock
[wakelock Pub]: https://pub.dev/packages/wakelock
[win32 Pub]: https://pub.dev/packages/win32
import 'dart:async';
import 'package:wakelock_platform_interface/wakelock_platform_interface.dart';
import 'package:win32/win32.dart';
/// Informs the system that the state being set should remain in effect until
/// the next call that uses ES_CONTINUOUS and one of the other state flags is
/// cleared.
///
/// See https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate#parameters.
// ignore: constant_identifier_names
const _ES_CONTINUOUS = 0x80000000;
/// Forces the display to be on by resetting the display idle timer.
///
/// See https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate#parameters.
// ignore: constant_identifier_names
const _ES_DISPLAY_REQUIRED = 0x00000002;
/// The Windows implementation of the [WakelockPlatformInterface].
///
/// This class implements the `wakelock` plugin functionality for Windows using
/// the `SetThreadExecutionState` win32 API (see https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate).
class WakelockWindows extends WakelockPlatformInterface {
var _enabled = false;
@override
Future<void> toggle({required bool enable}) async {
final int response;
if (enable) {
response = SetThreadExecutionState(_ES_CONTINUOUS | _ES_DISPLAY_REQUIRED);
} else {
response = SetThreadExecutionState(_ES_CONTINUOUS);
}
// SetThreadExecutionState returns 0 if the operation failed.
if (response != 0) {
_enabled = enable;
}
}
@override
Future<bool> get enabled async => _enabled;
@override
bool get isMock => false;
}
name: wakelock_windows
description: >-2
Windows platform implementation of the wakelock_platform_interface for the wakelock plugin.
version: 0.2.0
repository: https://github.com/creativecreatorormaybenot/wakelock/tree/main/wakelock_windows
environment:
sdk: '>=2.12.0 <3.0.0'
flutter: '>=2.0.0'
dependencies:
flutter:
sdk: flutter
wakelock_platform_interface: ^0.3.0
win32: ^2.0.0
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^1.0.4
# todo: use dartPluginClass declaration once that lands on stable (https://github.com/flutter/flutter/issues/52267_
#flutter:
# plugin:
# platforms:
# windows:
# dartPluginClass: WakelockWindows
import 'package:flutter_test/flutter_test.dart';
void main() {
// There are currently no unit tests for the Windows implementation as
// testing for Windows is currently done using the integration tests in
// wakelock/example.
// This means that every change to the wakelock_windows package should be
// tested using a local dependency in the wakelock example integration test
// before being published. For that, we use dependency overrides in the
// example app.
test('stub', () {
const acceptUnitTestingDefeat = true;
expect(acceptUnitTestingDefeat, isTrue);
});
}