27 changed files with 699 additions and 0 deletions
			
			
		@ -0,0 +1,32 @@
					 | 
				
			||||
# 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/ | 
				
			||||
.metadata | 
				
			||||
run.sh | 
				
			||||
@ -0,0 +1,38 @@
					 | 
				
			||||
# battery_plus_aurora | 
				
			||||
 | 
				
			||||
The Aurora implementation of [`battery_plus`][https://pub.dev/packages/battery_plus]. | 
				
			||||
 | 
				
			||||
## Usage | 
				
			||||
This package is not an _endorsed_ implementation of `battery_plus`.  | 
				
			||||
Therefore, you have to include `battery_plus_aurora` alongside `battery_plus` as dependencies in your `pubspec.yaml` file. | 
				
			||||
 | 
				
			||||
```yaml | 
				
			||||
dependencies: | 
				
			||||
  battery_plus: ^4.0.1 | 
				
			||||
  battery_plus_aurora: | 
				
			||||
    path: # path to folder with plugin | 
				
			||||
``` | 
				
			||||
 | 
				
			||||
```dart | 
				
			||||
// Import package | 
				
			||||
import 'package:battery_plus/battery_plus.dart'; | 
				
			||||
 | 
				
			||||
// Instantiate it | 
				
			||||
var battery = Battery(); | 
				
			||||
 | 
				
			||||
// Get current battery level | 
				
			||||
final batteryLevel = await _battery.batteryLevel; | 
				
			||||
// Get current battery state | 
				
			||||
final batteryState = await _battery.batteryState; | 
				
			||||
// Check is enable SaveMode | 
				
			||||
final isInBatterySaveMode = await _battery.isInBatterySaveMode; | 
				
			||||
 | 
				
			||||
// Be informed when the state (full, charging, discharging) changes | 
				
			||||
_battery.onBatteryStateChanged.listen((BatteryState state) { | 
				
			||||
  debugPrint(state.toString()); | 
				
			||||
}); | 
				
			||||
``` | 
				
			||||
 | 
				
			||||
### Preview example | 
				
			||||
 | 
				
			||||
 | 
				
			||||
@ -0,0 +1 @@
					 | 
				
			||||
include: package:flutter_lints/flutter.yaml | 
				
			||||
@ -0,0 +1,17 @@
					 | 
				
			||||
<?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="get_psm_state"> | 
				
			||||
      <arg direction="out" name="power_saving_mode_active" type="b"/> | 
				
			||||
    </method> | 
				
			||||
    <method name="get_battery_level"> | 
				
			||||
      <arg direction="out" name="battery_level" type="i"/> | 
				
			||||
    </method> | 
				
			||||
    <method name="get_charger_state"> | 
				
			||||
      <arg direction="out" name="charger_state" type="s"/> | 
				
			||||
    </method> | 
				
			||||
  </interface> | 
				
			||||
</node> | 
				
			||||
@ -0,0 +1,15 @@
					 | 
				
			||||
<?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/signal"> | 
				
			||||
  <interface name="com.nokia.mce.signal"> | 
				
			||||
    <signal name="battery_status_ind"> | 
				
			||||
      <arg name="battery_status" type="s"/> | 
				
			||||
    </signal> | 
				
			||||
    <signal name="charger_state_ind"> | 
				
			||||
      <arg name="charger_state" type="s"/> | 
				
			||||
    </signal> | 
				
			||||
  </interface> | 
				
			||||
</node> | 
				
			||||
 | 
				
			||||
| 
		 After Width: | Height: | Size: 73 KiB  | 
@ -0,0 +1,45 @@
					 | 
				
			||||
# 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 | 
				
			||||
**/doc/api/ | 
				
			||||
**/ios/Flutter/.last_build_id | 
				
			||||
.dart_tool/ | 
				
			||||
.flutter-plugins | 
				
			||||
.flutter-plugins-dependencies | 
				
			||||
.packages | 
				
			||||
.pub-cache/ | 
				
			||||
.pub/ | 
				
			||||
/build/ | 
				
			||||
 | 
				
			||||
# Symbolication related | 
				
			||||
app.*.symbols | 
				
			||||
 | 
				
			||||
# Obfuscation related | 
				
			||||
app.*.map.json | 
				
			||||
 | 
				
			||||
# Android Studio will place build artifacts here | 
				
			||||
/android/app/debug | 
				
			||||
/android/app/profile | 
				
			||||
/android/app/release | 
				
			||||
pubspec.lock | 
				
			||||
@ -0,0 +1,17 @@
					 | 
				
			||||
# battery_plus_aurora_example | 
				
			||||
 | 
				
			||||
Demonstrates how to use the battery_plus_aurora plugin. | 
				
			||||
 | 
				
			||||
## Build | 
				
			||||
 | 
				
			||||
```shell | 
				
			||||
# Add an alias if it doesn't already exist | 
				
			||||
alias flutter-aurora=$HOME/.local/opt/flutter-sdk/bin/flutter | 
				
			||||
# Get dependencies | 
				
			||||
flutter-aurora pub get | 
				
			||||
# Run build | 
				
			||||
flutter-aurora build aurora --release | 
				
			||||
``` | 
				
			||||
 | 
				
			||||
You can collect, sign, run an example on the device with a script located in the `script/build_example.sh` | 
				
			||||
More information in `build_example.sh`. | 
				
			||||
@ -0,0 +1 @@
					 | 
				
			||||
include: package:flutter_lints/flutter.yaml | 
				
			||||
@ -0,0 +1 @@
					 | 
				
			||||
flutter/ephemeral | 
				
			||||
@ -0,0 +1,47 @@
					 | 
				
			||||
cmake_minimum_required(VERSION 3.10) | 
				
			||||
project(com.example.battery_plus_aurora_example LANGUAGES CXX) | 
				
			||||
 | 
				
			||||
include(GNUInstallDirs) | 
				
			||||
 | 
				
			||||
set(BINARY_NAME ${CMAKE_PROJECT_NAME}) | 
				
			||||
set(FLUTTER_DIR ${CMAKE_CURRENT_SOURCE_DIR}/flutter) | 
				
			||||
 | 
				
			||||
set(CMAKE_CXX_STANDARD 17) | 
				
			||||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | 
				
			||||
 | 
				
			||||
set(CMAKE_CXX_FLAGS "-Wall -Wextra") | 
				
			||||
set(CMAKE_CXX_FLAGS_RELEASE "-O3") | 
				
			||||
 | 
				
			||||
set(CMAKE_SKIP_RPATH OFF) | 
				
			||||
set(CMAKE_INSTALL_RPATH "\$ORIGIN/../share/${BINARY_NAME}/lib") | 
				
			||||
 | 
				
			||||
find_package(PkgConfig REQUIRED) | 
				
			||||
pkg_check_modules(FlutterEmbedder REQUIRED IMPORTED_TARGET flutter-embedder) | 
				
			||||
 | 
				
			||||
add_executable(${BINARY_NAME} main.cpp ${FLUTTER_DIR}/generated_plugin_registrant.cpp) | 
				
			||||
target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::FlutterEmbedder) | 
				
			||||
