Skip to content

Commit

Permalink
Global logging, M3 Darkmode, OTF Theme and Language Switching (#191)
Browse files Browse the repository at this point in the history
Global logger and move to M3 for darkmode
Also make theme switching work on the fly.
  • Loading branch information
Foxushka authored Sep 1, 2023
1 parent a8268fa commit 5812f3f
Show file tree
Hide file tree
Showing 33 changed files with 552 additions and 487 deletions.
7 changes: 3 additions & 4 deletions chameleonultragui/lib/bridge/chameleon.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:convert';
import 'dart:math';
import 'dart:typed_data';
import 'dart:async';
import 'package:chameleonultragui/helpers/general.dart';
Expand Down Expand Up @@ -253,10 +252,10 @@ class ChameleonCommunicator {
int dataStatus = 0;
int dataLength = 0;
List<ChameleonMessage> messageQueue = [];
Logger log = Logger();
Random random = Random();

ChameleonCommunicator({AbstractSerial? port}) {
final Logger log;

ChameleonCommunicator(this.log, {AbstractSerial? port}) {
if (port != null) {
open(port);
}
Expand Down
4 changes: 2 additions & 2 deletions chameleonultragui/lib/bridge/dfu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ class DFUCommunicator {
AbstractSerial? _serialInstance;
Completer<List<int>>? responseCompleter;

Logger log = Logger();
final Logger log;

DFUCommunicator({AbstractSerial? port, bool viaBLE = false}) {
DFUCommunicator(this.log, {AbstractSerial? port, bool viaBLE = false}) {
isBLE = viaBLE;
if (port != null) {
open(port);
Expand Down
4 changes: 3 additions & 1 deletion chameleonultragui/lib/connector/serial_abstract.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Chameleon {
}

class AbstractSerial {
Logger log = Logger();
late Logger log;
ChameleonDevice device = ChameleonDevice.none;
bool connected = false;
bool isOpen = false;
Expand All @@ -29,6 +29,8 @@ class AbstractSerial {
ConnectionType connectionType = ConnectionType.none;
dynamic messageCallback;

AbstractSerial({required this.log});

Future<bool> performConnect() async {
return false;
}
Expand Down
6 changes: 4 additions & 2 deletions chameleonultragui/lib/connector/serial_android.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import 'package:permission_handler/permission_handler.dart';

// Class combines Android OTG and BLE serial
class AndroidSerial extends AbstractSerial {
BLESerial bleSerial = BLESerial();
MobileSerial mobileSerial = MobileSerial();
late BLESerial bleSerial = BLESerial(log: log);
late MobileSerial mobileSerial = MobileSerial(log: log);

AndroidSerial({required super.log});

@override
Future<bool> performDisconnect() async {
Expand Down
2 changes: 2 additions & 0 deletions chameleonultragui/lib/connector/serial_ble.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class BLESerial extends AbstractSerial {
Map<String, Chameleon> chameleonMap = {};
bool inSearch = false;

BLESerial({required super.log});

@override
Future<List> availableDevices() async {
if (inSearch) {
Expand Down
2 changes: 2 additions & 0 deletions chameleonultragui/lib/connector/serial_mobile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class MobileSerial extends AbstractSerial {
Map<String, UsbDevice> deviceMap = {};
UsbPort? port;

MobileSerial({required super.log});

@override
Future<bool> performDisconnect() async {
device = ChameleonDevice.none;
Expand Down
2 changes: 2 additions & 0 deletions chameleonultragui/lib/connector/serial_native.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class NativeSerial extends AbstractSerial {
bool checkDFU = true;
SerialPortReader? reader;

NativeSerial({required super.log});

@override
Future<List> availableDevices() async {
return SerialPort.availablePorts;
Expand Down
2 changes: 1 addition & 1 deletion chameleonultragui/lib/gui/component/developer_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class DeveloperList extends StatelessWidget {
return IntrinsicHeight(
child: Center(
child: Wrap(
alignment: WrapAlignment.center, // Center the items in each line
alignment: WrapAlignment.center,
children: List.generate(avatars.length, (index) {
final avatar = avatars[index];
return GestureDetector(
Expand Down
2 changes: 1 addition & 1 deletion chameleonultragui/lib/gui/component/slot_changer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class SlotChangerState extends State<SlotChanger> {
],
);
} else if (snapshot.hasError) {
appState.connector.performDisconnect();
appState.connector!.performDisconnect();
return Text('${localizations.error}: ${snapshot.error.toString()}');
} else {
final slotIcons = snapshot.data;
Expand Down
8 changes: 4 additions & 4 deletions chameleonultragui/lib/gui/menu/chameleon_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class ChameleonSettingsState extends State<ChameleonSettings> {
title: Text(localizations.device_settings),
content: const Column(children: [CircularProgressIndicator()]));
} else if (snapshot.hasError) {
appState.connector.performDisconnect();
appState.connector!.performDisconnect();
return AlertDialog(
title: Text(localizations.device_settings),
content: Text(
Expand All @@ -106,7 +106,7 @@ class ChameleonSettingsState extends State<ChameleonSettings> {
TextButton(
onPressed: () async {
await appState.communicator!.enterDFUMode();
appState.connector.performDisconnect();
appState.connector!.performDisconnect();
Navigator.pop(context, localizations.cancel);
appState.changesMade();
},
Expand All @@ -121,7 +121,7 @@ class ChameleonSettingsState extends State<ChameleonSettings> {
Navigator.pop(context, localizations.cancel);
var snackBar = SnackBar(
content: Text(localizations.downloading_fw(
appState.connector.device ==
appState.connector!.device ==
ChameleonDevice.ultra
? "Ultra"
: "Lite")),
Expand Down Expand Up @@ -334,7 +334,7 @@ class ChameleonSettingsState extends State<ChameleonSettings> {
TextButton(
onPressed: () async {
await appState.communicator!.factoryReset();
await appState.connector
await appState.connector!
.performDisconnect();
Navigator.pop(
context, localizations.cancel);
Expand Down
4 changes: 2 additions & 2 deletions chameleonultragui/lib/gui/menu/slot_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class SlotSettingsState extends State<SlotSettings> {
content: const SingleChildScrollView(
child: Column(children: [CircularProgressIndicator()])));
} else if (snapshot.hasError) {
appState.connector.performDisconnect();
appState.connector!.performDisconnect();
return AlertDialog(
title: Text(localizations.slot_settings),
content: Text(
Expand Down Expand Up @@ -183,7 +183,7 @@ class SlotSettingsState extends State<SlotSettings> {
}),
const SizedBox(height: 16),
Text(
localizations.mifare_clasic_e_s,
localizations.mifare_classic_emulator_settings,
textScaleFactor: 1.1,
),
const SizedBox(height: 8),
Expand Down
22 changes: 12 additions & 10 deletions chameleonultragui/lib/gui/page/connect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ class ConnectPage extends StatelessWidget {

@override
Widget build(BuildContext context) {
var appState = context.watch<ChameleonGUIState>(); // Get State
var appState = context.watch<ChameleonGUIState>();
var localizations = AppLocalizations.of(context)!;
return FutureBuilder(
future:
(appState.connector.connected || appState.connector.pendingConnection)
? Future.value([])
: appState.connector.availableChameleons(false),
future: (appState.connector!.connected ||
appState.connector!.pendingConnection)
? Future.value([])
: appState.connector!.availableChameleons(false),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Scaffold(
Expand All @@ -29,7 +29,7 @@ class ConnectPage extends StatelessWidget {
),
body: const Center(child: CircularProgressIndicator()));
} else if (snapshot.hasError) {
appState.connector.performDisconnect();
appState.connector!.performDisconnect();
return Text('${localizations.error}: ${snapshot.error}');
} else {
final (result as List<Chameleon>) = snapshot.data;
Expand All @@ -40,7 +40,7 @@ class ConnectPage extends StatelessWidget {
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center, // Center
mainAxisAlignment: MainAxisAlignment.center,
children: [
Align(
alignment: Alignment.topRight,
Expand Down Expand Up @@ -117,15 +117,17 @@ class ConnectPage extends StatelessWidget {
} else {
if (chameleonDevice.type ==
ConnectionType.ble) {
appState.connector.pendingConnection = true;
appState.connector!.pendingConnection =
true;
appState.changesMade();
}
await appState.connector
await appState.connector!
.connectSpecificDevice(
chameleonDevice.port);
appState.communicator = ChameleonCommunicator(
appState.log!,
port: appState.connector);
appState.connector.pendingConnection = false;
appState.connector!.pendingConnection = false;
appState.changesMade();
}
},
Expand Down
Loading

0 comments on commit 5812f3f

Please sign in to comment.