refactor(connector): adjust frame length check and simplify contact handling logic

refactor(settings): extract settings sending logic into a separate method
refactor(ble_debug_log_service): remove unused command case for radio settings
refactor(app_bar): update compact width threshold for app bar display
This commit is contained in:
Winston Lowe
2026-03-01 13:05:57 -08:00
parent d2640e1294
commit fcab69f9f0
4 changed files with 30 additions and 24 deletions
+2 -12
View File
@@ -2060,7 +2060,7 @@ class MeshCoreConnector extends ChangeNotifier {
_selfLatitude = readInt32LE(frame, 36) / 1000000.0; _selfLatitude = readInt32LE(frame, 36) / 1000000.0;
_selfLongitude = readInt32LE(frame, 40) / 1000000.0; _selfLongitude = readInt32LE(frame, 40) / 1000000.0;
if (frame.length >= 47 && frame[47] == 0x00) { if (frame.length >= 48 && frame[47] == 0x00) {
sendFrame(buildSetOtherParamsFrame(0, 0, 0)); sendFrame(buildSetOtherParamsFrame(0, 0, 0));
} }
@@ -3947,17 +3947,6 @@ class MeshCoreConnector extends ChangeNotifier {
final existingIndex = _discoveredContacts.indexWhere( final existingIndex = _discoveredContacts.indexWhere(
(c) => c.publicKeyHex == contact.publicKeyHex, (c) => c.publicKeyHex == contact.publicKeyHex,
); );
final existingContactsIndex = _contacts.indexWhere(
(c) => c.publicKeyHex == contact.publicKeyHex,
);
if (existingContactsIndex >= 0) {
if (existingIndex >= 0) {
removeDiscoveredContact(_discoveredContacts[existingIndex]);
unawaited(_persistDiscoveredContacts());
}
return;
}
// Update existing contact // Update existing contact
if (existingIndex >= 0) { if (existingIndex >= 0) {
@@ -3972,6 +3961,7 @@ class MeshCoreConnector extends ChangeNotifier {
longitude: contact.longitude, longitude: contact.longitude,
lastSeen: contact.lastSeen, lastSeen: contact.lastSeen,
); );
notifyListeners();
return; return;
} }
+27 -9
View File
@@ -938,16 +938,15 @@ class _SettingsScreenState extends State<SettingsScreen> {
child: Text(l10n.common_cancel), child: Text(l10n.common_cancel),
), ),
TextButton( TextButton(
onPressed: () async { onPressed: () {
final frame = buildSetAutoAddConfigFrame( _sendSettings(
autoAddChat: autoAddChat, connector,
autoAddRepeater: autoAddRepeater, autoAddChat,
autoAddRoomServer: autoAddRoomServer, autoAddRepeater,
autoAddSensor: autoAddSensor, autoAddRoomServer,
overwriteOldest: overwriteOldest, autoAddSensor,
overwriteOldest,
); );
await connector.sendFrame(frame);
await connector.sendFrame(buildGetAutoAddFlagsFrame());
Navigator.pop(context); Navigator.pop(context);
}, },
child: Text(l10n.common_save), child: Text(l10n.common_save),
@@ -957,6 +956,25 @@ class _SettingsScreenState extends State<SettingsScreen> {
), ),
); );
} }
void _sendSettings(
MeshCoreConnector connector,
autoAddChat,
autoAddRepeater,
autoAddRoomServer,
autoAddSensor,
overwriteOldest,
) async {
final frame = buildSetAutoAddConfigFrame(
autoAddChat: autoAddChat,
autoAddRepeater: autoAddRepeater,
autoAddRoomServer: autoAddRoomServer,
autoAddSensor: autoAddSensor,
overwriteOldest: overwriteOldest,
);
await connector.sendFrame(frame);
await connector.sendFrame(buildGetAutoAddFlagsFrame());
}
} }
class _RadioSettingsDialog extends StatefulWidget { class _RadioSettingsDialog extends StatefulWidget {
-2
View File
@@ -172,8 +172,6 @@ class BleDebugLogService extends ChangeNotifier {
return 'CMD_GET_CHANNEL'; return 'CMD_GET_CHANNEL';
case cmdSetChannel: case cmdSetChannel:
return 'CMD_SET_CHANNEL'; return 'CMD_SET_CHANNEL';
case cmdGetRadioSettings:
return 'CMD_GET_RADIO_SETTINGS';
case cmdSetCustomVar: case cmdSetCustomVar:
return 'CMD_SET_CUSTOM_VAR'; return 'CMD_SET_CUSTOM_VAR';
case cmdSendTracePath: case cmdSendTracePath:
+1 -1
View File
@@ -30,7 +30,7 @@ class AppBarTitle extends StatelessWidget {
final availableWidth = constraints.hasBoundedWidth final availableWidth = constraints.hasBoundedWidth
? constraints.maxWidth ? constraints.maxWidth
: MediaQuery.sizeOf(context).width; : MediaQuery.sizeOf(context).width;
final compact = availableWidth < 240; final compact = availableWidth < 170;
final showSubtitle = final showSubtitle =
!compact && connector.isConnected && selfName != null && subtitle; !compact && connector.isConnected && selfName != null && subtitle;
final showBattery = availableWidth >= 60; final showBattery = availableWidth >= 60;