target_include_directories(${BINARY_NAME} PRIVATE ${FLUTTER_DIR}) | 
				
			||||
 | 
				
			||||
include(flutter/generated_plugins.cmake) | 
				
			||||
 | 
				
			||||
set(PACKAGE_INSTALL_DIR    ${CMAKE_INSTALL_DATADIR}/${BINARY_NAME}) | 
				
			||||
set(DESKTOP_INSTALL_DIR    ${CMAKE_INSTALL_DATADIR}/applications) | 
				
			||||
set(ICONS_INSTALL_ROOT_DIR ${CMAKE_INSTALL_DATADIR}/icons/hicolor) | 
				
			||||
 | 
				
			||||
add_custom_command(TARGET ${BINARY_NAME} POST_BUILD | 
				
			||||
                   COMMAND ${CMAKE_COMMAND} -E copy | 
				
			||||
                   ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libflutter-embedder.so | 
				
			||||
                   ${PROJECT_BINARY_DIR}/bundle/lib/libflutter-embedder.so) | 
				
			||||
 | 
				
			||||
install(FILES     ${PROJECT_BINARY_DIR}/bundle/icudtl.dat     DESTINATION ${PACKAGE_INSTALL_DIR}) | 
				
			||||
install(DIRECTORY ${PROJECT_BINARY_DIR}/bundle/flutter_assets DESTINATION ${PACKAGE_INSTALL_DIR}) | 
				
			||||
install(DIRECTORY ${PROJECT_BINARY_DIR}/bundle/lib            DESTINATION ${PACKAGE_INSTALL_DIR}) | 
				
			||||
 | 
				
			||||
install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) | 
				
			||||
