mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-04-20 22:13:48 +00:00
The first issue was that the toggle switch states weren't being initialized when settings were refreshed from the device. The code would correctly update the interval values themselves, but failed to set the corresponding boolean flags that control whether the toggles appear as "on" or "off". This meant that if you refreshed settings from a device that had advertisements disabled (with an interval of zero), the toggles would incorrectly show as enabled even though the device was actually broadcasting no advertisements. We fixed this by adding two lines that explicitly set _advertEnable = _advertInterval > 0 and _floodAdvertEnable = _floodAdvertInterval > 0 after parsing the interval values from device responses.
The second critical bug was in the validation logic that checks whether responses from the device contain valid data. The validator was rejecting any interval values of zero because it checked interval > 0, but zero is now a meaningful and valid value that indicates advertisements are disabled. Without this fix, any time a device reported back that advertisements were disabled, the app would silently discard that information as invalid, leaving the UI out of sync with reality. We changed the validation to use interval >= 0 instead and updated the comment to explicitly document that zero means disabled. The third fix was a minor code style issue where a single-line if statement was missing braces, causing a linter warning. This doesn't affect functionality but ensures the code meets project standards.
This commit is contained in:
parent
be54419e5b
commit
818f514702
1 changed files with 6 additions and 3 deletions
|
|
@ -248,12 +248,14 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
|||
_fetchedSettings['advert.interval']!,
|
||||
_advertInterval,
|
||||
);
|
||||
_advertEnable = _advertInterval > 0;
|
||||
}
|
||||
if (_fetchedSettings.containsKey('flood.advert.interval')) {
|
||||
_floodAdvertInterval = _parseIntWithFallback(
|
||||
_fetchedSettings['flood.advert.interval']!,
|
||||
_floodAdvertInterval,
|
||||
);
|
||||
_floodAdvertEnable = _floodAdvertInterval > 0;
|
||||
}
|
||||
if (_fetchedSettings.containsKey('priv.advert.interval')) {
|
||||
_privAdvertInterval = _parseIntWithFallback(
|
||||
|
|
@ -379,18 +381,19 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
|||
case 'advert.interval':
|
||||
case 'flood.advert.interval':
|
||||
case 'priv.advert.interval':
|
||||
// Interval: positive integer
|
||||
// Interval: non-negative integer (0 means disabled)
|
||||
if (value.contains(',')) return false;
|
||||
final interval = int.tryParse(value.replaceAll(RegExp(r'[^0-9]'), ''));
|
||||
return interval != null && interval > 0;
|
||||
return interval != null && interval >= 0;
|
||||
|
||||
case 'name':
|
||||
// Name: any non-empty string, but should NOT look like radio settings
|
||||
if (value.isEmpty) return false;
|
||||
// If it has 3+ commas and looks like numbers, probably radio data
|
||||
final commaCount = ','.allMatches(value).length;
|
||||
if (commaCount >= 3 && RegExp(r'^[\d.,\s]+$').hasMatch(value))
|
||||
if (commaCount >= 3 && RegExp(r'^[\d.,\s]+$').hasMatch(value)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
default:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue