Browse Source

[plugin] Add wakelock_plus

merge-requests/35/merge
Vitaliy Zarubin 1 year ago
parent
commit
c382141993
  1. 1
      README.md
  2. 2
      example/lib/l10n/app_en.arb
  3. 2
      example/lib/l10n/app_ru.arb
  4. 2
      example/lib/packages/packages.dart
  5. 42
      example/lib/packages/wakelock_plus/model.dart
  6. 26
      example/lib/packages/wakelock_plus/package.dart
  7. 89
      example/lib/packages/wakelock_plus/page.dart
  8. 10
      example/pubspec.yaml
  9. 30
      packages/wakelock_plus/wakelock_plus_aurora/.gitignore
  10. 32
      packages/wakelock_plus/wakelock_plus_aurora/README.md
  11. 4
      packages/wakelock_plus/wakelock_plus_aurora/analysis_options.yaml
  12. 10
      packages/wakelock_plus/wakelock_plus_aurora/data/com.nokia.mce.request.xml
  13. 20
      packages/wakelock_plus/wakelock_plus_aurora/lib/com_nokia_mce_request.dart
  14. 40
      packages/wakelock_plus/wakelock_plus_aurora/lib/wakelock_plus_aurora.dart
  15. 28
      packages/wakelock_plus/wakelock_plus_aurora/pubspec.yaml

1
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` | | [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` | | [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` | | [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` | | [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` | | - | - | [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` | | - | - | [cached_network_image](https://pub.dev/packages/cached_network_image) | `3.3.0` | `4.0.2.269` |

2
example/lib/l10n/app_en.arb

@ -169,7 +169,7 @@
}, },
"@_WAKELOCK": {}, "@_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.", "wakelockDesc": "The plugin allows you to enable and toggle the screen wakelock, which prevents the screen from turning off automatically.",
"@_XDGA_DIRECTORIES": {}, "@_XDGA_DIRECTORIES": {},

2
example/lib/l10n/app_ru.arb

@ -161,7 +161,7 @@
"sharedPreferencesFieldError": "Пожалуйста, введите {value} значение", "sharedPreferencesFieldError": "Пожалуйста, введите {value} значение",
"@_WAKELOCK": {}, "@_WAKELOCK": {},
"wakelockTitle": "Wakelock", "wakelockTitle": "Блокировка",
"wakelockDesc": "Плагин позволяет включать и переключать блокировку экрана, которая предотвращает автоматическое выключение экрана.", "wakelockDesc": "Плагин позволяет включать и переключать блокировку экрана, которая предотвращает автоматическое выключение экрана.",
"@_XDGA_DIRECTORIES": {}, "@_XDGA_DIRECTORIES": {},

2
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/shared_preferences/package.dart';
import 'package:flutter_example_packages/packages/sqflite/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/universal_io/package.dart';
import 'package:flutter_example_packages/packages/wakelock_plus/package.dart';
import 'package:flutter_example_packages/packages/xdga_directories/package.dart'; import 'package:flutter_example_packages/packages/xdga_directories/package.dart';
/// List app packages /// List app packages
@ -67,5 +68,6 @@ final packages = <Package>[
packageSharedPreferences, packageSharedPreferences,
packageSqflite, packageSqflite,
packageUniversalIO, packageUniversalIO,
packageWakelockPlus,
packageXdgaDirectories, packageXdgaDirectories,
]; ];

42
example/lib/packages/wakelock_plus/model.dart

@ -0,0 +1,42 @@
// SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC <community@omp.ru>
// 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<WakelockPlusModel>(context);
/// Error
String? _error;
/// Public error
String? get error => _error;
/// Public is error
bool get isError => _error != null;
/// Check is enable Wakelock
Future<bool?> isEnable() async {
try {
return await WakelockPlus.enabled;
} catch (e) {
_error = e.toString();
}
notifyListeners();
return null;
}
/// Set state Wakelock
Future<void> setStateWakelockPlus(bool enable) async {
try {
await WakelockPlus.toggle(enable: enable);
} catch (e) {
_error = e.toString();
}
notifyListeners();
}
}

26
example/lib/packages/wakelock_plus/package.dart

@ -0,0 +1,26 @@
// SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC <community@omp.ru>
// 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>(() => WakelockPlusModel());
},
);

89
example/lib/packages/wakelock_plus/page.dart

@ -0,0 +1,89 @@
// SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC <community@omp.ru>
// 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<WakelockPlusPage> createState() => _WakelockPlusPageState();
}
class _WakelockPlusPageState extends AppState<WakelockPlusPage> {
@override
Widget buildWide(
BuildContext context,
MediaQueryData media,
AppLocalizations l10n,
) {
return BlockLayout<WakelockPlusModel>(
model: getIt<WakelockPlusModel>(),
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<bool?>(
future: model.isEnable(),
builder: (
BuildContext context,
AsyncSnapshot<bool?> 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);
},
),
);
},
),
],
),
],
),
),
);
},
);
}
}

10
example/pubspec.yaml

@ -153,6 +153,16 @@ dependencies:
# ref: master # ref: master
# path: packages/sqflite/sqflite_aurora # 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: dev_dependencies:
flutter_test: flutter_test:
sdk: sdk:

30
packages/wakelock_plus/wakelock_plus_aurora/.gitignore vendored

@ -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/

32
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();
```

4
packages/wakelock_plus/wakelock_plus_aurora/analysis_options.yaml

@ -0,0 +1,4 @@
# SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC <community@omp.ru>
# SPDX-License-Identifier: BSD-3-Clause
include: package:flutter_lints/flutter.yaml

10
packages/wakelock_plus/wakelock_plus_aurora/data/com.nokia.mce.request.xml

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE node PUBLIC
"-//freedesktop//DTD D-Bus Object Introspection 1.0//EN"
"http://standards.freedesktop.org/dbus/1.0/introspect.dtd">
<node name="/com/nokia/mce/request">
<interface name="com.nokia.mce.request">
<method name="req_display_blanking_pause">
</method>
</interface>
</node>

20
packages/wakelock_plus/wakelock_plus_aurora/lib/com_nokia_mce_request.dart

@ -0,0 +1,20 @@
// SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC <community@omp.ru>
// 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<void> 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);
}
}

40
packages/wakelock_plus/wakelock_plus_aurora/lib/wakelock_plus_aurora.dart

@ -0,0 +1,40 @@
// SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC <community@omp.ru>
// 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<void> 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<bool> get enabled async {
return _enable;
}
}

28
packages/wakelock_plus/wakelock_plus_aurora/pubspec.yaml

@ -0,0 +1,28 @@
# SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC <community@omp.ru>
# 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
Loading…
Cancel
Save