install(FILES desktop/${BINARY_NAME}.desktop DESTINATION ${DESKTOP_INSTALL_DIR}) | 
				
			||||
 | 
				
			||||
foreach(ICONS_SIZE 86x86 108x108 128x128 172x172) | 
				
			||||
    install(FILES icons/${ICONS_SIZE}.png | 
				
			||||
            RENAME ${BINARY_NAME}.png | 
				
			||||
            DESTINATION ${ICONS_INSTALL_ROOT_DIR}/${ICONS_SIZE}/apps/) | 
				
			||||
endforeach(ICONS_SIZE) | 
				
			||||
@ -0,0 +1,12 @@
					 | 
				
			||||
[Desktop Entry] | 
				
			||||
Type=Application | 
				
			||||
Name=battery_plus_aurora_example | 
				
			||||
Comment=Demonstrates how to use the battery_plus_aurora plugin. | 
				
			||||
Icon=com.example.battery_plus_aurora_example | 
				
			||||
Exec=/usr/bin/com.example.battery_plus_aurora_example | 
				
			||||
X-Nemo-Application-Type=silica-qt5 | 
				
			||||
 | 
				
			||||
[X-Application] | 
				
			||||
Permissions= | 
				
			||||
OrganizationName=com.example | 
				
			||||
ApplicationName=battery_plus_aurora_example | 
				
			||||
@ -0,0 +1,14 @@
					 | 
				
			||||
//
 | 
				
			||||
//  Generated file. Do not edit.
 | 
				
			||||
//
 | 
				
			||||
 | 
				
			||||
// clang-format off
 | 
				
			||||
 | 
				
			||||
#include <flutter/application.h> | 
				
			||||
 | 
				
			||||
#include "generated_plugin_registrant.h" | 
				
			||||
 | 
				
			||||
void RegisterPlugins() { | 
				
			||||
    Application::RegisterPlugins({ | 
				
			||||
    }); | 
				
			||||
} | 
				
			||||
@ -0,0 +1,12 @@
					 | 
				
			||||
//
 | 
				
			||||
//  Generated file. Do not edit.
 | 
				
			||||
//
 | 
				
			||||
 | 
				
			||||
// clang-format off
 | 
				
			||||
 | 
				
			||||
#ifndef GENERATED_PLUGIN_REGISTRANT | 
				
			||||
#define GENERATED_PLUGIN_REGISTRANT | 
				
			||||
 | 
				
			||||
void RegisterPlugins(); | 
				
			||||
 | 
				
			||||
#endif /* GENERATED_PLUGIN_REGISTRANT */ | 
				
			||||
@ -0,0 +1,30 @@
					 | 
				
			||||
# | 
				
			||||
# Generated file, do not edit. | 
				
			||||
# | 
				
			||||
set(ROOT_PROJECT_BINARY_DIR "${PROJECT_BINARY_DIR}") | 
				
			||||
 | 
				
			||||
function(add_library TARGET) | 
				
			||||
    _add_library(${TARGET} ${ARGN}) | 
				
			||||
 | 
				
			||||
    if(NOT "${TARGET}" MATCHES "^PkgConfig::.*") | 
				
			||||
      add_custom_command(TARGET ${TARGET} POST_BUILD | 
				
			||||
                        COMMAND ${CMAKE_COMMAND} -E copy | 
				
			||||
                        "$<TARGET_FILE:${TARGET}>" | 
				
			||||
                        "${ROOT_PROJECT_BINARY_DIR}/bundle/lib/$<TARGET_FILE_NAME:${TARGET}>") | 
				
			||||
    endif(NOT "${TARGET}" MATCHES "^PkgConfig::.*") | 
				
			||||
endfunction() | 
				
			||||
 | 
				
			||||
list(APPEND FLUTTER_PLATFORM_PLUGIN_LIST | 
				
			||||
) | 
				
			||||
 | 
				
			||||
list(APPEND FLUTTER_FFI_PLUGIN_LIST | 
				
			||||
) | 
				
			||||
 | 
				
			||||
foreach(PLUGIN ${FLUTTER_PLATFORM_PLUGIN_LIST}) | 
				
			||||
    add_subdirectory(flutter/ephemeral/.plugin_symlinks/${PLUGIN}/aurora plugins/${PLUGIN}) | 
				
			||||
    target_link_libraries(${BINARY_NAME} PRIVATE ${PLUGIN}_platform_plugin) | 
				
			||||
endforeach(PLUGIN) | 
				
			||||
 | 
				
			||||
