Showing
12 changed files
with
224 additions
and
0 deletions
wakelock_macos/.gitignore
0 → 100644
wakelock_macos/CHANGELOG.md
0 → 100644
wakelock_macos/LICENSE
0 → 100644
| 1 | +BSD 3-Clause License | ||
| 2 | + | ||
| 3 | +Copyright (c) 2020-2021, 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. |
wakelock_macos/README.md
0 → 100644
| 1 | +# wakelock_web [](https://pub.dev/packages/wakelock_web) [](https://github.com/creativecreatorormaybenot/wakelock) [](https://twitter.com/creativemaybeno) | ||
| 2 | + | ||
| 3 | +macOS 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 macOS, see the [main `wakelock` plugin package](https://pub.dev/packages/wakelock). | ||
| 9 | + | ||
| 10 | +[wakelock GitHub]: https://github.com/creativecreatorormaybenot/wakelock |
wakelock_macos/lib/wakelock_macos.dart
0 → 100644
| 1 | +import 'dart:async'; | ||
| 2 | + | ||
| 3 | +import 'package:flutter/services.dart'; | ||
| 4 | +import 'package:wakelock_platform_interface/wakelock_platform_interface.dart'; | ||
| 5 | + | ||
| 6 | +class WakelockMacos extends WakelockPlatformInterface { | ||
| 7 | + static const MethodChannel _channel = const MethodChannel('wakelock_macos'); | ||
| 8 | + | ||
| 9 | + @override | ||
| 10 | + Future<void> toggle({required bool enable}) async { | ||
| 11 | + await _channel.invokeMethod('toggle', <String, dynamic>{ | ||
| 12 | + 'enable': enable, | ||
| 13 | + }); | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + @override | ||
| 17 | + Future<bool> get enabled async { | ||
| 18 | + final enabled = await _channel.invokeMethod('enabled'); | ||
| 19 | + return enabled; | ||
| 20 | + } | ||
| 21 | +} |
| 1 | +import Cocoa | ||
| 2 | +import FlutterMacOS | ||
| 3 | +import IOKit.pwr_mgt | ||
| 4 | + | ||
| 5 | +public class WakelockMacosPlugin: NSObject, FlutterPlugin { | ||
| 6 | + public static func register(with registrar: FlutterPluginRegistrar) { | ||
| 7 | + let channel = FlutterMethodChannel(name: "wakelock_macos", binaryMessenger: registrar.messenger) | ||
| 8 | + let instance = WakelockMacosPlugin() | ||
| 9 | + registrar.addMethodCallDelegate(instance, channel: channel) | ||
| 10 | + } | ||
| 11 | + | ||
| 12 | + var assertionID: IOPMAssertionID = 0 | ||
| 13 | + var wakelockEnabled = false | ||
| 14 | + public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { | ||
| 15 | + switch call.method { | ||
| 16 | + case "toggle": | ||
| 17 | + let args = call.arguments as? Dictionary<String, Any> | ||
| 18 | + let enable = args!["enable"] as! Bool | ||
| 19 | + if(enable){ | ||
| 20 | + enableWakelock() | ||
| 21 | + }else { | ||
| 22 | + disableWakelock(); | ||
| 23 | + } | ||
| 24 | + result(true) | ||
| 25 | + case "enabled": | ||
| 26 | + result(wakelockEnabled) | ||
| 27 | + default: | ||
| 28 | + result(FlutterMethodNotImplemented) | ||
| 29 | + } | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + func enableWakelock(reason: String = "Disabling Screen Sleep") { | ||
| 33 | + if(!wakelockEnabled){ | ||
| 34 | + wakelockEnabled = IOPMAssertionCreateWithName( kIOPMAssertionTypeNoDisplaySleep as CFString, | ||
| 35 | + IOPMAssertionLevel(kIOPMAssertionLevelOn), | ||
| 36 | + reason as CFString, | ||
| 37 | + &assertionID) == kIOReturnSuccess | ||
| 38 | + } | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | +func disableWakelock() { | ||
| 42 | + if wakelockEnabled { | ||
| 43 | + IOPMAssertionRelease(assertionID) | ||
| 44 | + wakelockEnabled = false | ||
| 45 | + } | ||
| 46 | + } | ||
| 47 | +} |
| 1 | +// This is a generated file; do not edit or check into version control. | ||
| 2 | +FLUTTER_ROOT=/Users/wilson/Developer/flutter | ||
| 3 | +FLUTTER_APPLICATION_PATH=/Users/wilson/Flutter Projects/wakelock/wakelock_macos | ||
| 4 | +FLUTTER_BUILD_DIR=build | ||
| 5 | +FLUTTER_BUILD_NAME=0.2.0.0 | ||
| 6 | +FLUTTER_BUILD_NUMBER=0.2.0.0 | ||
| 7 | +EXCLUDED_ARCHS=arm64 | ||
| 8 | +DART_OBFUSCATION=false | ||
| 9 | +TRACK_WIDGET_CREATION=false | ||
| 10 | +TREE_SHAKE_ICONS=false | ||
| 11 | +PACKAGE_CONFIG=.packages |
| 1 | +#!/bin/sh | ||
| 2 | +# This is a generated file; do not edit or check into version control. | ||
| 3 | +export "FLUTTER_ROOT=/Users/wilson/Developer/flutter" | ||
| 4 | +export "FLUTTER_APPLICATION_PATH=/Users/wilson/Flutter Projects/wakelock/wakelock_macos" | ||
| 5 | +export "FLUTTER_BUILD_DIR=build" | ||
| 6 | +export "FLUTTER_BUILD_NAME=0.2.0.0" | ||
| 7 | +export "FLUTTER_BUILD_NUMBER=0.2.0.0" | ||
| 8 | +export "EXCLUDED_ARCHS=arm64" | ||
| 9 | +export "DART_OBFUSCATION=false" | ||
| 10 | +export "TRACK_WIDGET_CREATION=false" | ||
| 11 | +export "TREE_SHAKE_ICONS=false" | ||
| 12 | +export "PACKAGE_CONFIG=.packages" |
wakelock_macos/macos/wakelock_macos.podspec
0 → 100644
| 1 | +# | ||
| 2 | +# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html. | ||
| 3 | +# Run `pod lib lint wakelock_macos.podspec' to validate before publishing. | ||
| 4 | +# | ||
| 5 | +Pod::Spec.new do |s| | ||
| 6 | + s.name = 'wakelock' | ||
| 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.' | ||
| 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. | ||
| 11 | + DESC | ||
| 12 | + s.homepage = 'http://example.com' | ||
| 13 | + s.license = { :file => '../LICENSE' } | ||
| 14 | + s.author = { 'Your Company' => 'email@example.com' } | ||
| 15 | + s.source = { :path => '.' } | ||
| 16 | + s.source_files = 'Classes/**/*' | ||
| 17 | + s.dependency 'Flutter' | ||
| 18 | + s.platform = :ios, '8.0' | ||
| 19 | + | ||
| 20 | + # Flutter.framework does not contain a i386 slice. | ||
| 21 | + s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' } | ||
| 22 | +end |
wakelock_macos/pubspec.yaml
0 → 100644
| 1 | +name: wakelock_macos | ||
| 2 | +description: macOS platform implementation of the wakelock_platform_interface for the wakelock plugin. | ||
| 3 | +version: 0.2.0-nullsafety.0 | ||
| 4 | +homepage: https://github.com/creativecreatorormaybenot/wakelock/tree/master/wakelock_macos | ||
| 5 | + | ||
| 6 | +environment: | ||
| 7 | + sdk: '>=2.12.0-0 <3.0.0' | ||
| 8 | + flutter: '>=1.24.0-0 <2.0.0' | ||
| 9 | + | ||
| 10 | +dependencies: | ||
| 11 | + flutter: | ||
| 12 | + sdk: flutter | ||
| 13 | + flutter_web_plugins: | ||
| 14 | + sdk: flutter | ||
| 15 | + | ||
| 16 | + wakelock_platform_interface: ^0.2.0-nullsafety.2 | ||
| 17 | + | ||
| 18 | +dev_dependencies: | ||
| 19 | + flutter_test: | ||
| 20 | + sdk: flutter | ||
| 21 | + | ||
| 22 | + pedantic: ^1.10.0-nullsafety.0 | ||
| 23 | + | ||
| 24 | + wakelock: | ||
| 25 | + path: ../wakelock | ||
| 26 | + | ||
| 27 | +flutter: | ||
| 28 | + plugin: | ||
| 29 | + platforms: | ||
| 30 | + macos: | ||
| 31 | + pluginClass: WakelockMacosPlugin | ||
| 32 | + fileName: wakelock_macos.dart |
wakelock_macos/test/wakelock_macos_test.dart
0 → 100644
| 1 | +import 'package:flutter/services.dart'; | ||
| 2 | +import 'package:flutter_test/flutter_test.dart'; | ||
| 3 | + | ||
| 4 | +void main() { | ||
| 5 | + const MethodChannel channel = MethodChannel('wakelock_macos'); | ||
| 6 | + | ||
| 7 | + TestWidgetsFlutterBinding.ensureInitialized(); | ||
| 8 | + | ||
| 9 | + setUp(() { | ||
| 10 | + channel.setMockMethodCallHandler((MethodCall methodCall) async { | ||
| 11 | + return '42'; | ||
| 12 | + }); | ||
| 13 | + }); | ||
| 14 | + | ||
| 15 | + tearDown(() { | ||
| 16 | + channel.setMockMethodCallHandler(null); | ||
| 17 | + }); | ||
| 18 | +} |
-
Please register or login to post a comment