顾海波

【需求】移除win

1 -# Miscellaneous  
2 -*.class  
3 -*.log  
4 -*.pyc  
5 -*.swp  
6 -.DS_Store  
7 -.atom/  
8 -.buildlog/  
9 -.history  
10 -.svn/  
11 -  
12 -# IntelliJ related  
13 -*.iml  
14 -*.ipr  
15 -*.iws  
16 -.idea/  
17 -  
18 -# The .vscode folder contains launch configuration and tasks you configure in  
19 -# VS Code which you may wish to be included in version control, so this line  
20 -# is commented out by default.  
21 -#.vscode/  
22 -  
23 -# Flutter/Dart/Pub related  
24 -**/doc/api/  
25 -.dart_tool/  
26 -.flutter-plugins  
27 -.flutter-plugins-dependencies  
28 -.packages  
29 -.pub-cache/  
30 -.pub/  
31 -build/  
32 -  
33 -# Android related  
34 -**/android/**/gradle-wrapper.jar  
35 -**/android/.gradle  
36 -**/android/captures/  
37 -**/android/gradlew  
38 -**/android/gradlew.bat  
39 -**/android/local.properties  
40 -**/android/**/GeneratedPluginRegistrant.java  
41 -  
42 -# iOS/XCode related  
43 -**/ios/**/*.mode1v3  
44 -**/ios/**/*.mode2v3  
45 -**/ios/**/*.moved-aside  
46 -**/ios/**/*.pbxuser  
47 -**/ios/**/*.perspectivev3  
48 -**/ios/**/*sync/  
49 -**/ios/**/.sconsign.dblite  
50 -**/ios/**/.tags*  
51 -**/ios/**/.vagrant/  
52 -**/ios/**/DerivedData/  
53 -**/ios/**/Icon?  
54 -**/ios/**/Pods/  
55 -**/ios/**/.symlinks/  
56 -**/ios/**/profile  
57 -**/ios/**/xcuserdata  
58 -**/ios/.generated/  
59 -**/ios/Flutter/App.framework  
60 -**/ios/Flutter/Flutter.framework  
61 -**/ios/Flutter/Flutter.podspec  
62 -**/ios/Flutter/Generated.xcconfig  
63 -**/ios/Flutter/app.flx  
64 -**/ios/Flutter/app.zip  
65 -**/ios/Flutter/flutter_assets/  
66 -**/ios/Flutter/flutter_export_environment.sh  
67 -**/ios/ServiceDefinitions.json  
68 -**/ios/Runner/GeneratedPluginRegistrant.*  
69 -  
70 -# Exceptions to above rules.  
71 -!**/ios/**/default.mode1v3  
72 -!**/ios/**/default.mode2v3  
73 -!**/ios/**/default.pbxuser  
74 -!**/ios/**/default.perspectivev3  
1 -## 0.2.0  
2 -  
3 -* Bumped to depend on latest platform interface.  
4 -  
5 -## 0.1.0+2  
6 -  
7 -* Upgraded lints.  
8 -  
9 -## 0.1.0+1  
10 -  
11 -* Updated GitHub references to use `main` instead of `master`.  
12 -  
13 -## 0.1.0  
14 -  
15 -* Initial release  
1 -BSD 3-Clause License  
2 -  
3 -Copyright (c) 2021-2024, creativecreatorormaybenot  
4 -All rights reserved.  
5 -  
6 -Redistribution and use in source and binary forms, with or without  
7 -modification, are permitted provided that the following conditions are met:  
8 -  
9 -1. Redistributions of source code must retain the above copyright notice, this  
10 - list of conditions and the following disclaimer.  
11 -  
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.  
15 -  
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.  
19 -  
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  
22 -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE  
23 -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE  
24 -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL  
25 -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR  
26 -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER  
27 -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,  
28 -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE  
29 -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
1 -# 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)  
2 -  
3 -Windows platform implementation of the `wakelock_platform_interface` for the  
4 -[wakelock plugin][wakelock GitHub].  
5 -  
6 -## Getting started  
7 -  
8 -If you want to use the wakelock plugin on Windows, see the  
9 -[main `wakelock` plugin package][wakelock Pub].  
10 -  
11 -## Implementation  
12 -  
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  
1 -import 'dart:async';  
2 -  
3 -import 'package:wakelock_platform_interface/wakelock_platform_interface.dart';  
4 -import 'package:win32/win32.dart';  
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.  
11 -// ignore: constant_identifier_names  
12 -const _ES_CONTINUOUS = 0x80000000;  
13 -  
14 -/// Forces the display to be on by resetting the display idle timer.  
15 -///  
16 -/// See https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate#parameters.  
17 -// ignore: constant_identifier_names  
18 -const _ES_DISPLAY_REQUIRED = 0x00000002;  
19 -  
20 -/// The Windows implementation of the [WakelockPlatformInterface].  
21 -///  
22 -/// This class implements the `wakelock` plugin functionality for Windows using  
23 -/// the `SetThreadExecutionState` win32 API (see https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate).  
24 -class WakelockWindows extends WakelockPlatformInterface {  
25 - var _enabled = false;  
26 -  
27 - @override  
28 - Future<void> toggle({required bool enable}) async {  
29 - final int response;  
30 - if (enable) {  
31 - response = SetThreadExecutionState(_ES_CONTINUOUS | _ES_DISPLAY_REQUIRED);  
32 - } else {  
33 - response = SetThreadExecutionState(_ES_CONTINUOUS);  
34 - }  
35 -  
36 - // SetThreadExecutionState returns 0 if the operation failed.  
37 - if (response != 0) {  
38 - _enabled = enable;  
39 - }  
40 - }  
41 -  
42 - @override  
43 - Future<bool> get enabled async => _enabled;  
44 -  
45 - @override  
46 - bool get isMock => false;  
47 -}  
1 -name: wakelock_windows  
2 -description: >-2  
3 - Windows platform implementation of the wakelock_platform_interface for the wakelock plugin.  
4 -version: 0.2.0  
5 -repository: https://github.com/creativecreatorormaybenot/wakelock/tree/main/wakelock_windows  
6 -  
7 -environment:  
8 - sdk: '>=2.12.0 <3.0.0'  
9 - flutter: '>=2.0.0'  
10 -  
11 -dependencies:  
12 - flutter:  
13 - sdk: flutter  
14 -  
15 - wakelock_platform_interface: ^0.3.0  
16 - win32: ^2.0.0  
17 -  
18 -dev_dependencies:  
19 - flutter_test:  
20 - sdk: flutter  
21 -  
22 - flutter_lints: ^1.0.4  
23 -  
24 -# todo: use dartPluginClass declaration once that lands on stable (https://github.com/flutter/flutter/issues/52267_  
25 -#flutter:  
26 -# plugin:  
27 -# platforms:  
28 -# windows:  
29 -# dartPluginClass: WakelockWindows  
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 - const acceptUnitTestingDefeat = true;  
13 - expect(acceptUnitTestingDefeat, isTrue);  
14 - });  
15 -}