foreach(FFI_PLUGIN ${FLUTTER_FFI_PLUGIN_LIST}) | 
				
			||||
    add_subdirectory(flutter/ephemeral/.plugin_symlinks/${FFI_PLUGIN}/aurora plugins/${FFI_PLUGIN}) | 
				
			||||
endforeach(FFI_PLUGIN) | 
				
			||||
| 
		 After Width: | Height: | Size: 9.7 KiB  | 
| 
		 After Width: | Height: | Size: 13 KiB  | 
| 
		 After Width: | Height: | Size: 23 KiB  | 
| 
		 After Width: | Height: | Size: 6.5 KiB  | 
@ -0,0 +1,10 @@
					 | 
				
			||||
#include <flutter/application.h> | 
				
			||||
#include "generated_plugin_registrant.h" | 
				
			||||
 | 
				
			||||
int main(int argc, char *argv[]) { | 
				
			||||
    Application::Initialize(argc, argv); | 
				
			||||
    Application::SetPixelRatio(1.8); | 
				
			||||
    RegisterPlugins(); | 
				
			||||
    Application::Launch(); | 
				
			||||
    return 0; | 
				
			||||
} | 
				
			||||
@ -0,0 +1,31 @@
					 | 
				
			||||
%global __provides_exclude_from ^%{_datadir}/%{name}/lib/.*$ | 
				
			||||
%global __requires_exclude ^lib(dconf|flutter-embedder|maliit-glib|appmanifest-.+|.+_platform_plugin)\\.so.*$ | 
				
			||||
 | 
				
			||||
Name: com.example.battery_plus_aurora_example | 
				
			||||
Summary: Demonstrates how to use the battery_plus_aurora plugin. | 
				
			||||
Version: 0.1.0 | 
				
			||||
Release: 1 | 
				
			||||
License: Proprietary | 
				
			||||
Source0: %{name}-%{version}.tar.zst | 
				
			||||
 | 
				
			||||
BuildRequires: cmake | 
				
			||||
BuildRequires: pkgconfig(flutter-embedder) | 
				
			||||
 | 
				
			||||
%description | 
				
			||||
%{summary}. | 
				
			||||
 | 
				
			||||
%prep | 
				
			||||
%autosetup | 
				
			||||
 | 
				
			||||
%build | 
				
			||||
%cmake -DCMAKE_BUILD_TYPE=%{_flutter_build_type} | 
				
			||||
%make_build | 
				
			||||
 | 
				
			||||
%install | 
				
			||||
%make_install | 
				
			||||
 | 
				
			||||
%files | 
				
			||||
%{_bindir}/%{name} | 
				
			||||
%{_datadir}/%{name}/* | 
				
			||||
%{_datadir}/applications/%{name}.desktop | 
				
			||||
%{_datadir}/icons/hicolor/*/apps/%{name}.png | 
				
			||||
@ -0,0 +1,160 @@
					 | 
				
			||||
import 'package:flutter/material.dart'; | 
				
			||||
import 'dart:async'; | 
				
			||||
 | 
				
			||||
import 'package:battery_plus/battery_plus.dart'; | 
				
			||||
 | 
				
			||||
void main() { | 
				
			||||
  runApp(const MyApp()); | 
				
			||||
} | 
				
			||||
 | 
				
			||||
class MyApp extends StatefulWidget { | 
				
			||||
  const MyApp({super.key}); | 
				
			||||
 | 
				
			||||
  @override | 
				
			||||
  State<MyApp> createState() => _MyAppState(); | 
				
			||||
} | 
				
			||||
 | 
				
			||||
class _MyAppState extends State<MyApp> { | 
				
			||||
  final _battery = Battery(); | 
				
			||||
  String? _error; | 
				
			||||
  int? _batteryLevel; | 
				
			||||
  String? _batteryState; | 
				
			||||
  bool? _isInBatterySaveMode; | 
				
			||||
 | 
				
			||||
  @override | 
				
			||||
  void initState() { | 
				
			||||
    super.initState(); | 
				
			||||
    initPlatformState(); | 
				
			||||
  } | 
				
			||||
 | 
				
			||||
  // Platform messages are asynchronous, so we initialize in an async method. | 
				
