Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(codecov): add codecov github runner #11

Merged
merged 3 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Test

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

# Note: This workflow uses the latest stable version of the Dart SDK.
# You can specify other versions if desired, see documentation here:
# https://github.com/dart-lang/setup-dart/blob/main/README.md
# - uses: dart-lang/setup-dart@v1
- uses: subosito/flutter-action@v2

- name: Disable analytics
run: flutter config --no-analytics

- name: Install dependencies
run: flutter pub get

- name: Verify formatting
run: dart format --output=none --set-exit-if-changed .

# Consider passing '--fatal-infos' for slightly stricter analysis.
- name: Analyze project source
run: flutter analyze --fatal-infos
working-directory: lib

- name: Run tests
run: flutter test --coverage --update-goldens

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[![pub package](https://img.shields.io/pub/v/flutter_google_wallet.svg)](https://pub.dev/packages/flutter_eco_mode)
[![Test](https://github.com/voyages-sncf-technologies/flutter_eco_mode/actions/workflows/test.yaml/badge.svg)](https://github.com/voyages-sncf-technologies/flutter_eco_mode/actions/workflows/test.yaml)
[![codecov](https://codecov.io/gh/voyages-sncf-technologies/flutter_eco_mode/branch/main/graph/badge.svg)](https://codecov.io/gh/voyages-sncf-technologies/flutter_eco_mode)

# flutter_eco_mode

A Flutter plugin to help implementing custom eco-friendly mode in your mobile app. This plugin will tell you if a device
Expand Down
75 changes: 53 additions & 22 deletions example/lib/results.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,50 +24,81 @@ class _ResultsState extends State<Results> {
Widget build(BuildContext context) {
return _ResultsView(
[
_ResultLine(label: 'Platform info', widget: _ResultFuture(plugin.getPlatformInfo)),
_ResultLine(label: 'Battery level', widget: _ResultFuture(plugin.getBatteryLevelPercent)),
_ResultLine(label: 'Battery state', widget: _ResultFuture(plugin.getBatteryStateName)),
_ResultLine(label: 'Is battery in low power mode', widget: _ResultFuture(plugin.isBatteryEcoMode)),
_ResultLine(
label: 'Platform info',
widget: _ResultFuture(plugin.getPlatformInfo)),
_ResultLine(
label: 'Battery level',
widget: _ResultFuture(plugin.getBatteryLevelPercent)),
_ResultLine(
label: 'Battery state',
widget: _ResultFuture(plugin.getBatteryStateName)),
_ResultLine(
label: 'Is battery in low power mode',
widget: _ResultFuture(plugin.isBatteryEcoMode)),
_ResultLine(
label: 'Low power mode event stream',
widget: _ResultStream(
plugin.lowPowerModeEventStream,
initialFuture: plugin.isBatteryEcoMode,
),
),
_ResultLine(label: 'Thermal state', widget: _ResultFuture(plugin.getThermalStateName)),
_ResultLine(label: 'Processor count', widget: _ResultFuture(plugin.getProcessorCount)),
_ResultLine(label: 'Total memory', widget: _ResultFuture(plugin.getTotalMemory)),
_ResultLine(label: 'Free memory', widget: _ResultFuture(plugin.getFreeMemoryReachable)),
_ResultLine(label: 'Total storage', widget: _ResultFuture(plugin.getTotalStorage)),
_ResultLine(label: 'Free storage', widget: _ResultFuture(plugin.getFreeStorage)),
_ResultLine(label: 'Is battery in eco mode', widget: _ResultFuture(plugin.isBatteryEcoMode)),
_ResultLine(label: 'Eco range score', widget: _ResultFuture(ecoRange.getScore)),
_ResultLine(label: 'Device eco range', widget: _ResultFuture(ecoRange.getRange)),
_ResultLine(label: 'Is low end device', widget: _ResultFuture(ecoRange.isLowEndDevice)),
_ResultLine(
label: 'Thermal state',
widget: _ResultFuture(plugin.getThermalStateName)),
_ResultLine(
label: 'Processor count',
widget: _ResultFuture(plugin.getProcessorCount)),
_ResultLine(
label: 'Total memory',
widget: _ResultFuture(plugin.getTotalMemory)),
_ResultLine(
label: 'Free memory',
widget: _ResultFuture(plugin.getFreeMemoryReachable)),
_ResultLine(
label: 'Total storage',
widget: _ResultFuture(plugin.getTotalStorage)),
_ResultLine(
label: 'Free storage',
widget: _ResultFuture(plugin.getFreeStorage)),
_ResultLine(
label: 'Is battery in eco mode',
widget: _ResultFuture(plugin.isBatteryEcoMode)),
_ResultLine(
label: 'Eco range score', widget: _ResultFuture(ecoRange.getScore)),
_ResultLine(
label: 'Device eco range',
widget: _ResultFuture(ecoRange.getRange)),
_ResultLine(
label: 'Is low end device',
widget: _ResultFuture(ecoRange.isLowEndDevice)),
],
);
}
}

extension on FlutterEcoMode {
Future<String> getBatteryStateName() => getBatteryState().then((value) => value.name);
Future<String> getBatteryStateName() =>
getBatteryState().then((value) => value.name);

Future<String> getThermalStateName() => getThermalState().then((value) => value.name);
Future<String> getThermalStateName() =>
getThermalState().then((value) => value.name);

Future<String> getFreeMemoryReachable() =>
getFreeMemory().then((value) => value > 0 ? value.toString() : "not reachable");
Future<String> getFreeMemoryReachable() => getFreeMemory()
.then((value) => value > 0 ? value.toString() : "not reachable");

Future<String> getBatteryLevelPercent() =>
getBatteryLevel().then((value) => value != null && value > 0 ? "${value.toInt()} %" : "not reachable");
Future<String> getBatteryLevelPercent() => getBatteryLevel().then((value) =>
value != null && value > 0 ? "${value.toInt()} %" : "not reachable");
}

extension on Future<EcoRange?> {
Future<String?> getScore() => then((value) => value?.score != null ? "${(value!.score * 100).toInt()}/100" : null);
Future<String?> getScore() => then((value) =>
value?.score != null ? "${(value!.score * 100).toInt()}/100" : null);

Future<String?> getRange() => then((value) => value?.range.name);

Future<String?> isLowEndDevice() => then((value) => value?.isLowEndDevice.toString());
Future<String?> isLowEndDevice() =>
then((value) => value?.isLowEndDevice.toString());
}

class _ResultLine {
Expand Down
14 changes: 10 additions & 4 deletions lib/flutter_eco_mode.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class FlutterEcoMode extends FlutterEcoModePlatform {

FlutterEcoMode({EcoModeApi? api}) : _api = api ?? EcoModeApi();

static const eventChannel = EventChannel('sncf.connect.tech/battery.isLowPowerMode');
static const eventChannel =
EventChannel('sncf.connect.tech/battery.isLowPowerMode');

@override
Future<String?> getPlatformInfo() async {
Expand Down Expand Up @@ -84,7 +85,10 @@ class FlutterEcoMode extends FlutterEcoModePlatform {
throw Exception('Error while getting eco score');
}
final range = _buildRange(value);
return EcoRange(score: value, range: range, isLowEndDevice: range == DeviceEcoRange.lowEnd);
return EcoRange(
score: value,
range: range,
isLowEndDevice: range == DeviceEcoRange.lowEnd);
}).onError((error, stackTrace) {
log(stackTrace.toString(), error: error);
return null;
Expand Down Expand Up @@ -124,7 +128,8 @@ class FlutterEcoMode extends FlutterEcoModePlatform {
return Future.wait([
Future<bool?>.value((await getBatteryLevel())?.isNotEnough),
Future<bool?>.value((await getBatteryState()).isDischarging),
]).then((List<bool?> value) => value.every((bool? element) => element ?? false));
]).then((List<bool?> value) =>
value.every((bool? element) => element ?? false));
} catch (error, stackTrace) {
log(stackTrace.toString(), error: error);
return null;
Expand Down Expand Up @@ -159,5 +164,6 @@ extension on BatteryState {
}

extension on ThermalState {
bool get isSeriousAtLeast => this == ThermalState.serious || this == ThermalState.critical;
bool get isSeriousAtLeast =>
this == ThermalState.serious || this == ThermalState.critical;
}
79 changes: 54 additions & 25 deletions lib/messages.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ enum BatteryState {
enum ThermalState {
/// nominal value
safe,

/// device is getting warm, but not under throttling
fair,

/// device is getting warm and performance is throttled
serious,

/// performance is throttled, device is too hot
critical,

/// unknown state
unknown,
}
Expand All @@ -39,18 +43,23 @@ class EcoModeApi {
/// Constructor for [EcoModeApi]. The [binaryMessenger] named argument is
/// available for dependency injection. If it is left null, the default
/// BinaryMessenger will be used which routes to the host platform.
EcoModeApi({BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''})
EcoModeApi(
{BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''})
: __pigeon_binaryMessenger = binaryMessenger,
__pigeon_messageChannelSuffix = messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : '';
__pigeon_messageChannelSuffix =
messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : '';
final BinaryMessenger? __pigeon_binaryMessenger;

static const MessageCodec<Object?> pigeonChannelCodec = StandardMessageCodec();
static const MessageCodec<Object?> pigeonChannelCodec =
StandardMessageCodec();

final String __pigeon_messageChannelSuffix;

Future<String> getPlatformInfo() async {
final String __pigeon_channelName = 'dev.flutter.pigeon.flutter_eco_mode.EcoModeApi.getPlatformInfo$__pigeon_messageChannelSuffix';
final BasicMessageChannel<Object?> __pigeon_channel = BasicMessageChannel<Object?>(
final String __pigeon_channelName =
'dev.flutter.pigeon.flutter_eco_mode.EcoModeApi.getPlatformInfo$__pigeon_messageChannelSuffix';
final BasicMessageChannel<Object?> __pigeon_channel =
BasicMessageChannel<Object?>(
__pigeon_channelName,
pigeonChannelCodec,
binaryMessenger: __pigeon_binaryMessenger,
Expand All @@ -76,8 +85,10 @@ class EcoModeApi {
}

Future<double> getBatteryLevel() async {
final String __pigeon_channelName = 'dev.flutter.pigeon.flutter_eco_mode.EcoModeApi.getBatteryLevel$__pigeon_messageChannelSuffix';
final BasicMessageChannel<Object?> __pigeon_channel = BasicMessageChannel<Object?>(
final String __pigeon_channelName =
'dev.flutter.pigeon.flutter_eco_mode.EcoModeApi.getBatteryLevel$__pigeon_messageChannelSuffix';
final BasicMessageChannel<Object?> __pigeon_channel =
BasicMessageChannel<Object?>(
__pigeon_channelName,
pigeonChannelCodec,
binaryMessenger: __pigeon_binaryMessenger,
Expand All @@ -103,8 +114,10 @@ class EcoModeApi {
}

Future<BatteryState> getBatteryState() async {
final String __pigeon_channelName = 'dev.flutter.pigeon.flutter_eco_mode.EcoModeApi.getBatteryState$__pigeon_messageChannelSuffix';
final BasicMessageChannel<Object?> __pigeon_channel = BasicMessageChannel<Object?>(
final String __pigeon_channelName =
'dev.flutter.pigeon.flutter_eco_mode.EcoModeApi.getBatteryState$__pigeon_messageChannelSuffix';
final BasicMessageChannel<Object?> __pigeon_channel =
BasicMessageChannel<Object?>(
__pigeon_channelName,
pigeonChannelCodec,
binaryMessenger: __pigeon_binaryMessenger,
Expand All @@ -130,8 +143,10 @@ class EcoModeApi {
}

Future<bool> isBatteryInLowPowerMode() async {
final String __pigeon_channelName = 'dev.flutter.pigeon.flutter_eco_mode.EcoModeApi.isBatteryInLowPowerMode$__pigeon_messageChannelSuffix';
final BasicMessageChannel<Object?> __pigeon_channel = BasicMessageChannel<Object?>(
final String __pigeon_channelName =
'dev.flutter.pigeon.flutter_eco_mode.EcoModeApi.isBatteryInLowPowerMode$__pigeon_messageChannelSuffix';
final BasicMessageChannel<Object?> __pigeon_channel =
BasicMessageChannel<Object?>(
__pigeon_channelName,
pigeonChannelCodec,
binaryMessenger: __pigeon_binaryMessenger,
Expand All @@ -157,8 +172,10 @@ class EcoModeApi {
}

Future<ThermalState> getThermalState() async {
final String __pigeon_channelName = 'dev.flutter.pigeon.flutter_eco_mode.EcoModeApi.getThermalState$__pigeon_messageChannelSuffix';
final BasicMessageChannel<Object?> __pigeon_channel = BasicMessageChannel<Object?>(
final String __pigeon_channelName =
'dev.flutter.pigeon.flutter_eco_mode.EcoModeApi.getThermalState$__pigeon_messageChannelSuffix';
final BasicMessageChannel<Object?> __pigeon_channel =
BasicMessageChannel<Object?>(
__pigeon_channelName,
pigeonChannelCodec,
binaryMessenger: __pigeon_binaryMessenger,
Expand All @@ -184,8 +201,10 @@ class EcoModeApi {
}

Future<int> getProcessorCount() async {
final String __pigeon_channelName = 'dev.flutter.pigeon.flutter_eco_mode.EcoModeApi.getProcessorCount$__pigeon_messageChannelSuffix';
final BasicMessageChannel<Object?> __pigeon_channel = BasicMessageChannel<Object?>(
final String __pigeon_channelName =
'dev.flutter.pigeon.flutter_eco_mode.EcoModeApi.getProcessorCount$__pigeon_messageChannelSuffix';
final BasicMessageChannel<Object?> __pigeon_channel =
BasicMessageChannel<Object?>(
__pigeon_channelName,
pigeonChannelCodec,
binaryMessenger: __pigeon_binaryMessenger,
Expand All @@ -211,8 +230,10 @@ class EcoModeApi {
}

Future<int> getTotalMemory() async {
final String __pigeon_channelName = 'dev.flutter.pigeon.flutter_eco_mode.EcoModeApi.getTotalMemory$__pigeon_messageChannelSuffix';
final BasicMessageChannel<Object?> __pigeon_channel = BasicMessageChannel<Object?>(
final String __pigeon_channelName =
'dev.flutter.pigeon.flutter_eco_mode.EcoModeApi.getTotalMemory$__pigeon_messageChannelSuffix';
final BasicMessageChannel<Object?> __pigeon_channel =
BasicMessageChannel<Object?>(
__pigeon_channelName,
pigeonChannelCodec,
binaryMessenger: __pigeon_binaryMessenger,
Expand All @@ -238,8 +259,10 @@ class EcoModeApi {
}

Future<int> getFreeMemory() async {
final String __pigeon_channelName = 'dev.flutter.pigeon.flutter_eco_mode.EcoModeApi.getFreeMemory$__pigeon_messageChannelSuffix';
final BasicMessageChannel<Object?> __pigeon_channel = BasicMessageChannel<Object?>(
final String __pigeon_channelName =
'dev.flutter.pigeon.flutter_eco_mode.EcoModeApi.getFreeMemory$__pigeon_messageChannelSuffix';
final BasicMessageChannel<Object?> __pigeon_channel =
BasicMessageChannel<Object?>(
__pigeon_channelName,
pigeonChannelCodec,
binaryMessenger: __pigeon_binaryMessenger,
Expand All @@ -265,8 +288,10 @@ class EcoModeApi {
}

Future<int> getTotalStorage() async {
final String __pigeon_channelName = 'dev.flutter.pigeon.flutter_eco_mode.EcoModeApi.getTotalStorage$__pigeon_messageChannelSuffix';
final BasicMessageChannel<Object?> __pigeon_channel = BasicMessageChannel<Object?>(
final String __pigeon_channelName =
'dev.flutter.pigeon.flutter_eco_mode.EcoModeApi.getTotalStorage$__pigeon_messageChannelSuffix';
final BasicMessageChannel<Object?> __pigeon_channel =
BasicMessageChannel<Object?>(
__pigeon_channelName,
pigeonChannelCodec,
binaryMessenger: __pigeon_binaryMessenger,
Expand All @@ -292,8 +317,10 @@ class EcoModeApi {
}

Future<int> getFreeStorage() async {
final String __pigeon_channelName = 'dev.flutter.pigeon.flutter_eco_mode.EcoModeApi.getFreeStorage$__pigeon_messageChannelSuffix';
final BasicMessageChannel<Object?> __pigeon_channel = BasicMessageChannel<Object?>(
final String __pigeon_channelName =
'dev.flutter.pigeon.flutter_eco_mode.EcoModeApi.getFreeStorage$__pigeon_messageChannelSuffix';
final BasicMessageChannel<Object?> __pigeon_channel =
BasicMessageChannel<Object?>(
__pigeon_channelName,
pigeonChannelCodec,
binaryMessenger: __pigeon_binaryMessenger,
Expand All @@ -319,8 +346,10 @@ class EcoModeApi {
}

Future<double?> getEcoScore() async {
final String __pigeon_channelName = 'dev.flutter.pigeon.flutter_eco_mode.EcoModeApi.getEcoScore$__pigeon_messageChannelSuffix';
final BasicMessageChannel<Object?> __pigeon_channel = BasicMessageChannel<Object?>(
final String __pigeon_channelName =
'dev.flutter.pigeon.flutter_eco_mode.EcoModeApi.getEcoScore$__pigeon_messageChannelSuffix';
final BasicMessageChannel<Object?> __pigeon_channel =
BasicMessageChannel<Object?>(
__pigeon_channelName,
pigeonChannelCodec,
binaryMessenger: __pigeon_binaryMessenger,
Expand Down
3 changes: 2 additions & 1 deletion pigeons/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import 'package:pigeon/pigeon.dart';
@ConfigurePigeon(PigeonOptions(
dartOut: 'lib/messages.g.dart',
dartOptions: DartOptions(),
kotlinOut: 'android/src/main/kotlin/sncf/connect/tech/flutter_eco_mode/Messages.g.kt',
kotlinOut:
'android/src/main/kotlin/sncf/connect/tech/flutter_eco_mode/Messages.g.kt',
kotlinOptions: KotlinOptions(package: 'sncf.connect.tech.flutter_eco_mode'),
swiftOut: 'ios/Classes/Messages.g.swift',
swiftOptions: SwiftOptions(),
Expand Down
5 changes: 5 additions & 0 deletions run_pigeon.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dart run pigeon \
--input pigeons/messages.dart \
--dart_out lib/messages.dart \
--kotlin_out android/src/main/kotlin/sncf/connect/tech/flutter_eco_mode/Messages.kt \
--kotlin_package "sncf.connect.tech.flutter_eco_mode"
Loading
Loading