Skip to content

Commit

Permalink
Expose battery info into tooltip (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
Foxushka authored Oct 10, 2023
1 parent dec5e80 commit 6400565
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
38 changes: 22 additions & 16 deletions chameleonultragui/lib/gui/page/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class HomePageState extends State<HomePage> {
super.initState();
}

Future<(Icon, String, List<String>, bool)> getFutureData() async {
Future<((Icon, int, int), String, List<String>, bool)> getFutureData() async {
var appState = context.read<ChameleonGUIState>();
List<(TagType, TagType)> usedSlots = [];
try {
Expand All @@ -39,42 +39,44 @@ class HomePageState extends State<HomePage> {
}

return (
await getBatteryChargeIcon(),
await getBatteryInfo(),
await getUsedSlotsOut8(usedSlots),
await getVersion(),
await isReaderDeviceMode()
);
}

Future<Icon> getBatteryChargeIcon() async {
Future<(Icon, int, int)> getBatteryInfo() async {
var appState = context.read<ChameleonGUIState>();
var icon = const Icon(Icons.battery_unknown);
int charge = 0;
int voltage = 0;

try {
(_, charge) = await appState.communicator!.getBatteryCharge();
(voltage, charge) = await appState.communicator!.getBatteryCharge();
} catch (_) {}

if (charge > 98) {
return const Icon(Icons.battery_full);
icon = const Icon(Icons.battery_full);
} else if (charge > 87) {
return const Icon(Icons.battery_6_bar);
icon = const Icon(Icons.battery_6_bar);
} else if (charge > 75) {
return const Icon(Icons.battery_5_bar);
icon = const Icon(Icons.battery_5_bar);
} else if (charge > 62) {
return const Icon(Icons.battery_4_bar);
icon = const Icon(Icons.battery_4_bar);
} else if (charge > 50) {
return const Icon(Icons.battery_3_bar);
icon = const Icon(Icons.battery_3_bar);
} else if (charge > 37) {
return const Icon(Icons.battery_2_bar);
icon = const Icon(Icons.battery_2_bar);
} else if (charge > 10) {
return const Icon(Icons.battery_1_bar);
icon = const Icon(Icons.battery_1_bar);
} else if (charge > 3) {
return const Icon(Icons.battery_0_bar);
icon = const Icon(Icons.battery_0_bar);
} else if (charge > 0) {
return const Icon(Icons.battery_alert);
icon = const Icon(Icons.battery_alert);
}

return const Icon(Icons.battery_unknown);
return (icon, charge, voltage);
}

Future<String> getUsedSlotsOut8(List<(TagType, TagType)> usedSlots) async {
Expand Down Expand Up @@ -192,7 +194,7 @@ class HomePageState extends State<HomePage> {
return Text('${localizations.error}: ${snapshot.error.toString()}');
} else {
final (
batteryIcon,
batteryInfo,
usedSlots,
fwVersion,
isReaderDeviceMode,
Expand Down Expand Up @@ -235,7 +237,11 @@ class HomePageState extends State<HomePage> {
ConnectionType.ble
? Icons.bluetooth
: Icons.usb),
batteryIcon,
Tooltip(
message: localizations.battery_info(
batteryInfo.$2, batteryInfo.$3),
child: batteryInfo.$1,
),
],
),
],
Expand Down
3 changes: 2 additions & 1 deletion chameleonultragui/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,6 @@
"read_gen1_card_data": "Read Gen1 card data",
"card_tech": "Tech",
"charge": "Charge",
"copy_all_keys": "Copy all keys to clipboard"
"copy_all_keys": "Copy all keys to clipboard",
"battery_info": "Charge: {percent}%\nVoltage: {voltage} mV"
}

0 comments on commit 6400565

Please sign in to comment.