diff --git a/README.md b/README.md index e81c286..2c56916 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ | [path_provider_aurora](https://gitlab.com/omprussia/flutter/flutter-plugins/-/tree/master/packages/path_provider/path_provider_aurora) | `0.0.1` | [path_provider](https://pub.dev/packages/path_provider) | `2.1.1` | `4.0.2.269` | | [shared_preferences_aurora](https://gitlab.com/omprussia/flutter/flutter-plugins/-/tree/master/packages/shared_preferences/shared_preferences_aurora) | `0.0.1` | [shared_preferences](https://pub.dev/packages/shared_preferences) | `2.1.2` | `4.0.2.269` | | [sqflite_aurora](https://gitlab.com/omprussia/flutter/flutter-plugins/-/tree/master/packages/sqflite/sqflite_aurora) | `0.0.1` | [sqflite](https://pub.dev/packages/sqflite) | `2.3.0` | `4.0.2.269` | +| [wakelock_plus_aurora](https://gitlab.com/omprussia/flutter/flutter-plugins/-/tree/master/packages/wakelock_plus/wakelock_plus_aurora) | `0.0.1` | [wakelock_plus](https://pub.dev/packages/wakelock_plus) | `1.1.1` | `4.0.2.269` | | [xdga_directories](https://gitlab.com/omprussia/flutter/flutter-plugins/-/tree/master/packages/xdga_directories) | `0.0.1` | - | - | `4.0.2.269` | | - | - | [flutter_cache_manager](https://pub.dev/packages/flutter_cache_manager) | `3.3.1` | `4.0.2.269` | | - | - | [cached_network_image](https://pub.dev/packages/cached_network_image) | `3.3.0` | `4.0.2.269` | diff --git a/example/lib/l10n/app_en.arb b/example/lib/l10n/app_en.arb index 2647a5f..857b8d2 100644 --- a/example/lib/l10n/app_en.arb +++ b/example/lib/l10n/app_en.arb @@ -169,7 +169,7 @@ }, "@_WAKELOCK": {}, - "wakelockTitle": "Wakelock", + "wakelockTitle": "Lock", "wakelockDesc": "The plugin allows you to enable and toggle the screen wakelock, which prevents the screen from turning off automatically.", "@_XDGA_DIRECTORIES": {}, diff --git a/example/lib/l10n/app_ru.arb b/example/lib/l10n/app_ru.arb index 89c7f69..beec8aa 100644 --- a/example/lib/l10n/app_ru.arb +++ b/example/lib/l10n/app_ru.arb @@ -161,7 +161,7 @@ "sharedPreferencesFieldError": "Пожалуйста, введите {value} значение", "@_WAKELOCK": {}, - "wakelockTitle": "Wakelock", + "wakelockTitle": "Блокировка", "wakelockDesc": "Плагин позволяет включать и переключать блокировку экрана, которая предотвращает автоматическое выключение экрана.", "@_XDGA_DIRECTORIES": {}, diff --git a/example/lib/packages/packages.dart b/example/lib/packages/packages.dart index 1d41e86..f1a3ad7 100644 --- a/example/lib/packages/packages.dart +++ b/example/lib/packages/packages.dart @@ -32,6 +32,7 @@ import 'package:flutter_example_packages/packages/scoped_model/package.dart'; import 'package:flutter_example_packages/packages/shared_preferences/package.dart'; import 'package:flutter_example_packages/packages/sqflite/package.dart'; import 'package:flutter_example_packages/packages/universal_io/package.dart'; +import 'package:flutter_example_packages/packages/wakelock_plus/package.dart'; import 'package:flutter_example_packages/packages/xdga_directories/package.dart'; /// List app packages @@ -67,5 +68,6 @@ final packages = [ packageSharedPreferences, packageSqflite, packageUniversalIO, + packageWakelockPlus, packageXdgaDirectories, ]; diff --git a/example/lib/packages/wakelock_plus/model.dart b/example/lib/packages/wakelock_plus/model.dart new file mode 100644 index 0000000..a03c63f --- /dev/null +++ b/example/lib/packages/wakelock_plus/model.dart @@ -0,0 +1,42 @@ +// SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC +// SPDX-License-Identifier: BSD-3-Clause +import 'package:flutter/widgets.dart'; +import 'package:scoped_model/scoped_model.dart'; +import 'package:wakelock_plus/wakelock_plus.dart'; + +/// Model for [WakelockPlusPage] +class WakelockPlusModel extends Model { + /// Get [ScopedModel] + static WakelockPlusModel of(BuildContext context) => + ScopedModel.of(context); + + /// Error + String? _error; + + /// Public error + String? get error => _error; + + /// Public is error + bool get isError => _error != null; + + /// Check is enable Wakelock + Future isEnable() async { + try { + return await WakelockPlus.enabled; + } catch (e) { + _error = e.toString(); + } + notifyListeners(); + return null; + } + + /// Set state Wakelock + Future setStateWakelockPlus(bool enable) async { + try { + await WakelockPlus.toggle(enable: enable); + } catch (e) { + _error = e.toString(); + } + notifyListeners(); + } +} diff --git a/example/lib/packages/wakelock_plus/package.dart b/example/lib/packages/wakelock_plus/package.dart new file mode 100644 index 0000000..3e057e4 --- /dev/null +++ b/example/lib/packages/wakelock_plus/package.dart @@ -0,0 +1,26 @@ +// SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC +// SPDX-License-Identifier: BSD-3-Clause +import 'package:flutter_example_packages/base/package/package_page.dart'; +import 'package:flutter_example_packages/packages/wakelock_plus/page.dart'; +import 'package:get_it/get_it.dart'; + +import 'model.dart'; + +/// Package values +final packageWakelockPlus = PackagePage( + key: 'wakelock_plus', + descEN: ''' + Plugin that allows you to keep the device screen awake, i.e. + prevent the screen from sleeping. + ''', + descRU: ''' + Плагин, который позволяет держать экран устройства в активном состоянии, + т. е. предотвращать переход экрана в спящий режим. + ''', + version: '1.1.1', + isPlatformDependent: true, + page: () => WakelockPlusPage(), + init: () { + GetIt.instance.registerFactory(() => WakelockPlusModel()); + }, +); diff --git a/example/lib/packages/wakelock_plus/page.dart b/example/lib/packages/wakelock_plus/page.dart new file mode 100644 index 0000000..be9634a --- /dev/null +++ b/example/lib/packages/wakelock_plus/page.dart @@ -0,0 +1,89 @@ +// SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC +// SPDX-License-Identifier: BSD-3-Clause +import 'package:flutter/material.dart'; +import 'package:flutter_example_packages/base/di/app_di.dart'; +import 'package:flutter_example_packages/base/package/package.dart'; +import 'package:flutter_example_packages/packages/wakelock_plus/model.dart'; +import 'package:flutter_example_packages/packages/wakelock_plus/package.dart'; +import 'package:flutter_example_packages/theme/colors.dart'; +import 'package:flutter_example_packages/widgets/base/export.dart'; +import 'package:flutter_example_packages/widgets/blocks/block_alert.dart'; +import 'package:flutter_example_packages/widgets/blocks/block_info_package.dart'; +import 'package:flutter_example_packages/widgets/layouts/block_layout.dart'; +import 'package:flutter_example_packages/widgets/texts/export.dart'; +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; + +class WakelockPlusPage extends AppStatefulWidget { + WakelockPlusPage({ + super.key, + }); + + final Package package = packageWakelockPlus; + + @override + State createState() => _WakelockPlusPageState(); +} + +class _WakelockPlusPageState extends AppState { + @override + Widget buildWide( + BuildContext context, + MediaQueryData media, + AppLocalizations l10n, + ) { + return BlockLayout( + model: getIt(), + title: widget.package.key, + builder: (context, child, model) { + return SingleChildScrollView( + child: Padding( + padding: const EdgeInsets.all(20), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + BlockInfoPackage(widget.package), + BlockAlert(model.error), + if (!model.isError) + Row( + children: [ + Expanded( + flex: 1, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + TextTitleLarge(l10n.wakelockTitle), + const SizedBox(height: 8), + TextBodyMedium(l10n.wakelockDesc), + ], + ), + ), + FutureBuilder( + future: model.isEnable(), + builder: ( + BuildContext context, + AsyncSnapshot snapshot, + ) { + final value = snapshot.data ?? false; + return Expanded( + flex: 0, + child: Switch( + // This bool value toggles the switch. + value: value, + activeColor: AppColors.secondary, + onChanged: (bool value) { + model.setStateWakelockPlus(value); + }, + ), + ); + }, + ), + ], + ), + ], + ), + ), + ); + }, + ); + } +} diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 5ee9b10..746b27b 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -153,6 +153,16 @@ dependencies: # ref: master # path: packages/sqflite/sqflite_aurora + ## https://pub.dev/packages/wakelock_plus + wakelock_plus: ^1.1.1 + ## https://gitlab.com/omprussia/flutter/flutter-plugins/-/tree/master/packages/wakelock_plus/wakelock_plus_aurora + wakelock_plus_aurora: + path: ../packages/wakelock_plus/wakelock_plus_aurora +# git: +# url: https://gitlab.com/omprussia/flutter/flutter-plugins.git +# ref: master +# path: packages/wakelock_plus/wakelock_plus_aurora + dev_dependencies: flutter_test: sdk: diff --git a/packages/wakelock_plus/wakelock_plus_aurora/.gitignore b/packages/wakelock_plus/wakelock_plus_aurora/.gitignore new file mode 100644 index 0000000..96486fd --- /dev/null +++ b/packages/wakelock_plus/wakelock_plus_aurora/.gitignore @@ -0,0 +1,30 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# 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 +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. +/pubspec.lock +**/doc/api/ +.dart_tool/ +.packages +build/ diff --git a/packages/wakelock_plus/wakelock_plus_aurora/README.md b/packages/wakelock_plus/wakelock_plus_aurora/README.md new file mode 100644 index 0000000..50d922d --- /dev/null +++ b/packages/wakelock_plus/wakelock_plus_aurora/README.md @@ -0,0 +1,32 @@ +# wakelock_plus_aurora + +The Aurora implementation of [`wakelock_plus`](https://pub.dev/packages/wakelock_plus). + +## Usage +This package is not an _endorsed_ implementation of `wakelock_plus`. +Therefore, you have to include `wakelock_plus_aurora` alongside `wakelock_plus` as dependencies in your `pubspec.yaml` file. + +**pubspec.yaml** + +```yaml +dependencies: + wakelock_plus: ^1.1.1 + wakelock_plus_aurora: + git: + url: https://gitlab.com/omprussia/flutter/flutter-plugins.git + ref: master + path: packages/wakelock_plus/wakelock_plus_aurora +``` + +***.dart** + +```dart +import 'package:wakelock_plus/wakelock_plus.dart'; +// ... + +// The following line will enable the Android and iOS wakelock. +WakelockPlus.enable(); + +// The next line disables the wakelock again. +WakelockPlus.disable(); +``` diff --git a/packages/wakelock_plus/wakelock_plus_aurora/analysis_options.yaml b/packages/wakelock_plus/wakelock_plus_aurora/analysis_options.yaml new file mode 100644 index 0000000..8a1fdc6 --- /dev/null +++ b/packages/wakelock_plus/wakelock_plus_aurora/analysis_options.yaml @@ -0,0 +1,4 @@ +# SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC +# SPDX-License-Identifier: BSD-3-Clause + +include: package:flutter_lints/flutter.yaml diff --git a/packages/wakelock_plus/wakelock_plus_aurora/data/com.nokia.mce.request.xml b/packages/wakelock_plus/wakelock_plus_aurora/data/com.nokia.mce.request.xml new file mode 100644 index 0000000..ee47a8a --- /dev/null +++ b/packages/wakelock_plus/wakelock_plus_aurora/data/com.nokia.mce.request.xml @@ -0,0 +1,10 @@ + + + + + + + + diff --git a/packages/wakelock_plus/wakelock_plus_aurora/lib/com_nokia_mce_request.dart b/packages/wakelock_plus/wakelock_plus_aurora/lib/com_nokia_mce_request.dart new file mode 100644 index 0000000..8120726 --- /dev/null +++ b/packages/wakelock_plus/wakelock_plus_aurora/lib/com_nokia_mce_request.dart @@ -0,0 +1,20 @@ +// SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC +// SPDX-License-Identifier: BSD-3-Clause +import 'package:dbus/dbus.dart'; + +class ComNokiaMceRequest extends DBusRemoteObject { + ComNokiaMceRequest(DBusClient client, String destination, + {DBusObjectPath path = + const DBusObjectPath.unchecked('/com/nokia/mce/request')}) + : super(client, name: destination, path: path); + + /// Invokes com.nokia.mce.request.req_display_blanking_pause() + Future callreq_display_blanking_pause( + {bool noAutoStart = false, + bool allowInteractiveAuthorization = false}) async { + await callMethod('com.nokia.mce.request', 'req_display_blanking_pause', [], + replySignature: DBusSignature(''), + noAutoStart: noAutoStart, + allowInteractiveAuthorization: allowInteractiveAuthorization); + } +} diff --git a/packages/wakelock_plus/wakelock_plus_aurora/lib/wakelock_plus_aurora.dart b/packages/wakelock_plus/wakelock_plus_aurora/lib/wakelock_plus_aurora.dart new file mode 100644 index 0000000..d8f33e7 --- /dev/null +++ b/packages/wakelock_plus/wakelock_plus_aurora/lib/wakelock_plus_aurora.dart @@ -0,0 +1,40 @@ +// SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC +// SPDX-License-Identifier: BSD-3-Clause +import 'dart:async'; + +import 'package:dbus/dbus.dart'; +import 'package:wakelock_plus_platform_interface/wakelock_plus_platform_interface.dart'; +import 'com_nokia_mce_request.dart'; + +class WakelockPlusAurora extends WakelockPlusPlatformInterface { + bool _enable = false; + Timer? _timer; + + static void registerWith() { + WakelockPlusPlatformInterface.instance = WakelockPlusAurora(); + } + + @override + Future toggle({required bool enable}) async { + if (_enable != enable) { + _enable = enable; + final client = DBusClient.system(); + final request = ComNokiaMceRequest(client, 'com.nokia.mce'); + if (_timer == null) { + request.callreq_display_blanking_pause(); + _timer = Timer.periodic(const Duration(seconds: 60), (timer) { + request.callreq_display_blanking_pause(); + }); + } else { + _timer?.cancel(); + _timer = null; + } + await client.close(); + } + } + + @override + Future get enabled async { + return _enable; + } +} diff --git a/packages/wakelock_plus/wakelock_plus_aurora/pubspec.yaml b/packages/wakelock_plus/wakelock_plus_aurora/pubspec.yaml new file mode 100644 index 0000000..64526d4 --- /dev/null +++ b/packages/wakelock_plus/wakelock_plus_aurora/pubspec.yaml @@ -0,0 +1,28 @@ +# SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC +# SPDX-License-Identifier: BSD-3-Clause + +name: wakelock_plus_aurora +description: Wakelock is Flutter plugin that allows you to keep the device screen awake, i.e. prevent the screen from sleeping. +version: 0.0.1 + +environment: + sdk: '>=2.18.6 <4.0.0' + flutter: ">=3.0.0" + +dependencies: + flutter: + sdk: flutter + dbus: ^0.7.8 + plugin_platform_interface: ^2.0.2 + wakelock_plus_platform_interface: ^1.1.0 + +dev_dependencies: + flutter_test: + sdk: flutter + flutter_lints: ^2.0.0 + +flutter: + plugin: + platforms: + aurora: + dartPluginClass: WakelockPlusAurora