Browse Source
			
			
			
			
				
		[plugin] Add wakelock_plus See merge request omprussia/flutter/flutter-plugins!32merge-requests/32/merge
				 15 changed files with 336 additions and 2 deletions
			
			
		@ -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(); | 
				
			||||
  } | 
				
			||||
} | 
				
			||||
@ -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()); | 
				
			||||
  }, | 
				
			||||
); | 
				
			||||
@ -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); | 
				
			||||
                              }, | 
				
			||||
                            ), | 
				
			||||
                          ); | 
				
			||||
                        }, | 
				
			||||
                      ), | 
				
			||||
                    ], | 
				
			||||
                  ), | 
				
			||||
              ], | 
				
			||||
            ), | 
				
			||||
          ), | 
				
			||||
        ); | 
				
			||||
      }, | 
				
			||||
    ); | 
				
			||||
  } | 
				
			||||
} | 
				
			||||
@ -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/ | 
				
			||||
@ -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(); | 
				
			||||
``` | 
				
			||||
@ -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 | 
				
			||||
@ -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> | 
				
			||||
@ -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); | 
				
			||||
  } | 
				
			||||
} | 
				
			||||
@ -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; | 
				
			||||
  } | 
				
			||||
} | 
				
			||||
@ -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…
					
					
				
		Reference in new issue