12 changed files with 344 additions and 0 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/wakelock.dart'; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Model for [WakelockPage] | 
				
			||||||
 | 
					class WakelockModel extends Model { | 
				
			||||||
 | 
					  /// Get [ScopedModel] | 
				
			||||||
 | 
					  static WakelockModel of(BuildContext context) => | 
				
			||||||
 | 
					      ScopedModel.of<WakelockModel>(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 Wakelock.enabled; | 
				
			||||||
 | 
					    } catch (e) { | 
				
			||||||
 | 
					      _error = e.toString(); | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					    notifyListeners(); | 
				
			||||||
 | 
					    return null; | 
				
			||||||
 | 
					  } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /// Set state Wakelock | 
				
			||||||
 | 
					  Future<void> setStateWakelock(bool enable) async { | 
				
			||||||
 | 
					    try { | 
				
			||||||
 | 
					      await Wakelock.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/page.dart'; | 
				
			||||||
 | 
					import 'package:get_it/get_it.dart'; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import 'model.dart'; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Package values | 
				
			||||||
 | 
					final packageWakelock = PackagePage( | 
				
			||||||
 | 
					  key: 'wakelock', | 
				
			||||||
 | 
					  descEN: ''' | 
				
			||||||
 | 
					    Plugin that allows you to keep the device screen awake, i.e.  | 
				
			||||||
 | 
					    prevent the screen from sleeping. | 
				
			||||||
 | 
					    ''', | 
				
			||||||
 | 
					  descRU: ''' | 
				
			||||||
 | 
					    Плагин, который позволяет держать экран устройства в активном состоянии,  | 
				
			||||||
 | 
					    т. е. предотвращать переход экрана в спящий режим. | 
				
			||||||
 | 
					    ''', | 
				
			||||||
 | 
					  version: '0.6.2', | 
				
			||||||
 | 
					  isPlatformDependent: true, | 
				
			||||||
 | 
					  page: () => WakelockPage(), | 
				
			||||||
 | 
					  init: () { | 
				
			||||||
 | 
					    GetIt.instance.registerFactory<WakelockModel>(() => WakelockModel()); | 
				
			||||||
 | 
					  }, | 
				
			||||||
 | 
					); | 
				
			||||||
@ -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/model.dart'; | 
				
			||||||
 | 
					import 'package:flutter_example_packages/packages/wakelock/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 WakelockPage extends AppStatefulWidget { | 
				
			||||||
 | 
					  WakelockPage({ | 
				
			||||||
 | 
					    super.key, | 
				
			||||||
 | 
					  }); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  final Package package = packageWakelock; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @override | 
				
			||||||
 | 
					  State<WakelockPage> createState() => _WakelockPageState(); | 
				
			||||||
 | 
					} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class _WakelockPageState extends AppState<WakelockPage> { | 
				
			||||||
 | 
					  @override | 
				
			||||||
 | 
					  Widget buildWide( | 
				
			||||||
 | 
					    BuildContext context, | 
				
			||||||
 | 
					    MediaQueryData media, | 
				
			||||||
 | 
					    AppLocalizations l10n, | 
				
			||||||
 | 
					  ) { | 
				
			||||||
 | 
					    return BlockLayout<WakelockModel>( | 
				
			||||||
 | 
					      model: getIt<WakelockModel>(), | 
				
			||||||
 | 
					      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.setStateWakelock(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,37 @@ | 
				
			|||||||
 | 
					# wakelock_aurora | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					The Aurora implementation of [`wakelock`](https://pub.dev/packages/wakelock). | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Usage | 
				
			||||||
 | 
					This package is not an _endorsed_ implementation of `wakelock`.  | 
				
			||||||
 | 
					Therefore, you have to include `wakelock_aurora` alongside `wakelock` as dependencies in your `pubspec.yaml` file. | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					**pubspec.yaml** | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```yaml | 
				
			||||||
 | 
					dependencies: | 
				
			||||||
 | 
					  # wakelock: ^0.6.2 - Version is outdated | 
				
			||||||
 | 
					  wakelock: | 
				
			||||||
 | 
					    git: | 
				
			||||||
 | 
					      url: https://github.com/keygenqt/wakelock.git | 
				
			||||||
 | 
					      ref: wakelock_windows_git | 
				
			||||||
 | 
					      path: wakelock | 
				
			||||||
 | 
					       | 
				
			||||||
 | 
					  wakelock_aurora: | 
				
			||||||
 | 
					    git: | 
				
			||||||
 | 
					      url: https://gitlab.com/omprussia/flutter/flutter-plugins.git | 
				
			||||||
 | 
					      ref: master | 
				
			||||||
 | 
					      path: packages/wakelock/wakelock_aurora | 
				
			||||||
 | 
					``` | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					***.dart** | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```dart | 
				
			||||||
 | 
					import 'package:wakelock/wakelock.dart'; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// The following line will enable wakelock. | 
				
			||||||
 | 
					Wakelock.enable(); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// The next line disables the wakelock again. | 
				
			||||||
 | 
					Wakelock.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_platform_interface/wakelock_platform_interface.dart'; | 
				
			||||||
 | 
					import 'com_nokia_mce_request.dart'; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class WakelockAurora extends WakelockPlatformInterface { | 
				
			||||||
 | 
					  bool _enable = false; | 
				
			||||||
 | 
					  Timer? _timer; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  static void registerWith() { | 
				
			||||||
 | 
					    WakelockPlatformInterface.instance = WakelockAurora(); | 
				
			||||||
 | 
					  } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @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_aurora | 
				
			||||||
 | 
					description: A new Flutter plugin project. | 
				
			||||||
 | 
					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_platform_interface: ^0.3.0 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					dev_dependencies: | 
				
			||||||
 | 
					  flutter_test: | 
				
			||||||
 | 
					    sdk: flutter | 
				
			||||||
 | 
					  flutter_lints: ^2.0.0 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					flutter: | 
				
			||||||
 | 
					  plugin: | 
				
			||||||
 | 
					    platforms: | 
				
			||||||
 | 
					      aurora: | 
				
			||||||
 | 
					        dartPluginClass: WakelockAurora | 
				
			||||||
					Loading…
					
					
				
		Reference in new issue