From a8268fa8366b8ed84ce14839277e8514c72efc29 Mon Sep 17 00:00:00 2001 From: Foxushka <135865149+Foxushka@users.noreply.github.com> Date: Fri, 1 Sep 2023 19:35:41 +0300 Subject: [PATCH] Wakelock (#189) * Wakelock * Some renaming * Some renaming * And there too --- .../lib/gui/component/slot_changer.dart | 6 +- chameleonultragui/lib/gui/menu/card_edit.dart | 23 +++--- .../lib/gui/menu/chameleon_settings.dart | 42 ++++++----- .../lib/gui/menu/dictionary_edit.dart | 3 +- .../lib/gui/menu/slot_settings.dart | 28 +++++--- chameleonultragui/lib/gui/page/connect.dart | 2 +- chameleonultragui/lib/gui/page/debug.dart | 3 +- chameleonultragui/lib/gui/page/flashing.dart | 2 +- chameleonultragui/lib/gui/page/home.dart | 10 +-- chameleonultragui/lib/gui/page/mfkey32.dart | 7 +- .../lib/gui/page/pending_connection.dart | 2 +- chameleonultragui/lib/gui/page/read_card.dart | 70 +++++++++---------- .../lib/gui/page/saved_cards.dart | 5 +- chameleonultragui/lib/gui/page/settings.dart | 2 +- .../lib/gui/page/slot_manager.dart | 56 ++------------- chameleonultragui/lib/helpers/flash.dart | 6 +- chameleonultragui/lib/main.dart | 33 ++++----- .../Flutter/GeneratedPluginRegistrant.swift | 2 + chameleonultragui/pubspec.lock | 24 +++++++ chameleonultragui/pubspec.yaml | 1 + chameleonultragui/untranslated_messages.json | 28 +------- 21 files changed, 163 insertions(+), 192 deletions(-) diff --git a/chameleonultragui/lib/gui/component/slot_changer.dart b/chameleonultragui/lib/gui/component/slot_changer.dart index e1972abb..2cbdbab2 100644 --- a/chameleonultragui/lib/gui/component/slot_changer.dart +++ b/chameleonultragui/lib/gui/component/slot_changer.dart @@ -22,7 +22,7 @@ class SlotChangerState extends State { } Future> getFutureData() async { - var appState = context.read(); + var appState = context.read(); List<(TagType, TagType)> usedSlots; try { @@ -35,7 +35,7 @@ class SlotChangerState extends State { } Future> getSlotIcons(List<(TagType, TagType)> usedSlots) async { - var appState = context.read(); + var appState = context.read(); List icons = []; try { @@ -77,7 +77,7 @@ class SlotChangerState extends State { @override Widget build(BuildContext context) { - var appState = context.read(); + var appState = context.read(); var localizations = AppLocalizations.of(context)!; return FutureBuilder( future: getFutureData(), diff --git a/chameleonultragui/lib/gui/menu/card_edit.dart b/chameleonultragui/lib/gui/menu/card_edit.dart index 465bda94..6e80b449 100644 --- a/chameleonultragui/lib/gui/menu/card_edit.dart +++ b/chameleonultragui/lib/gui/menu/card_edit.dart @@ -50,7 +50,7 @@ class CardEditMenuState extends State { @override Widget build(BuildContext context) { - var appState = context.watch(); + var appState = context.watch(); var localizations = AppLocalizations.of(context)!; return AlertDialog( title: Text(localizations.edit_card), @@ -78,8 +78,7 @@ class CardEditMenuState extends State { context: context, builder: (BuildContext context) { return AlertDialog( - title: Text(localizations - .pick_color), + title: Text(localizations.pick_color), content: SingleChildScrollView( child: ColorPicker( pickerColor: pickerColor, @@ -98,19 +97,16 @@ class CardEditMenuState extends State { pickerColor = Colors.deepOrange); Navigator.pop(context); }, - child: Text(localizations - .reset_default), + child: Text(localizations.reset_default), ), TextButton( onPressed: () { Navigator.pop(context); }, - child: Text(localizations - .cancel), + child: Text(localizations.cancel), ), TextButton( - child: Text(localizations - .ok), + child: Text(localizations.ok), onPressed: () { setState(() => currentColor = pickerColor); Navigator.pop(context); @@ -154,7 +150,8 @@ class CardEditMenuState extends State { TextFormField( controller: uidController, decoration: InputDecoration( - labelText: localizations.uid, hintText: localizations.enter_something("UID")), + labelText: localizations.uid, + hintText: localizations.enter_something("UID")), validator: (value) { if (value == null || value.isEmpty) { return localizations.please_enter_something("UID"); @@ -180,7 +177,8 @@ class CardEditMenuState extends State { child: TextFormField( controller: sak4Controller, decoration: InputDecoration( - labelText: localizations.sak, hintText: localizations.enter_something("SAK")), + labelText: localizations.sak, + hintText: localizations.enter_something("SAK")), validator: (value) { if (value == null || value.isEmpty && @@ -204,7 +202,8 @@ class CardEditMenuState extends State { child: TextFormField( controller: atqa4Controller, decoration: InputDecoration( - labelText: localizations.atqa, hintText: localizations.enter_something("ATQA")), + labelText: localizations.atqa, + hintText: localizations.enter_something("ATQA")), validator: (value) { if (value == null || value.isEmpty && diff --git a/chameleonultragui/lib/gui/menu/chameleon_settings.dart b/chameleonultragui/lib/gui/menu/chameleon_settings.dart index 5c4f1e59..c47cd64b 100644 --- a/chameleonultragui/lib/gui/menu/chameleon_settings.dart +++ b/chameleonultragui/lib/gui/menu/chameleon_settings.dart @@ -25,7 +25,7 @@ class ChameleonSettingsState extends State { } Future getAnimationMode() async { - var appState = context.read(); + var appState = context.read(); try { return await appState.communicator!.getAnimationMode(); @@ -35,7 +35,7 @@ class ChameleonSettingsState extends State { } Future getButtonConfig(ButtonType type) async { - var appState = context.read(); + var appState = context.read(); try { return await appState.communicator!.getButtonConfig(type); } catch (_) { @@ -44,7 +44,7 @@ class ChameleonSettingsState extends State { } Future getLongButtonConfig(ButtonType type) async { - var appState = context.read(); + var appState = context.read(); try { return await appState.communicator!.getLongButtonConfig(type); } catch (_) { @@ -72,7 +72,7 @@ class ChameleonSettingsState extends State { // ignore_for_file: use_build_context_synchronously @override Widget build(BuildContext context) { - var appState = context.watch(); + var appState = context.watch(); var localizations = AppLocalizations.of(context)!; return FutureBuilder( future: getSettingsData(), @@ -85,7 +85,8 @@ class ChameleonSettingsState extends State { appState.connector.performDisconnect(); return AlertDialog( title: Text(localizations.device_settings), - content: Text('${localizations.error}: ${snapshot.error.toString()}')); + content: Text( + '${localizations.error}: ${snapshot.error.toString()}')); } else { var ( animationMode, @@ -136,7 +137,8 @@ class ChameleonSettingsState extends State { } catch (e) { ScaffoldMessenger.of(context).hideCurrentSnackBar(); snackBar = SnackBar( - content: Text('${localizations.update_error}: ${e.toString()}'), + content: Text( + '${localizations.update_error}: ${e.toString()}'), action: SnackBarAction( label: localizations.close, onPressed: () {}, @@ -168,7 +170,11 @@ class ChameleonSettingsState extends State { Text("${localizations.animations}:"), const SizedBox(height: 10), ToggleButtonsWrapper( - items: [localizations.full, localizations.mini, localizations.none], + items: [ + localizations.full, + localizations.mini, + localizations.none + ], selectedValue: animationMode.value, onChange: (int index) async { var animation = AnimationSetting.full; @@ -187,7 +193,8 @@ class ChameleonSettingsState extends State { const SizedBox(height: 10), Text("${localizations.button_config}:"), const SizedBox(height: 7), - Text("${localizations.button_x("A")}:", textScaleFactor: 0.8), + Text("${localizations.button_x("A")}:", + textScaleFactor: 0.8), const SizedBox(height: 7), ToggleButtonsWrapper( items: [ @@ -214,7 +221,8 @@ class ChameleonSettingsState extends State { appState.changesMade(); }), const SizedBox(height: 7), - Text("${localizations.button_x("B")}:", textScaleFactor: 0.8), + Text("${localizations.button_x("B")}:", + textScaleFactor: 0.8), const SizedBox(height: 7), ToggleButtonsWrapper( items: [ @@ -243,7 +251,8 @@ class ChameleonSettingsState extends State { const SizedBox(height: 7), Text(localizations.long_press, textScaleFactor: 0.9), const SizedBox(height: 7), - Text("${localizations.button_x("A")}:", textScaleFactor: 0.8), + Text("${localizations.button_x("A")}:", + textScaleFactor: 0.8), const SizedBox(height: 7), ToggleButtonsWrapper( items: [ @@ -270,7 +279,8 @@ class ChameleonSettingsState extends State { appState.changesMade(); }), const SizedBox(height: 7), - Text("${localizations.button_x("B")}:", textScaleFactor: 0.8), + Text("${localizations.button_x("B")}:", + textScaleFactor: 0.8), const SizedBox(height: 7), ToggleButtonsWrapper( items: [ @@ -319,22 +329,22 @@ class ChameleonSettingsState extends State { context: context, builder: (BuildContext context) => AlertDialog( title: Text(localizations.factory_reset), - content: Text( - localizations.factory_sure), + content: Text(localizations.factory_sure), actions: [ TextButton( onPressed: () async { await appState.communicator!.factoryReset(); await appState.connector .performDisconnect(); - Navigator.pop(context, localizations.cancel); + Navigator.pop( + context, localizations.cancel); appState.changesMade(); }, child: Text(localizations.yes), ), TextButton( - onPressed: () => - Navigator.pop(context, localizations.cancel), + onPressed: () => Navigator.pop( + context, localizations.cancel), child: Text(localizations.no), ), ], diff --git a/chameleonultragui/lib/gui/menu/dictionary_edit.dart b/chameleonultragui/lib/gui/menu/dictionary_edit.dart index 6309c78e..cb9cb1ee 100644 --- a/chameleonultragui/lib/gui/menu/dictionary_edit.dart +++ b/chameleonultragui/lib/gui/menu/dictionary_edit.dart @@ -10,7 +10,6 @@ import 'package:chameleonultragui/helpers/general.dart'; // Localizations import 'package:flutter_gen/gen_l10n/app_localizations.dart'; - class DictionaryEditMenu extends StatefulWidget { final Dictionary dict; @@ -65,7 +64,7 @@ class DictionaryEditMenuState extends State { @override Widget build(BuildContext context) { - var appState = context.watch(); + var appState = context.watch(); var localizations = AppLocalizations.of(context)!; return AlertDialog( title: Text(localizations.edit_dictionary), diff --git a/chameleonultragui/lib/gui/menu/slot_settings.dart b/chameleonultragui/lib/gui/menu/slot_settings.dart index 86eb2498..195e5ab9 100644 --- a/chameleonultragui/lib/gui/menu/slot_settings.dart +++ b/chameleonultragui/lib/gui/menu/slot_settings.dart @@ -35,7 +35,7 @@ class SlotSettingsState extends State { } Future fetchInfo() async { - var appState = context.read(); + var appState = context.read(); var localizations = AppLocalizations.of(context)!; if (hfName.isEmpty) { try { @@ -86,7 +86,7 @@ class SlotSettingsState extends State { @override Widget build(BuildContext context) { - var appState = context.watch(); + var appState = context.watch(); var localizations = AppLocalizations.of(context)!; return FutureBuilder( @@ -101,7 +101,8 @@ class SlotSettingsState extends State { appState.connector.performDisconnect(); return AlertDialog( title: Text(localizations.slot_settings), - content: Text('${localizations.error}: ${snapshot.error.toString()}')); + content: Text( + '${localizations.error}: ${snapshot.error.toString()}')); } else { return AlertDialog( title: Text(localizations.slot_settings), @@ -122,7 +123,9 @@ class SlotSettingsState extends State { await appState.communicator! .deleteSlotInfo(widget.slot, TagFrequency.hf); await appState.communicator!.setSlotTagName( - widget.slot, localizations.empty, TagFrequency.hf); + widget.slot, + localizations.empty, + TagFrequency.hf); await appState.communicator!.saveSlotData(); setState(() { @@ -151,7 +154,9 @@ class SlotSettingsState extends State { await appState.communicator! .deleteSlotInfo(widget.slot, TagFrequency.lf); await appState.communicator!.setSlotTagName( - widget.slot, localizations.empty, TagFrequency.lf); + widget.slot, + localizations.empty, + TagFrequency.lf); await appState.communicator!.saveSlotData(); setState(() { @@ -238,8 +243,7 @@ class SlotSettingsState extends State { ...(detectionCount == 0) ? [ const SizedBox(height: 8), - Text( - localizations.present_cham_reader_keys, + Text(localizations.present_cham_reader_keys, textScaleFactor: 0.8) ] : [ @@ -257,7 +261,8 @@ class SlotSettingsState extends State { child: Row( children: [ const Icon(Icons.lock_open), - Text(localizations.recover_keys), + Text( + localizations.recover_keys), ], )), ]), @@ -272,7 +277,12 @@ class SlotSettingsState extends State { Text(localizations.write_mode), const SizedBox(height: 8), ToggleButtonsWrapper( - items: [localizations.normal, localizations.decline, localizations.deceive, localizations.shadow], + items: [ + localizations.normal, + localizations.decline, + localizations.deceive, + localizations.shadow + ], selectedValue: writeMode.value, onChange: (int index) async { await appState.communicator!.activateSlot(widget.slot); diff --git a/chameleonultragui/lib/gui/page/connect.dart b/chameleonultragui/lib/gui/page/connect.dart index 6a4c61e1..9217a7f5 100644 --- a/chameleonultragui/lib/gui/page/connect.dart +++ b/chameleonultragui/lib/gui/page/connect.dart @@ -14,7 +14,7 @@ class ConnectPage extends StatelessWidget { @override Widget build(BuildContext context) { - var appState = context.watch(); // Get State + var appState = context.watch(); // Get State var localizations = AppLocalizations.of(context)!; return FutureBuilder( future: diff --git a/chameleonultragui/lib/gui/page/debug.dart b/chameleonultragui/lib/gui/page/debug.dart index 6a2777e2..b7e43a0c 100644 --- a/chameleonultragui/lib/gui/page/debug.dart +++ b/chameleonultragui/lib/gui/page/debug.dart @@ -20,7 +20,7 @@ class DebugPage extends StatelessWidget { @override Widget build(BuildContext context) { - var appState = context.watch(); // Get State + var appState = context.watch(); // Get State var localizations = AppLocalizations.of(context)!; return Center( child: Column( @@ -47,7 +47,6 @@ class DebugPage extends StatelessWidget { ), Text('⚠️ ${localizations.warned} ⚠️', textScaleFactor: 3), Text('${localizations.platform}: ${Platform.operatingSystem}'), - Text('${localizations.android}: ${appState.onAndroid}'), Text('${localizations.serial_protocol}: ${appState.connector}'), Text( '${localizations.chameleon_connected}: ${appState.connector.connected}'), diff --git a/chameleonultragui/lib/gui/page/flashing.dart b/chameleonultragui/lib/gui/page/flashing.dart index 8033334e..863c8a23 100644 --- a/chameleonultragui/lib/gui/page/flashing.dart +++ b/chameleonultragui/lib/gui/page/flashing.dart @@ -11,7 +11,7 @@ class FlashingPage extends StatelessWidget { @override Widget build(BuildContext context) { - var appState = context.watch(); + var appState = context.watch(); var localizations = AppLocalizations.of(context)!; return Scaffold( appBar: AppBar( diff --git a/chameleonultragui/lib/gui/page/home.dart b/chameleonultragui/lib/gui/page/home.dart index 62a2229b..e2f3c363 100644 --- a/chameleonultragui/lib/gui/page/home.dart +++ b/chameleonultragui/lib/gui/page/home.dart @@ -27,7 +27,7 @@ class HomePageState extends State { } Future<(Icon, String, List, bool)> getFutureData() async { - var appState = context.read(); + var appState = context.read(); List<(TagType, TagType)> usedSlots = []; try { usedSlots = await appState.communicator!.getUsedSlots(); @@ -44,7 +44,7 @@ class HomePageState extends State { } Future getBatteryChargeIcon() async { - var appState = context.read(); + var appState = context.read(); int charge = 0; try { @@ -91,7 +91,7 @@ class HomePageState extends State { } Future> getVersion() async { - var appState = context.read(); + var appState = context.read(); String commitHash = ""; String firmwareVersion = numToVerCode(await appState.communicator!.getFirmwareVersion()); @@ -112,13 +112,13 @@ class HomePageState extends State { } Future isReaderDeviceMode() async { - var appState = context.read(); + var appState = context.read(); return await appState.communicator!.isReaderDeviceMode(); } @override Widget build(BuildContext context) { - var appState = context.read(); + var appState = context.read(); var localizations = AppLocalizations.of(context)!; return FutureBuilder( future: getFutureData(), diff --git a/chameleonultragui/lib/gui/page/mfkey32.dart b/chameleonultragui/lib/gui/page/mfkey32.dart index 2082d3af..f2fd6881 100644 --- a/chameleonultragui/lib/gui/page/mfkey32.dart +++ b/chameleonultragui/lib/gui/page/mfkey32.dart @@ -28,7 +28,7 @@ class Mfkey32PageState extends State { } Future<(bool, int)> getMf1DetectionStatus() async { - var appState = context.read(); + var appState = context.read(); return ( await appState.communicator!.isMf1DetectionMode(), @@ -46,7 +46,7 @@ class Mfkey32PageState extends State { } Future handleMfkeyCalculation() async { - var appState = context.read(); + var appState = context.read(); var detections = await appState.communicator!.getMf1DetectionResult(0); for (var item in detections.entries) { @@ -131,7 +131,8 @@ class Mfkey32PageState extends State { await handleMfkeyCalculation(); } : null, - child: Text(localizations.recover_keys_nonce(detectionCount)), + child: Text( + localizations.recover_keys_nonce(detectionCount)), ), const SizedBox(height: 16.0), Expanded( diff --git a/chameleonultragui/lib/gui/page/pending_connection.dart b/chameleonultragui/lib/gui/page/pending_connection.dart index e9f4dac9..b764235c 100644 --- a/chameleonultragui/lib/gui/page/pending_connection.dart +++ b/chameleonultragui/lib/gui/page/pending_connection.dart @@ -10,7 +10,7 @@ class PendingConnectionPage extends StatelessWidget { @override Widget build(BuildContext context) { - var appState = context.watch(); + var appState = context.watch(); var localizations = AppLocalizations.of(context)!; return Scaffold( diff --git a/chameleonultragui/lib/gui/page/read_card.dart b/chameleonultragui/lib/gui/page/read_card.dart index 1d98d89a..25c3b34f 100644 --- a/chameleonultragui/lib/gui/page/read_card.dart +++ b/chameleonultragui/lib/gui/page/read_card.dart @@ -96,7 +96,7 @@ class ReadCardPage extends StatefulWidget { class ReadCardPageState extends State { ChameleonReadTagStatus status = ChameleonReadTagStatus(); - Future readHFInfo(MyAppState appState) async { + Future readHFInfo(ChameleonGUIState appState) async { status.validKeys = List.generate(80, (_) => Uint8List(0)); status.checkMarks = List.generate(80, (_) => ChameleonKeyCheckmark.none); @@ -151,7 +151,7 @@ class ReadCardPageState extends State { } } - Future readLFInfo(MyAppState appState) async { + Future readLFInfo(ChameleonGUIState appState) async { try { if (!await appState.communicator!.isReaderDeviceMode()) { await appState.communicator!.setReaderDeviceMode(true); @@ -180,7 +180,7 @@ class ReadCardPageState extends State { } } - Future recoverKeys(MyAppState appState) async { + Future recoverKeys(ChameleonGUIState appState) async { setState(() { status.state = ChameleonMifareClassicState.recoveryOngoing; }); @@ -263,8 +263,7 @@ class ReadCardPageState extends State { if (prng != NTLevel.weak) { // No hardnested/staticnested implementation yet setState(() { - status.recoveryError = - localizations.recovery_error_no_supported; + status.recoveryError = localizations.recovery_error_no_supported; status.state = ChameleonMifareClassicState.recovery; }); return; @@ -358,7 +357,7 @@ class ReadCardPageState extends State { } catch (_) {} } - Future checkKeys(MyAppState appState) async { + Future checkKeys(ChameleonGUIState appState) async { setState(() { status.state = ChameleonMifareClassicState.checkKeysOngoing; }); @@ -453,14 +452,13 @@ class ReadCardPageState extends State { } } catch (_) { setState(() { - status.recoveryError = localizations - .recovery_error_dict; + status.recoveryError = localizations.recovery_error_dict; status.state = ChameleonMifareClassicState.checkKeys; }); } } - Future dumpData(MyAppState appState) async { + Future dumpData(ChameleonGUIState appState) async { setState(() { status.state = ChameleonMifareClassicState.dumpOngoing; }); @@ -545,7 +543,7 @@ class ReadCardPageState extends State { } } - Future saveHFCard(MyAppState appState, + Future saveHFCard(ChameleonGUIState appState, {bool bin = false, bool skipDump = false}) async { List cardDump = []; var localizations = AppLocalizations.of(context)!; @@ -596,7 +594,7 @@ class ReadCardPageState extends State { } } - Future saveLFCard(MyAppState appState) async { + Future saveLFCard(ChameleonGUIState appState) async { var tags = appState.sharedPreferencesProvider.getCards(); tags.add(CardSave( id: const Uuid().v4(), @@ -646,9 +644,10 @@ class ReadCardPageState extends State { double fieldFontSize = isSmallScreen ? 16 : 20; double checkmarkSize = isSmallScreen ? 16 : 20; - var appState = context.watch(); + var appState = context.watch(); status.dictionaries = appState.sharedPreferencesProvider.getDictionaries(); - status.dictionaries.insert(0, Dictionary(id: "", name: localizations.empty, keys: [])); + status.dictionaries + .insert(0, Dictionary(id: "", name: localizations.empty, keys: [])); status.selectedDictionary ??= status.dictionaries[0]; return Scaffold( @@ -675,9 +674,12 @@ class ReadCardPageState extends State { ), ), const SizedBox(height: 8), - buildFieldRow(localizations.uid, status.hfUid, fieldFontSize), - buildFieldRow(localizations.sak, status.sak, fieldFontSize), - buildFieldRow(localizations.atqa, status.atqa, fieldFontSize), + buildFieldRow( + localizations.uid, status.hfUid, fieldFontSize), + buildFieldRow( + localizations.sak, status.sak, fieldFontSize), + buildFieldRow( + localizations.atqa, status.atqa, fieldFontSize), // buildFieldRow('ATS', status.ats, fieldFontSize), const SizedBox(height: 16), Text( @@ -687,9 +689,7 @@ class ReadCardPageState extends State { ), const SizedBox(height: 16), if (status.noHfCard) ...[ - ErrorMessage( - errorMessage: - localizations.no_card_found), + ErrorMessage(errorMessage: localizations.no_card_found), const SizedBox(height: 16) ], ElevatedButton( @@ -703,14 +703,13 @@ class ReadCardPageState extends State { context: context, builder: (BuildContext context) => AlertDialog( title: Text(localizations.no_supported), - content: Text( - localizations.lite_no_read, - style: - const TextStyle(fontWeight: FontWeight.bold)), + content: Text(localizations.lite_no_read, + style: const TextStyle( + fontWeight: FontWeight.bold)), actions: [ TextButton( - onPressed: () => - Navigator.pop(context, localizations.ok), + onPressed: () => Navigator.pop( + context, localizations.ok), child: Text(localizations.ok), ), ], @@ -860,8 +859,7 @@ class ReadCardPageState extends State { const SizedBox(height: 8), Row( children: [ - Text( - localizations.letter_space("A")), + Text(localizations.letter_space("A")), ...List.generate( 16, (index) => Padding( @@ -1134,7 +1132,8 @@ class ReadCardPageState extends State { ), ), const SizedBox(height: 8), - buildFieldRow(localizations.uid, status.lfUid, fieldFontSize), + buildFieldRow( + localizations.uid, status.lfUid, fieldFontSize), const SizedBox(height: 16), Text( 'Tech: ${status.lfTech}', @@ -1143,9 +1142,7 @@ class ReadCardPageState extends State { ), const SizedBox(height: 16), if (status.noLfCard) ...[ - ErrorMessage( - errorMessage: - localizations.no_card_found), + ErrorMessage(errorMessage: localizations.no_card_found), const SizedBox(height: 16) ], ElevatedButton( @@ -1159,14 +1156,13 @@ class ReadCardPageState extends State { context: context, builder: (BuildContext context) => AlertDialog( title: Text(localizations.no_supported), - content: Text( - localizations.lite_no_read, - style: - const TextStyle(fontWeight: FontWeight.bold)), + content: Text(localizations.lite_no_read, + style: const TextStyle( + fontWeight: FontWeight.bold)), actions: [ TextButton( - onPressed: () => - Navigator.pop(context, localizations.ok), + onPressed: () => Navigator.pop( + context, localizations.ok), child: Text(localizations.ok), ), ], diff --git a/chameleonultragui/lib/gui/page/saved_cards.dart b/chameleonultragui/lib/gui/page/saved_cards.dart index 891cb0fb..85267d3d 100644 --- a/chameleonultragui/lib/gui/page/saved_cards.dart +++ b/chameleonultragui/lib/gui/page/saved_cards.dart @@ -28,7 +28,8 @@ class SavedCardsPage extends StatefulWidget { class SavedCardsPageState extends State { MifareClassicType selectedType = MifareClassicType.m1k; - Future saveTag(CardSave tag, MyAppState appState, bool bin) async { + Future saveTag( + CardSave tag, ChameleonGUIState appState, bool bin) async { var localizations = AppLocalizations.of(context)!; if (bin) { List tagDump = []; @@ -76,7 +77,7 @@ class SavedCardsPageState extends State { // ignore_for_file: use_build_context_synchronously @override Widget build(BuildContext context) { - var appState = context.watch(); + var appState = context.watch(); var dictionaries = appState.sharedPreferencesProvider.getDictionaries(); var tags = appState.sharedPreferencesProvider.getCards(); var localizations = AppLocalizations.of(context)!; diff --git a/chameleonultragui/lib/gui/page/settings.dart b/chameleonultragui/lib/gui/page/settings.dart index f70490f8..317be869 100644 --- a/chameleonultragui/lib/gui/page/settings.dart +++ b/chameleonultragui/lib/gui/page/settings.dart @@ -48,7 +48,7 @@ class SettingsMainPageState extends State { @override Widget build(BuildContext context) { - var appState = context.watch(); // Get State + var appState = context.watch(); // Get State var localizations = AppLocalizations.of(context)!; return Scaffold( appBar: AppBar( diff --git a/chameleonultragui/lib/gui/page/slot_manager.dart b/chameleonultragui/lib/gui/page/slot_manager.dart index f2ec184f..7eb6534f 100644 --- a/chameleonultragui/lib/gui/page/slot_manager.dart +++ b/chameleonultragui/lib/gui/page/slot_manager.dart @@ -13,52 +13,6 @@ import 'package:provider/provider.dart'; // Localizations import 'package:flutter_gen/gen_l10n/app_localizations.dart'; -class Tile extends StatelessWidget { - const Tile({ - Key? key, - required this.index, - this.extent, - this.backgroundColor, - this.bottomSpace, - }) : super(key: key); - - final int index; - final double? extent; - final double? bottomSpace; - final Color? backgroundColor; - - @override - Widget build(BuildContext context) { - final child = Container( - color: backgroundColor, - height: extent, - child: Center( - child: CircleAvatar( - minRadius: 20, - maxRadius: 20, - backgroundColor: Colors.white, - foregroundColor: Colors.black, - child: Text('$index', style: const TextStyle(fontSize: 20)), - ), - ), - ); - - if (bottomSpace == null) { - return child; - } - - return Column( - children: [ - Expanded(child: child), - Container( - height: bottomSpace, - color: Colors.green, - ) - ], - ); - } -} - class SlotManagerPage extends StatefulWidget { const SlotManagerPage({super.key}); @@ -90,7 +44,7 @@ class SlotManagerPageState extends State { bool onlyOneSlot = false; Future executeNextFunction() async { - var appState = context.read(); + var appState = context.read(); var localizations = AppLocalizations.of(context)!; if (currentFunctionIndex == 0 || onlyOneSlot) { try { @@ -157,7 +111,7 @@ class SlotManagerPageState extends State { currentFunctionIndex = slot; onlyOneSlot = true; }); - var appState = context.read(); + var appState = context.read(); appState.changesMade(); } @@ -165,7 +119,7 @@ class SlotManagerPageState extends State { setState(() { progress = progressBar; }); - var appState = context.read(); + var appState = context.read(); appState.changesMade(); } @@ -282,7 +236,7 @@ class SlotManagerPageState extends State { } Future cardSelectDialog(BuildContext context, int gridPosition) { - var appState = context.read(); + var appState = context.read(); var tags = appState.sharedPreferencesProvider.getCards(); // Don't allow user to upload more tags while already uploading dump @@ -414,7 +368,7 @@ class CardSearchDelegate extends SearchDelegate { (filter == SearchFilter.lf && chameleonTagToFrequency(card.tag) == TagFrequency.lf)))); - var appState = context.read(); + var appState = context.read(); return ListView.builder( itemCount: results.length, diff --git a/chameleonultragui/lib/helpers/flash.dart b/chameleonultragui/lib/helpers/flash.dart index e420484c..41031653 100644 --- a/chameleonultragui/lib/helpers/flash.dart +++ b/chameleonultragui/lib/helpers/flash.dart @@ -192,7 +192,7 @@ void validateFiles(Uint8List dat, Uint8List bin) { } } -Future flashFirmware(MyAppState appState) async { +Future flashFirmware(ChameleonGUIState appState) async { Uint8List applicationDat, applicationBin; Uint8List content = await fetchFirmware(appState.connector.device); @@ -204,7 +204,7 @@ Future flashFirmware(MyAppState appState) async { firmwareZip: content); } -Future flashFirmwareZip(MyAppState appState) async { +Future flashFirmwareZip(ChameleonGUIState appState) async { Uint8List applicationDat, applicationBin; FilePickerResult? result = await FilePicker.platform.pickFiles(); @@ -223,7 +223,7 @@ Future flashFirmwareZip(MyAppState appState) async { Future flashFile( ChameleonCommunicator? connection, - MyAppState appState, + ChameleonGUIState appState, Uint8List applicationDat, Uint8List applicationBin, void Function(int progress) callback, diff --git a/chameleonultragui/lib/main.dart b/chameleonultragui/lib/main.dart index 04fb03e8..9c85062b 100644 --- a/chameleonultragui/lib/main.dart +++ b/chameleonultragui/lib/main.dart @@ -6,6 +6,7 @@ import 'package:chameleonultragui/connector/serial_ble.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:provider/provider.dart'; +import 'package:wakelock_plus/wakelock_plus.dart'; import 'connector/serial_native.dart'; @@ -35,13 +36,14 @@ Future main() async { WidgetsFlutterBinding.ensureInitialized(); final sharedPreferencesProvider = SharedPreferencesProvider(); await sharedPreferencesProvider.load(); - runApp(MyApp(sharedPreferencesProvider)); + runApp(ChameleonGUI(sharedPreferencesProvider)); } -class MyApp extends StatelessWidget { +class ChameleonGUI extends StatelessWidget { // Root Widget final SharedPreferencesProvider _sharedPreferencesProvider; - const MyApp(this._sharedPreferencesProvider, {Key? key}) : super(key: key); + const ChameleonGUI(this._sharedPreferencesProvider, {Key? key}) + : super(key: key); @override Widget build(BuildContext context) { @@ -49,7 +51,7 @@ class MyApp extends StatelessWidget { providers: [ ChangeNotifierProvider.value(value: _sharedPreferencesProvider), ChangeNotifierProvider( - create: (context) => MyAppState(_sharedPreferencesProvider), + create: (context) => ChameleonGUIState(_sharedPreferencesProvider), ), ], child: MaterialApp( @@ -71,7 +73,7 @@ class MyApp extends StatelessWidget { brightness: Brightness.dark, // Dark Theme ), themeMode: _sharedPreferencesProvider.getTheme(), // Dark Theme - home: const MyHomePage(), + home: const MainPage(), ), ); @@ -82,12 +84,9 @@ class MyApp extends StatelessWidget { } } -class MyAppState extends ChangeNotifier { +class ChameleonGUIState extends ChangeNotifier { final SharedPreferencesProvider sharedPreferencesProvider; - MyAppState(this.sharedPreferencesProvider); - - bool onAndroid = - Platform.isAndroid; // Are we on android? (mostly for serial port) + ChameleonGUIState(this.sharedPreferencesProvider); // Android uses AndroidSerial, iOS can only use BLESerial // The rest (desktops?) can use NativeSerial @@ -116,21 +115,21 @@ class MyAppState extends ChangeNotifier { } } -class MyHomePage extends StatefulWidget { +class MainPage extends StatefulWidget { // Main Page - const MyHomePage({super.key}); + const MainPage({super.key}); @override - State createState() => _MyHomePageState(); + State createState() => _MainPageState(); } -class _MyHomePageState extends State { +class _MainPageState extends State { // Main Page State, Sidebar visible, Navigation var selectedIndex = 0; @override Widget build(BuildContext context) { - var appState = context.watch(); // Get State + var appState = context.watch(); // Get State if (appState.sharedPreferencesProvider.getSideBarAutoExpansion()) { double width = MediaQuery.of(context).size.width; if (width >= 600) { @@ -200,6 +199,8 @@ class _MyHomePageState extends State { statusBarColor: Theme.of(context).colorScheme.surface, )); + WakelockPlus.toggle(enable: page is FlashingPage); + return LayoutBuilder(// Build Page builder: (context, constraints) { return Scaffold( @@ -280,7 +281,7 @@ class BottomProgressBar extends StatelessWidget { @override Widget build(BuildContext context) { - var appState = context.watch(); + var appState = context.watch(); return (appState.connector.connected && appState.connector.isDFU) ? LinearProgressIndicator( value: appState.progress, diff --git a/chameleonultragui/macos/Flutter/GeneratedPluginRegistrant.swift b/chameleonultragui/macos/Flutter/GeneratedPluginRegistrant.swift index bdd9f478..b4065a14 100644 --- a/chameleonultragui/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/chameleonultragui/macos/Flutter/GeneratedPluginRegistrant.swift @@ -12,6 +12,7 @@ import path_provider_foundation import shared_preferences_foundation import sqflite import url_launcher_macos +import wakelock_plus func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { FileSaverPlugin.register(with: registry.registrar(forPlugin: "FileSaverPlugin")) @@ -21,4 +22,5 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin")) UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) + WakelockPlusMacosPlugin.register(with: registry.registrar(forPlugin: "WakelockPlusMacosPlugin")) } diff --git a/chameleonultragui/pubspec.lock b/chameleonultragui/pubspec.lock index e8d6c3a3..0a5c49ec 100644 --- a/chameleonultragui/pubspec.lock +++ b/chameleonultragui/pubspec.lock @@ -89,6 +89,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.3" + dbus: + dependency: transitive + description: + name: dbus + sha256: "6f07cba3f7b3448d42d015bfd3d53fe12e5b36da2423f23838efc1d5fb31a263" + url: "https://pub.dev" + source: hosted + version: "0.7.8" dylib: dependency: "direct main" description: @@ -779,6 +787,22 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" + wakelock_plus: + dependency: "direct main" + description: + name: wakelock_plus + sha256: aac3f3258f01781ec9212df94eecef1eb9ba9350e106728def405baa096ba413 + url: "https://pub.dev" + source: hosted + version: "1.1.1" + wakelock_plus_platform_interface: + dependency: transitive + description: + name: wakelock_plus_platform_interface + sha256: "40fabed5da06caff0796dc638e1f07ee395fb18801fbff3255a2372db2d80385" + url: "https://pub.dev" + source: hosted + version: "1.1.0" web: dependency: transitive description: diff --git a/chameleonultragui/pubspec.yaml b/chameleonultragui/pubspec.yaml index 6e809733..14764d22 100644 --- a/chameleonultragui/pubspec.yaml +++ b/chameleonultragui/pubspec.yaml @@ -65,6 +65,7 @@ dependencies: flutter_localizations: sdk: flutter intl: any + wakelock_plus: ^1.1.1 # crowdin_sdk: ^0.3.1 dev_dependencies: diff --git a/chameleonultragui/untranslated_messages.json b/chameleonultragui/untranslated_messages.json index 212d8d5a..9e26dfee 100644 --- a/chameleonultragui/untranslated_messages.json +++ b/chameleonultragui/untranslated_messages.json @@ -1,27 +1 @@ -{ - "de": [ - "connecting_to_ble", - "default_ble_password", - "connection_might_take_some_time" - ], - - "de_AT": [ - "connecting_to_ble", - "default_ble_password", - "connection_might_take_some_time" - ], - - "es": [ - "connecting_to_ble", - "default_ble_password", - "connection_might_take_some_time" - ], - - "fr": [ - "unavailable", - "correct_tag_data", - "connecting_to_ble", - "default_ble_password", - "connection_might_take_some_time" - ] -} +{} \ No newline at end of file