			||||
  Future<void> initPlatformState() async { | 
				
			||||
    try { | 
				
			||||
      // Get current battery level | 
				
			||||
      final batteryLevel = await _battery.batteryLevel; | 
				
			||||
      // Get current battery state | 
				
			||||
      final batteryState = await _battery.batteryState; | 
				
			||||
      // Check is enable SaveMode | 
				
			||||
      final isInBatterySaveMode = await _battery.isInBatterySaveMode; | 
				
			||||
 | 
				
			||||
      // Be informed when the state (full, charging, discharging) changes | 
				
			||||
      _battery.onBatteryStateChanged.listen((BatteryState state) { | 
				
			||||
        debugPrint(state.toString()); | 
				
			||||
      }); | 
				
			||||
 | 
				
			||||
      setState(() { | 
				
			||||
        _batteryLevel = batteryLevel; | 
				
			||||
        _batteryState = batteryState.name; | 
				
			||||
        _isInBatterySaveMode = isInBatterySaveMode; | 
				
			||||
      }); | 
				
			||||
    } on Exception catch (e) { | 
				
			||||
      setState(() { | 
				
			||||
        _error = e.toString(); | 
				
			||||
      }); | 
				
			||||
    } | 
				
			||||
  } | 
				
			||||
 | 
				
			||||
  @override | 
				
			||||
  Widget build(BuildContext context) { | 
				
			||||
    const textStyleWhite = TextStyle(fontSize: 18, color: Colors.white); | 
				
			||||
    const textStyleTitle = TextStyle(fontSize: 20, color: Colors.black); | 
				
			||||
    const textStylePath = TextStyle(fontSize: 18, color: Colors.black54); | 
				
			||||
 | 
				
			||||
    const spaceMedium = SizedBox(height: 20); | 
				
			||||
    const spaceSmall = SizedBox(height: 10); | 
				
			||||
 | 
				
			||||
    return MaterialApp( | 
				
			||||
      home: Scaffold( | 
				
			||||
        appBar: AppBar( | 
				
			||||
          title: const Text('Example battery_plus'), | 
				
			||||
        ), | 
				
			||||
        body: Stack( | 
				
			||||
          children: [ | 
				
			||||
            // Error message | 
				
			||||
            Visibility( | 
				
			||||
              visible: _error != null, | 
				
			||||
              child: Center( | 
				
			||||
                child: Padding( | 
				
			||||
                  padding: const EdgeInsets.all(16), | 
				
			||||
                  child: Container( | 
				
			||||
                    padding: const EdgeInsets.all(20), | 
				
			||||
                    decoration: const BoxDecoration( | 
				
			||||
                      color: Colors.redAccent, | 
				
			||||
                      borderRadius: BorderRadius.all(Radius.circular(10.0)), | 
				
			||||
                    ), | 
				
			||||
                    child: Text( | 
				
			||||
                      _error ?? '', | 
				
			||||
                      style: textStyleWhite, | 
				
			||||
                    ), | 
				
			||||
                  ), | 
				
			||||
                ), | 
				
			||||
              ), | 
				
			||||
            ), | 
				
			||||
            // List directories path | 
				
			||||
            Visibility( | 
				
			||||
              visible: _error == null, | 
				
			||||
              child: SingleChildScrollView( | 
				
			||||
                child: Padding( | 
				
			||||
                  padding: const EdgeInsets.all(16), | 
				
			||||
                  child: Center( | 
				
			||||
                    child: Column( | 
				
			||||
                      children: [ | 
				
			||||
                        // Info | 
				
			||||
                        Container( | 
				
			||||
                          padding: const EdgeInsets.all(20), | 
				
			||||
                          decoration: const BoxDecoration( | 
				
			||||
                            color: Colors.green, | 
				
			||||
                            borderRadius: | 
				
			||||
                                BorderRadius.all(Radius.circular(10.0)), | 
				
			||||
                          ), | 
				
			||||
                          child: const Text( | 
				
			||||
                            'Demo application demonstration implementation of battery_plus', | 
				
			||||
                            style: textStyleWhite, | 
				
			||||
                            textAlign: TextAlign.center, | 
				
			||||
                          ), | 
				
			||||
                        ), | 
				
			||||
                        const SizedBox(height: 30), | 
				
			||||
 | 
				
			||||
                        const Text( | 
				
			||||
                          'Battery Level', | 
				
			||||
                          style: textStyleTitle, | 
				
			||||
                        ), | 
				
			||||
                        spaceSmall, | 
				
			||||
                        Text( | 
				
			||||
                          "$_batteryLevel%", | 
				
			||||
                          style: textStylePath, | 
				
			||||
                        ), | 
				
			||||
 | 
				
			||||
                        spaceMedium, | 
				
			||||
                        const Text( | 
				
			||||
                          'Battery State', | 
				
			||||
                          style: textStyleTitle, | 
				
			||||
                        ), | 
				
			||||
                        spaceSmall, | 
				
			||||
                        Text( | 
				
			||||
                          _batteryState.toString(), | 
				
			||||
                          style: textStylePath, | 
				
			||||
                        ), | 
				
			||||
 | 
				
			||||
                        spaceMedium, | 
				
			||||
                        const Text( | 
				
			||||
                          'Is In Battery SaveMode', | 
				
			||||
                          style: textStyleTitle, | 
				
			||||
                        ), | 
				
			||||
                        spaceSmall, | 
				
			||||
                        Text( | 
				
			||||
                          _isInBatterySaveMode.toString(), | 
				
			||||
                          style: textStylePath, | 
				
			||||
                        ), | 
				
			||||
                      ], | 
				
			||||
                    ), | 
				
			||||
                  ), | 
				
			||||
                ), | 
				
			||||
              ), | 
				
			||||
            ), | 
				
			||||
          ], | 
				
			||||
        ), | 
				
			||||
      ), | 
				
			||||
    ); | 
				
			||||
  } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,23 @@
					 | 
				
			||||
name: battery_plus_aurora_example | 
				
			||||
description: Demonstrates how to use the battery_plus_aurora plugin. | 
				
			||||
 | 
				
			||||
publish_to: 'none' | 
				
			||||
 | 
				
			||||
environment: | 
				
			||||
  sdk: '>=2.18.6 <3.0.0' | 
				
			||||
 | 
				
			||||
dependencies: | 
				
			||||
  flutter: | 
				
			||||
    sdk: flutter | 
				
			||||
  battery_plus: ^4.0.1 | 
				
			||||
  battery_plus_aurora: | 
				
			||||
    path: ../ | 
				
			||||
  cupertino_icons: ^1.0.2 | 
				
			||||
 | 
				
			||||
dev_dependencies: | 
				
			||||
  flutter_test: | 
				
			||||
    sdk: flutter | 
				
			||||
  flutter_lints: ^2.0.0 | 
				
			||||
 | 
				
			||||
flutter: | 
				
			||||
  uses-material-design: true | 
				
			||||
@ -0,0 +1,88 @@
					 | 
				
			||||
import 'package:battery_plus_aurora/com_nokia_mce_request.dart'; | 
				
			||||
import 'package:battery_plus_aurora/com_nokia_mce_signal.dart'; | 
				
			||||
import 'package:dbus/dbus.dart'; | 
				
			||||
import 'package:battery_plus_platform_interface/battery_plus_platform_interface.dart'; | 
				
			||||
import 'package:flutter/foundation.dart'; | 
				
			||||
import 'dart:async' show Stream; | 
				
			||||
import 'package:async/async.dart' show StreamGroup; | 
				
			||||
 | 
				
			||||
class BatteryPlusAurora extends BatteryPlatform { | 
				
			||||
  /// Register this dart class as the platform implementation for aurora | 
				
			||||
  static void registerWith() { | 
				
			||||
    if (TargetPlatform.aurora == defaultTargetPlatform) { | 
				
			||||
      BatteryPlatform.instance = BatteryPlusAurora(); | 
				
			||||
    } | 
				
			||||
  } | 
				
			||||
 | 
				
			||||
  /// Returns the current battery level in percent. | 
				
			||||
  @override | 
				
			||||
  Future<int> get batteryLevel async { | 
				
			||||
    final client = DBusClient.system(); | 
				
			||||
    final request = ComNokiaMceRequest(client, 'com.nokia.mce'); | 
				
			||||
    final level = await request.callget_battery_level(); | 
				
			||||
    await client.close(); | 
				
			||||
    return level; | 
				
			||||
  } | 
				
			||||
 | 
				
			||||
  /// Returns true if the device is on battery save mode | 
				
			||||
  @override | 
				
			||||
  Future<bool> get isInBatterySaveMode async { | 
				
			||||
    final client = DBusClient.system(); | 
				
			||||
    final request = ComNokiaMceRequest(client, 'com.nokia.mce'); | 
				
			||||
    final state = await request.callget_psm_state(); | 
				
			||||
    await client.close(); | 
				
			||||
    return state; | 
				
			||||
  } | 
				
			||||
 | 
				
			||||
  /// Returns the current battery state in percent. | 
				
			||||
  @override | 
				
			||||
  Future<BatteryState> get batteryState async { | 
				
			||||
    final client = DBusClient.system(); | 
				
			||||
    final request = ComNokiaMceRequest(client, 'com.nokia.mce'); | 
				
			||||
 | 
				
			||||
    final level = await request.callget_battery_level(); | 
				
			||||
    final status = await request.callget_charger_state(); | 
				
			||||
 | 
				
			||||
    await client.close(); | 
				
			||||
 | 
				
			||||
    if (level == 100) { | 
				
			||||
      return BatteryState.full; | 
				
			||||
    } else if (status == 'on') { | 
				
			||||
      return BatteryState.charging; | 
				
			||||
    } else { | 
				
			||||
      return BatteryState.discharging; | 
				
			||||
    } | 
				
			||||
  } | 
				
			||||
 | 
				
			||||
  /// Returns a Stream of BatteryState changes. | 
				
			||||
  @override | 
				
			||||
  Stream<BatteryState> get onBatteryStateChanged async* { | 
				
			||||
    final client = DBusClient.system(); | 
				
			||||
    final signal = ComNokiaMceSignal(client, 'com.nokia.mce'); | 
				
			||||
    final request = ComNokiaMceRequest(client, 'com.nokia.mce'); | 
				
			||||
 | 
				
			||||
    var steam = StreamGroup.merge([ | 
				
			||||
      signal.battery_status_ind, | 
				
			||||
      signal.charger_state_ind, | 
				
			||||
    ]); | 
				
			||||
 | 
				
			||||
    await for (final event in steam) { | 
				
			||||
      if (event.name == 'battery_status_ind') { | 
				
			||||
        if (event.values.first.toNative() == 'full') { | 
				
			||||
          yield BatteryState.full; | 
				
			||||
        } | 
				
			||||
      } else { | 
				
			||||
        if (event.values.first.toNative() == 'on') { | 
				
			||||
          yield BatteryState.charging; | 
				
			||||
          final level = await request.callget_battery_level(); | 
				
			||||
          if (level == 100) { | 
				
			||||
            yield BatteryState.full; | 
				
			||||
          } | 
				
			||||
        } else { | 
				
			||||
          yield BatteryState.discharging; | 
				
			||||
        } | 
				
			||||
      } | 
				
			||||
    } | 
				
			||||
    await client.close(); | 
				
			||||
  } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,46 @@
					 | 
				
			||||
// This file was generated using the following command and may be overwritten. | 
				
			||||
// dart-dbus generate-remote-object data/com.nokia.mce.request.xml | 
				
			||||
 | 
				
			||||
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.get_psm_state() | 
				
			||||
  Future<bool> callget_psm_state( | 
				
			||||
      {bool noAutoStart = false, | 
				
			||||
      bool allowInteractiveAuthorization = false}) async { | 
				
			||||
    var result = await callMethod('com.nokia.mce.request', 'get_psm_state', [], | 
				
			||||
        replySignature: DBusSignature('b'), | 
				
			||||
        noAutoStart: noAutoStart, | 
				
			||||
        allowInteractiveAuthorization: allowInteractiveAuthorization); | 
				
			||||
    return result.returnValues[0].asBoolean(); | 
				
			||||
  } | 
				
			||||
 | 
				
			||||
  /// Invokes com.nokia.mce.request.get_battery_level() | 
				
			||||
  Future<int> callget_battery_level( | 
				
			||||
      {bool noAutoStart = false, | 
				
			||||
      bool allowInteractiveAuthorization = false}) async { | 
				
			||||
    var result = await callMethod( | 
				
			||||
        'com.nokia.mce.request', 'get_battery_level', [], | 
				
			||||
        replySignature: DBusSignature('i'), | 
				
			||||
        noAutoStart: noAutoStart, | 
				
			||||
        allowInteractiveAuthorization: allowInteractiveAuthorization); | 
				
			||||
    return result.returnValues[0].asInt32(); | 
				
			||||
  } | 
				
			||||
 | 
				
			||||
  /// Invokes com.nokia.mce.request.get_charger_state() | 
				
			||||
  Future<String> callget_charger_state( | 
				
			||||
      {bool noAutoStart = false, | 
				
			||||
      bool allowInteractiveAuthorization = false}) async { | 
				
			||||
    var result = await callMethod( | 
				
			||||
        'com.nokia.mce.request', 'get_charger_state', [], | 
				
			||||
        replySignature: DBusSignature('s'), | 
				
			||||
        noAutoStart: noAutoStart, | 
				
			||||
        allowInteractiveAuthorization: allowInteractiveAuthorization); | 
				
			||||
    return result.returnValues[0].asString(); | 
				
			||||
  } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,32 @@
					 | 
				
			||||
// This file was generated using the following command and may be overwritten. | 
				
			||||
// dart-dbus generate-remote-object data/com.nokia.mce.signal.xml | 
				
			||||
 | 
				
			||||
import 'package:dbus/dbus.dart'; | 
				
			||||
 | 
				
			||||
/// Signal data for com.nokia.mce.signal.battery_status_ind. | 
				
			||||
class ComNokiaMceSignalbattery_status_ind extends DBusSignal { | 
				
			||||
  String get battery_status => values[0].asString(); | 
				
			||||
 | 
				
			||||
  ComNokiaMceSignalbattery_status_ind(DBusSignal signal) : super(sender: signal.sender, path: signal.path, interface: signal.interface, name: signal.name, values: signal.values); | 
				
			||||
} | 
				
			||||
 | 
				
			||||
/// Signal data for com.nokia.mce.signal.charger_state_ind. | 
				
			||||
class ComNokiaMceSignalcharger_state_ind extends DBusSignal { | 
				
			||||
  String get charger_state => values[0].asString(); | 
				
			||||
 | 
				
			||||
  ComNokiaMceSignalcharger_state_ind(DBusSignal signal) : super(sender: signal.sender, path: signal.path, interface: signal.interface, name: signal.name, values: signal.values); | 
				
			||||
} | 
				
			||||
 | 
				
			||||
class ComNokiaMceSignal extends DBusRemoteObject { | 
				
			||||
  /// Stream of com.nokia.mce.signal.battery_status_ind signals. | 
				
			||||
  late final Stream<ComNokiaMceSignalbattery_status_ind> battery_status_ind; | 
				
			||||
 | 
				
			||||
  /// Stream of com.nokia.mce.signal.charger_state_ind signals. | 
				
			||||
  late final Stream<ComNokiaMceSignalcharger_state_ind> charger_state_ind; | 
				
			||||
 | 
				
			||||
  ComNokiaMceSignal(DBusClient client, String destination, {DBusObjectPath path = const DBusObjectPath.unchecked('/com/nokia/mce/signal')}) : super(client, name: destination, path: path) { | 
				
			||||
    battery_status_ind = DBusRemoteObjectSignalStream(object: this, interface: 'com.nokia.mce.signal', name: 'battery_status_ind', signature: DBusSignature('s')).asBroadcastStream().map((signal) => ComNokiaMceSignalbattery_status_ind(signal)); | 
				
			||||
 | 
				
			||||
    charger_state_ind = DBusRemoteObjectSignalStream(object: this, interface: 'com.nokia.mce.signal', name: 'charger_state_ind', signature: DBusSignature('s')).asBroadcastStream().map((signal) => ComNokiaMceSignalcharger_state_ind(signal)); | 
				
			||||
  } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,27 @@
					 | 
				
			||||
name: battery_plus_aurora | 
				
			||||
description: The Aurora OS implementation of battery_plus. | 
				
			||||
version: 0.0.1 | 
				
			||||
homepage: | 
				
			||||
 | 
				
			||||
environment: | 
				
			||||
  sdk: '>=2.18.6 <3.0.0' | 
				
			||||
  flutter: ">=2.5.0" | 
				
			||||
 | 
				
			||||
dependencies: | 
				
			||||
  flutter: | 
				
			||||
    sdk: flutter | 
				
			||||
  dbus: ^0.7.8 | 
				
			||||
  async: ^2.11.0 | 
				
			||||
  plugin_platform_interface: ^2.0.2 | 
				
			||||
  battery_plus_platform_interface: ^1.2.2 | 
				
			||||
 | 
				
			||||
dev_dependencies: | 
				
			||||
  flutter_test: | 
				
			||||
    sdk: flutter | 
				
			||||
  flutter_lints: ^2.0.0 | 
				
			||||
 | 
				
			||||
flutter: | 
				
			||||
  plugin: | 
				
			||||
    platforms: | 
				
			||||
      aurora: | 
				
			||||
        dartPluginClass: BatteryPlusAurora | 
				
			||||
					Loading…
					
					
				
		Reference in new issue