From 296eab20ca6b4655dc9b29b732e7fd95e565540c Mon Sep 17 00:00:00 2001 From: shortwavesurfer2009 Date: Sun, 4 Oct 2026 00:48:51 -0400 Subject: [PATCH 1/5] Add low battery notification channel with threshold alerts --- lib/connector/meshcore_connector.dart | 27 ++++++++ lib/l10n/app_en.arb | 13 ++++ lib/l10n/app_localizations.dart | 12 ++++ lib/l10n/app_localizations_bg.dart | 8 +++ lib/l10n/app_localizations_de.dart | 8 +++ lib/l10n/app_localizations_en.dart | 8 +++ lib/l10n/app_localizations_es.dart | 8 +++ lib/l10n/app_localizations_fr.dart | 8 +++ lib/l10n/app_localizations_hu.dart | 8 +++ lib/l10n/app_localizations_it.dart | 8 +++ lib/l10n/app_localizations_ja.dart | 8 +++ lib/l10n/app_localizations_ko.dart | 8 +++ lib/l10n/app_localizations_nl.dart | 8 +++ lib/l10n/app_localizations_pl.dart | 8 +++ lib/l10n/app_localizations_pt.dart | 8 +++ lib/l10n/app_localizations_ru.dart | 8 +++ lib/l10n/app_localizations_sk.dart | 8 +++ lib/l10n/app_localizations_sl.dart | 8 +++ lib/l10n/app_localizations_sv.dart | 8 +++ lib/l10n/app_localizations_uk.dart | 8 +++ lib/l10n/app_localizations_zh.dart | 8 +++ lib/services/notification_service.dart | 45 +++++++++++++ untranslated.json | 87 +++++++++++++++++++++++++- 23 files changed, 327 insertions(+), 1 deletion(-) diff --git a/lib/connector/meshcore_connector.dart b/lib/connector/meshcore_connector.dart index 7874bc18..5b96b31f 100644 --- a/lib/connector/meshcore_connector.dart +++ b/lib/connector/meshcore_connector.dart @@ -266,6 +266,10 @@ class MeshCoreConnector extends ChangeNotifier { Stopwatch? _airtimeBumpStopwatch; int _prevTotalAirSecs = 0; int? _batteryMillivolts; + // Thresholds (percent) that trigger a low-battery notification once per + // crossing, re-arming 5 points above the threshold after recharge. + static const List _lowBatteryThresholds = [25, 10]; + final Set _batteryAlertedThresholds = {}; double? _selfLatitude; double? _selfLongitude; final List _directRepeaters = List.empty(growable: true); @@ -3139,6 +3143,7 @@ class MeshCoreConnector extends ChangeNotifier { _autoAddMaxHops = null; _contactsStorageFull = false; _batteryMillivolts = null; + _batteryAlertedThresholds.clear(); _repeaterBatterySnapshots.clear(); _batteryRequested = false; _awaitingSelfInfo = false; @@ -5357,6 +5362,7 @@ class MeshCoreConnector extends ChangeNotifier { _batteryMillivolts = reader.readUInt16LE(); _storageUsedKb = reader.readUInt32LE(); _storageTotalKb = reader.readUInt32LE(); + _checkLowBatteryThresholds(); final volts = (_batteryMillivolts! / 1000.0).toStringAsFixed(2); _appDebugLogService?.info( 'Pulled battery: $volts V ($_batteryMillivolts mV)', @@ -5371,6 +5377,27 @@ class MeshCoreConnector extends ChangeNotifier { } } + void _checkLowBatteryThresholds() { + final percent = batteryPercent; + if (percent == null) return; + + for (final threshold in _lowBatteryThresholds) { + if (percent <= threshold && + !_batteryAlertedThresholds.contains(threshold)) { + _batteryAlertedThresholds.add(threshold); + NotificationService().showLowBatteryNotification( + batteryPercent: percent, + threshold: threshold, + ); + } else if (percent > threshold + 5 && + _batteryAlertedThresholds.contains(threshold)) { + // Re-arm once the battery recovers 5 points above the threshold, + // so a recharge + discharge cycle alerts again without flapping. + _batteryAlertedThresholds.remove(threshold); + } + } + } + void _checkManualAddContacts() async { // If manual add contacts is enabled, set auto add config and other params. // and disable it after diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 47f2dba6..a8718ea7 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -2573,6 +2573,19 @@ "contacts_contactAdvertCopied": "Advert copied to Clipboard.", "contacts_contactAdvertCopyFailed": "Copying advert to Clipboard failed.", "notification_activityTitle": "MeshCore Activity", + "notification_lowBatteryTitle": "Low battery", + "@notification_lowBatteryTitle": { + "description": "Title of the low battery notification" + }, + "notification_lowBatteryBody": "Device battery is at {percent}%", + "@notification_lowBatteryBody": { + "description": "Body of the low battery notification", + "placeholders": { + "percent": { + "type": "int" + } + } + }, "notification_messagesCount": "{count} {count, plural, =1{message} other{messages}}", "@notification_messagesCount": { "placeholders": { diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dart index 66eedf4c..c5c9e414 100644 --- a/lib/l10n/app_localizations.dart +++ b/lib/l10n/app_localizations.dart @@ -7924,6 +7924,18 @@ abstract class AppLocalizations { /// **'MeshCore Activity'** String get notification_activityTitle; + /// Title of the low battery notification + /// + /// In en, this message translates to: + /// **'Low battery'** + String get notification_lowBatteryTitle; + + /// Body of the low battery notification + /// + /// In en, this message translates to: + /// **'Device battery is at {percent}%'** + String notification_lowBatteryBody(int percent); + /// No description provided for @notification_messagesCount. /// /// In en, this message translates to: diff --git a/lib/l10n/app_localizations_bg.dart b/lib/l10n/app_localizations_bg.dart index c54ab2ee..c1c2ac7f 100644 --- a/lib/l10n/app_localizations_bg.dart +++ b/lib/l10n/app_localizations_bg.dart @@ -4597,6 +4597,14 @@ class AppLocalizationsBg extends AppLocalizations { @override String get notification_activityTitle => 'Активност на MeshCore'; + @override + String get notification_lowBatteryTitle => 'Low battery'; + + @override + String notification_lowBatteryBody(int percent) { + return 'Device battery is at $percent%'; + } + @override String notification_messagesCount(int count) { String _temp0 = intl.Intl.pluralLogic( diff --git a/lib/l10n/app_localizations_de.dart b/lib/l10n/app_localizations_de.dart index ca2ada41..e33166ef 100644 --- a/lib/l10n/app_localizations_de.dart +++ b/lib/l10n/app_localizations_de.dart @@ -4608,6 +4608,14 @@ class AppLocalizationsDe extends AppLocalizations { @override String get notification_activityTitle => 'MeshCore Aktivität'; + @override + String get notification_lowBatteryTitle => 'Low battery'; + + @override + String notification_lowBatteryBody(int percent) { + return 'Device battery is at $percent%'; + } + @override String notification_messagesCount(int count) { String _temp0 = intl.Intl.pluralLogic( diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dart index 70ce610f..b2f769bf 100644 --- a/lib/l10n/app_localizations_en.dart +++ b/lib/l10n/app_localizations_en.dart @@ -4533,6 +4533,14 @@ class AppLocalizationsEn extends AppLocalizations { @override String get notification_activityTitle => 'MeshCore Activity'; + @override + String get notification_lowBatteryTitle => 'Low battery'; + + @override + String notification_lowBatteryBody(int percent) { + return 'Device battery is at $percent%'; + } + @override String notification_messagesCount(int count) { String _temp0 = intl.Intl.pluralLogic( diff --git a/lib/l10n/app_localizations_es.dart b/lib/l10n/app_localizations_es.dart index f0c31cb3..1a1f1e81 100644 --- a/lib/l10n/app_localizations_es.dart +++ b/lib/l10n/app_localizations_es.dart @@ -4599,6 +4599,14 @@ class AppLocalizationsEs extends AppLocalizations { @override String get notification_activityTitle => 'Actividad de MeshCore'; + @override + String get notification_lowBatteryTitle => 'Low battery'; + + @override + String notification_lowBatteryBody(int percent) { + return 'Device battery is at $percent%'; + } + @override String notification_messagesCount(int count) { String _temp0 = intl.Intl.pluralLogic( diff --git a/lib/l10n/app_localizations_fr.dart b/lib/l10n/app_localizations_fr.dart index 0385315d..176f8008 100644 --- a/lib/l10n/app_localizations_fr.dart +++ b/lib/l10n/app_localizations_fr.dart @@ -4619,6 +4619,14 @@ class AppLocalizationsFr extends AppLocalizations { @override String get notification_activityTitle => 'Activité MeshCore'; + @override + String get notification_lowBatteryTitle => 'Low battery'; + + @override + String notification_lowBatteryBody(int percent) { + return 'Device battery is at $percent%'; + } + @override String notification_messagesCount(int count) { String _temp0 = intl.Intl.pluralLogic( diff --git a/lib/l10n/app_localizations_hu.dart b/lib/l10n/app_localizations_hu.dart index 0b909253..e42e58d3 100644 --- a/lib/l10n/app_localizations_hu.dart +++ b/lib/l10n/app_localizations_hu.dart @@ -4597,6 +4597,14 @@ class AppLocalizationsHu extends AppLocalizations { @override String get notification_activityTitle => 'MeshCore tevékenység'; + @override + String get notification_lowBatteryTitle => 'Low battery'; + + @override + String notification_lowBatteryBody(int percent) { + return 'Device battery is at $percent%'; + } + @override String notification_messagesCount(int count) { String _temp0 = intl.Intl.pluralLogic( diff --git a/lib/l10n/app_localizations_it.dart b/lib/l10n/app_localizations_it.dart index e737afdd..d29f0045 100644 --- a/lib/l10n/app_localizations_it.dart +++ b/lib/l10n/app_localizations_it.dart @@ -4604,6 +4604,14 @@ class AppLocalizationsIt extends AppLocalizations { @override String get notification_activityTitle => 'Attività MeshCore'; + @override + String get notification_lowBatteryTitle => 'Low battery'; + + @override + String notification_lowBatteryBody(int percent) { + return 'Device battery is at $percent%'; + } + @override String notification_messagesCount(int count) { String _temp0 = intl.Intl.pluralLogic( diff --git a/lib/l10n/app_localizations_ja.dart b/lib/l10n/app_localizations_ja.dart index 86130828..65f7d04e 100644 --- a/lib/l10n/app_localizations_ja.dart +++ b/lib/l10n/app_localizations_ja.dart @@ -4373,6 +4373,14 @@ class AppLocalizationsJa extends AppLocalizations { @override String get notification_activityTitle => 'メッシュコアの活動'; + @override + String get notification_lowBatteryTitle => 'Low battery'; + + @override + String notification_lowBatteryBody(int percent) { + return 'Device battery is at $percent%'; + } + @override String notification_messagesCount(int count) { String _temp0 = intl.Intl.pluralLogic( diff --git a/lib/l10n/app_localizations_ko.dart b/lib/l10n/app_localizations_ko.dart index 94c0f3bd..c8ca6e2b 100644 --- a/lib/l10n/app_localizations_ko.dart +++ b/lib/l10n/app_localizations_ko.dart @@ -4384,6 +4384,14 @@ class AppLocalizationsKo extends AppLocalizations { @override String get notification_activityTitle => '메쉬코어 활동'; + @override + String get notification_lowBatteryTitle => 'Low battery'; + + @override + String notification_lowBatteryBody(int percent) { + return 'Device battery is at $percent%'; + } + @override String notification_messagesCount(int count) { String _temp0 = intl.Intl.pluralLogic( diff --git a/lib/l10n/app_localizations_nl.dart b/lib/l10n/app_localizations_nl.dart index 0c7a199a..9369eb42 100644 --- a/lib/l10n/app_localizations_nl.dart +++ b/lib/l10n/app_localizations_nl.dart @@ -4575,6 +4575,14 @@ class AppLocalizationsNl extends AppLocalizations { @override String get notification_activityTitle => 'MeshCore Activiteit'; + @override + String get notification_lowBatteryTitle => 'Low battery'; + + @override + String notification_lowBatteryBody(int percent) { + return 'Device battery is at $percent%'; + } + @override String notification_messagesCount(int count) { String _temp0 = intl.Intl.pluralLogic( diff --git a/lib/l10n/app_localizations_pl.dart b/lib/l10n/app_localizations_pl.dart index fbe65401..42862a06 100644 --- a/lib/l10n/app_localizations_pl.dart +++ b/lib/l10n/app_localizations_pl.dart @@ -4623,6 +4623,14 @@ class AppLocalizationsPl extends AppLocalizations { @override String get notification_activityTitle => 'Aktywność MeshCore'; + @override + String get notification_lowBatteryTitle => 'Low battery'; + + @override + String notification_lowBatteryBody(int percent) { + return 'Device battery is at $percent%'; + } + @override String notification_messagesCount(int count) { String _temp0 = intl.Intl.pluralLogic( diff --git a/lib/l10n/app_localizations_pt.dart b/lib/l10n/app_localizations_pt.dart index 4c3b7c43..19e4552a 100644 --- a/lib/l10n/app_localizations_pt.dart +++ b/lib/l10n/app_localizations_pt.dart @@ -4601,6 +4601,14 @@ class AppLocalizationsPt extends AppLocalizations { @override String get notification_activityTitle => 'Atividade MeshCore'; + @override + String get notification_lowBatteryTitle => 'Low battery'; + + @override + String notification_lowBatteryBody(int percent) { + return 'Device battery is at $percent%'; + } + @override String notification_messagesCount(int count) { String _temp0 = intl.Intl.pluralLogic( diff --git a/lib/l10n/app_localizations_ru.dart b/lib/l10n/app_localizations_ru.dart index b197ce46..1916766f 100644 --- a/lib/l10n/app_localizations_ru.dart +++ b/lib/l10n/app_localizations_ru.dart @@ -4607,6 +4607,14 @@ class AppLocalizationsRu extends AppLocalizations { @override String get notification_activityTitle => 'Активность MeshCore'; + @override + String get notification_lowBatteryTitle => 'Low battery'; + + @override + String notification_lowBatteryBody(int percent) { + return 'Device battery is at $percent%'; + } + @override String notification_messagesCount(int count) { String _temp0 = intl.Intl.pluralLogic( diff --git a/lib/l10n/app_localizations_sk.dart b/lib/l10n/app_localizations_sk.dart index 2818ab6b..daf8043e 100644 --- a/lib/l10n/app_localizations_sk.dart +++ b/lib/l10n/app_localizations_sk.dart @@ -4581,6 +4581,14 @@ class AppLocalizationsSk extends AppLocalizations { @override String get notification_activityTitle => 'Aktivita MeshCore'; + @override + String get notification_lowBatteryTitle => 'Low battery'; + + @override + String notification_lowBatteryBody(int percent) { + return 'Device battery is at $percent%'; + } + @override String notification_messagesCount(int count) { String _temp0 = intl.Intl.pluralLogic( diff --git a/lib/l10n/app_localizations_sl.dart b/lib/l10n/app_localizations_sl.dart index ab8ba209..de74a7b3 100644 --- a/lib/l10n/app_localizations_sl.dart +++ b/lib/l10n/app_localizations_sl.dart @@ -4579,6 +4579,14 @@ class AppLocalizationsSl extends AppLocalizations { @override String get notification_activityTitle => 'Aktivnost MeshCore'; + @override + String get notification_lowBatteryTitle => 'Low battery'; + + @override + String notification_lowBatteryBody(int percent) { + return 'Device battery is at $percent%'; + } + @override String notification_messagesCount(int count) { String _temp0 = intl.Intl.pluralLogic( diff --git a/lib/l10n/app_localizations_sv.dart b/lib/l10n/app_localizations_sv.dart index aa6022e0..f5fc9e5e 100644 --- a/lib/l10n/app_localizations_sv.dart +++ b/lib/l10n/app_localizations_sv.dart @@ -4557,6 +4557,14 @@ class AppLocalizationsSv extends AppLocalizations { @override String get notification_activityTitle => 'MeshCore Aktivitet'; + @override + String get notification_lowBatteryTitle => 'Low battery'; + + @override + String notification_lowBatteryBody(int percent) { + return 'Device battery is at $percent%'; + } + @override String notification_messagesCount(int count) { String _temp0 = intl.Intl.pluralLogic( diff --git a/lib/l10n/app_localizations_uk.dart b/lib/l10n/app_localizations_uk.dart index c3e5f7a0..be816508 100644 --- a/lib/l10n/app_localizations_uk.dart +++ b/lib/l10n/app_localizations_uk.dart @@ -4607,6 +4607,14 @@ class AppLocalizationsUk extends AppLocalizations { @override String get notification_activityTitle => 'Активність MeshCore'; + @override + String get notification_lowBatteryTitle => 'Low battery'; + + @override + String notification_lowBatteryBody(int percent) { + return 'Device battery is at $percent%'; + } + @override String notification_messagesCount(int count) { String _temp0 = intl.Intl.pluralLogic( diff --git a/lib/l10n/app_localizations_zh.dart b/lib/l10n/app_localizations_zh.dart index d9d7281e..a9f91a99 100644 --- a/lib/l10n/app_localizations_zh.dart +++ b/lib/l10n/app_localizations_zh.dart @@ -4285,6 +4285,14 @@ class AppLocalizationsZh extends AppLocalizations { @override String get notification_activityTitle => 'MeshCore 活动'; + @override + String get notification_lowBatteryTitle => 'Low battery'; + + @override + String notification_lowBatteryBody(int percent) { + return 'Device battery is at $percent%'; + } + @override String notification_messagesCount(int count) { return '$count 条消息'; diff --git a/lib/services/notification_service.dart b/lib/services/notification_service.dart index 83714cfa..333466e4 100644 --- a/lib/services/notification_service.dart +++ b/lib/services/notification_service.dart @@ -597,6 +597,51 @@ class NotificationService { } } + /// Posts a low-battery alert for the connected device. + /// + /// Uses a per-threshold notification id so each alert level updates its own + /// notification instead of stacking. Bypasses the rate-limit queue, which + /// only handles message and advert notifications. + Future showLowBatteryNotification({ + required int batteryPercent, + required int threshold, + }) async { + if (!await _ensureCanNotify()) return; + + const androidDetails = AndroidNotificationDetails( + 'low_battery', + 'Low Battery', + channelDescription: 'Low battery alerts for the connected device', + importance: Importance.high, + priority: Priority.high, + icon: '@mipmap/ic_launcher', + ); + + const darwinDetails = DarwinNotificationDetails( + presentAlert: true, + presentBadge: false, + presentSound: true, + ); + + const notificationDetails = NotificationDetails( + android: androidDetails, + iOS: darwinDetails, + macOS: darwinDetails, + ); + + try { + await _notifications.show( + id: 'low_battery:$threshold'.hashCode, + title: _l10n.notification_lowBatteryTitle, + body: _l10n.notification_lowBatteryBody(batteryPercent), + notificationDetails: notificationDetails, + payload: 'low_battery', + ); + } catch (e) { + debugPrint('Failed to show low battery notification: $e'); + } + } + /// Returns a privacy-safe identifier for debug logging. /// - advert: shows device name (body contains contactName) /// - message: shows "from: sender" (avoids logging message content) diff --git a/untranslated.json b/untranslated.json index 9e26dfee..440e93f0 100644 --- a/untranslated.json +++ b/untranslated.json @@ -1 +1,86 @@ -{} \ No newline at end of file +{ + "bg": [ + "notification_lowBatteryTitle", + "notification_lowBatteryBody" + ], + + "de": [ + "notification_lowBatteryTitle", + "notification_lowBatteryBody" + ], + + "es": [ + "notification_lowBatteryTitle", + "notification_lowBatteryBody" + ], + + "fr": [ + "notification_lowBatteryTitle", + "notification_lowBatteryBody" + ], + + "hu": [ + "notification_lowBatteryTitle", + "notification_lowBatteryBody" + ], + + "it": [ + "notification_lowBatteryTitle", + "notification_lowBatteryBody" + ], + + "ja": [ + "notification_lowBatteryTitle", + "notification_lowBatteryBody" + ], + + "ko": [ + "notification_lowBatteryTitle", + "notification_lowBatteryBody" + ], + + "nl": [ + "notification_lowBatteryTitle", + "notification_lowBatteryBody" + ], + + "pl": [ + "notification_lowBatteryTitle", + "notification_lowBatteryBody" + ], + + "pt": [ + "notification_lowBatteryTitle", + "notification_lowBatteryBody" + ], + + "ru": [ + "notification_lowBatteryTitle", + "notification_lowBatteryBody" + ], + + "sk": [ + "notification_lowBatteryTitle", + "notification_lowBatteryBody" + ], + + "sl": [ + "notification_lowBatteryTitle", + "notification_lowBatteryBody" + ], + + "sv": [ + "notification_lowBatteryTitle", + "notification_lowBatteryBody" + ], + + "uk": [ + "notification_lowBatteryTitle", + "notification_lowBatteryBody" + ], + + "zh": [ + "notification_lowBatteryTitle", + "notification_lowBatteryBody" + ] +} From c161bffc837adcc12dc38fda8dc6b241f47eddf5 Mon Sep 17 00:00:00 2001 From: shortwavesurfer2009 Date: Mon, 5 Oct 2026 19:19:08 -0400 Subject: [PATCH 2/5] fold path hash size into radio settings --- lib/models/radio_settings.dart | 2 ++ lib/screens/settings_screen.dart | 38 ++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/lib/models/radio_settings.dart b/lib/models/radio_settings.dart index f7c4709c..6b3eee84 100644 --- a/lib/models/radio_settings.dart +++ b/lib/models/radio_settings.dart @@ -50,6 +50,7 @@ class RadioSettings { final LoRaSpreadingFactor spreadingFactor; final LoRaCodingRate codingRate; final int txPowerDbm; + final int pathHashByteWidth; RadioSettings({ required this.frequencyMHz, @@ -57,6 +58,7 @@ class RadioSettings { required this.spreadingFactor, required this.codingRate, required this.txPowerDbm, + this.pathHashByteWidth = 1, // app default; presets override if needed }); // Regional preset configurations diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dart index 502e0f18..c94e23f2 100644 --- a/lib/screens/settings_screen.dart +++ b/lib/screens/settings_screen.dart @@ -1526,10 +1526,14 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> { LoRaCodingRate _codingRate = LoRaCodingRate.cr4_5; final _txPowerController = TextEditingController(text: '20'); bool _clientRepeat = false; + int _pathHashByteWidth = 1; int? _selectedPresetIndex; _RadioSettingsSnapshot? _lastNonRepeatSnapshot; String? _frequencyError; String? _txPowerError; + bool get _supportsPathHashMode => + (widget.connector.firmwareVerCode ?? 0) >= + _minFirmwareVerCodeForPathHashMode; AppDebugLogService get _appLog => Provider.of(context, listen: false); @@ -1583,6 +1587,7 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> { _txPowerController.text = widget.connector.currentTxPower.toString(); } + _pathHashByteWidth = widget.connector.pathHashByteWidth; _clientRepeat = widget.connector.clientRepeat ?? false; _selectedPresetIndex = _findMatchingPresetIndex(); if (_clientRepeat) { @@ -1752,6 +1757,7 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> { _spreadingFactor = preset.spreadingFactor; _codingRate = preset.codingRate; _txPowerController.text = preset.txPowerDbm.toString(); + _pathHashByteWidth = preset.pathHashByteWidth; _selectedPresetIndex = index; _lastNonRepeatSnapshot = baseSnapshot; } @@ -1911,6 +1917,10 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> { return; } await widget.connector.sendFrame(buildSetRadioTxPowerFrame(txPower)); + if (_supportsPathHashMode && + _pathHashByteWidth != widget.connector.pathHashByteWidth) { + await widget.connector.setPathHashMode(_pathHashByteWidth - 1); + } final selfInfo = widget.connector.receivedFrames .firstWhere((f) => f.isNotEmpty && f[0] == respCodeSelfInfo) .timeout(const Duration(seconds: 5)); @@ -2144,6 +2154,34 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> { }, ), const SizedBox(height: 16), + if (_supportsPathHashMode) ...[ + DropdownButtonFormField( + initialValue: _pathHashByteWidth, + decoration: InputDecoration( + labelText: l10n.repeater_pathHashMode, + border: const OutlineInputBorder(), + ), + items: [ + DropdownMenuItem( + value: 1, + child: Text(l10n.repeater_pathHashModeOption0), + ), + DropdownMenuItem( + value: 2, + child: Text(l10n.repeater_pathHashModeOption1), + ), + DropdownMenuItem( + value: 3, + child: Text(l10n.repeater_pathHashModeOption2), + ), + ], + onChanged: (value) { + if (value == null) return; + setState(() => _pathHashByteWidth = value); + }, + ), + const SizedBox(height: 16), + ], TextField( controller: _txPowerController, onChanged: (_) => _handleManualSettingsChanged('tx power'), From fe7e72a4218cf314f2ca106e83041d400f9b6a20 Mon Sep 17 00:00:00 2001 From: zjs81 Date: Sat, 24 Oct 2026 20:22:12 -0700 Subject: [PATCH 3/5] Make Android Auto an opt-in build flag Android Auto support is now merged into the app only when building with -PandroidAuto=true (flutter build apk --android-project-arg=androidAuto=true). The car application meta-data and automotive_app_desc.xml move to android/app/src/androidAuto/, so default builds no longer declare Android Auto. Notification replies from the shade and watches are unchanged. --- README.md | 6 +++--- android/app/build.gradle.kts | 18 ++++++++++++++++++ .../app/src/androidAuto/AndroidManifest.xml | 9 +++++++++ .../res/xml/automotive_app_desc.xml | 0 android/app/src/main/AndroidManifest.xml | 4 ---- documentation/notifications.md | 8 ++++++++ 6 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 android/app/src/androidAuto/AndroidManifest.xml rename android/app/src/{main => androidAuto}/res/xml/automotive_app_desc.xml (100%) diff --git a/README.md b/README.md index 92d60fe4..1ca9ba29 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ See the [user documentation](documentation/README.md), [connection guide](docume - **Contact Groups**: Create custom groups to organize your mesh network contacts - **Message Reactions**: React to messages with emoji responses - **Message Replies**: Thread conversations with inline reply functionality -- **Android Auto & Watches**: Hear messages and reply by voice in Android Auto, or reply from the notification shade and Wear OS/Galaxy watches ([guide](documentation/notifications.md#android-auto)) +- **Android Auto & Watches**: Reply from the notification shade and Wear OS/Galaxy watches, or hear messages and reply by voice in Android Auto (optional build flag) ([guide](documentation/notifications.md#android-auto)) - **Channel Muting**: Mute a channel from its chat screen, the channel list, or its notification ### Mesh Network @@ -103,7 +103,7 @@ See the [user documentation](documentation/README.md), [connection guide](docume | Map & Location | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | Device Management | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | Repeater Hub | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| Notification replies | ✅
(incl. Android Auto, watches) | ❌ | ❌ | ❌ | ❌ | ❌ | +| Notification replies | ✅
(incl. watches; Android Auto optional) | ❌ | ❌ | ❌ | ❌ | ❌ | The matrix describes implemented functionality, not a guarantee that every feature has been tested on every device. Web device connections use Web Serial and require Chrome and a secure origin. Image inference and translation require native runtimes and are unavailable on web. Android APKs currently include only `arm64-v8a`; the minimum Android API follows the Flutter SDK used to build. @@ -228,7 +228,7 @@ Messages are transmitted as binary frames using a custom protocol optimized for - **Theme**: System default, light, or dark mode - **Language**: Use one of 18 languages (English, Chinese, French, Spanish, Portuguese, German, Dutch, Polish, Swedish, Italian, Slovak, Slovenian, Bulgarian, Russian, Ukrainian, Hungarian, Japanese, Korean) -- **Notifications**: Configurable for messages, channels, and node advertisements; per-channel muting; reply, mark-as-read, and mute actions on Android notifications and watches (reply and mark-as-read in Android Auto) +- **Notifications**: Configurable for messages, channels, and node advertisements; per-channel muting; reply, mark-as-read, and mute actions on Android notifications and watches (reply and mark-as-read in Android Auto when built with `--android-project-arg=androidAuto=true`) - **Battery Chemistry**: Support for NMC, LiFePO4, LiPo, and LiPo HV battery types - **Message Retry**: Automatic retry with configurable path clearing diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 8aa73ce6..24b5883c 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -98,6 +98,24 @@ android { // } } +// Android Auto (notification read-aloud and voice reply) is opt-in, because +// declaring it puts the app through Play's separate Android Auto review. +// Enable it with `flutter build apk --android-project-arg=androidAuto=true` +// or `./gradlew -PandroidAuto=true ...`. +val androidAutoEnabled = (findProperty("androidAuto") as String?)?.toBoolean() == true + +if (androidAutoEnabled) { + android.sourceSets.getByName("main").res.srcDir("src/androidAuto/res") +} + +androidComponents { + onVariants { variant -> + if (androidAutoEnabled) { + variant.sources.manifests.addStaticManifestFile("src/androidAuto/AndroidManifest.xml") + } + } +} + flutter { source = "../.." } diff --git a/android/app/src/androidAuto/AndroidManifest.xml b/android/app/src/androidAuto/AndroidManifest.xml new file mode 100644 index 00000000..4c5db2aa --- /dev/null +++ b/android/app/src/androidAuto/AndroidManifest.xml @@ -0,0 +1,9 @@ + + + + + + + diff --git a/android/app/src/main/res/xml/automotive_app_desc.xml b/android/app/src/androidAuto/res/xml/automotive_app_desc.xml similarity index 100% rename from android/app/src/main/res/xml/automotive_app_desc.xml rename to android/app/src/androidAuto/res/xml/automotive_app_desc.xml diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 3bb75c69..27d9692a 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -34,10 +34,6 @@ - - Date: Sat, 24 Oct 2026 20:43:00 -0700 Subject: [PATCH 4/5] Fix review findings in radio settings path hash size - Presets no longer reset the path hash size; the unused preset field is gone - Confirm the new path hash size from the refreshed DEVICE_INFO and show a specific error when the radio does not apply it - Log path hash size with the other radio settings and on manual edits - Add MeshCoreConnector.supportsPathHashMode and use it in both screens - Use the same 0-2 mode values and helper text as the other selectors --- lib/connector/meshcore_connector.dart | 3 ++ lib/l10n/app_en.arb | 1 + lib/l10n/app_localizations.dart | 6 +++ lib/l10n/app_localizations_bg.dart | 4 ++ lib/l10n/app_localizations_de.dart | 4 ++ lib/l10n/app_localizations_en.dart | 4 ++ lib/l10n/app_localizations_es.dart | 4 ++ lib/l10n/app_localizations_fr.dart | 4 ++ lib/l10n/app_localizations_hu.dart | 4 ++ lib/l10n/app_localizations_it.dart | 4 ++ lib/l10n/app_localizations_ja.dart | 4 ++ lib/l10n/app_localizations_ko.dart | 4 ++ lib/l10n/app_localizations_nl.dart | 4 ++ lib/l10n/app_localizations_pl.dart | 4 ++ lib/l10n/app_localizations_pt.dart | 4 ++ lib/l10n/app_localizations_ru.dart | 4 ++ lib/l10n/app_localizations_sk.dart | 4 ++ lib/l10n/app_localizations_sl.dart | 4 ++ lib/l10n/app_localizations_sv.dart | 4 ++ lib/l10n/app_localizations_uk.dart | 4 ++ lib/l10n/app_localizations_zh.dart | 4 ++ lib/models/radio_settings.dart | 2 - lib/screens/settings_screen.dart | 11 +--- lib/widgets/radio_settings_dialog.dart | 72 +++++++++++++++++++------- untranslated.json | 70 ++++++++++++++++++++++++- 25 files changed, 205 insertions(+), 32 deletions(-) diff --git a/lib/connector/meshcore_connector.dart b/lib/connector/meshcore_connector.dart index 03b03944..1d7dfa0a 100644 --- a/lib/connector/meshcore_connector.dart +++ b/lib/connector/meshcore_connector.dart @@ -681,6 +681,9 @@ class MeshCoreConnector extends ChangeNotifier { /// from ver code 8. bool get supportsNodeDiscover => (_firmwareVerCode ?? 0) >= 8; + /// CMD_SET_PATH_HASH_MODE exists from ver code 10 (v1.14.0). + bool get supportsPathHashMode => (_firmwareVerCode ?? 0) >= 10; + /// CMD_GET/SET_DEFAULT_FLOOD_SCOPE exist from ver code 11 (v1.15.0). bool get supportsDefaultFloodScope => (_firmwareVerCode ?? 0) >= 11; diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index f62a038b..6d29965a 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -198,6 +198,7 @@ "settings_radioSettingsSubtitle": "Frequency, power, spreading factor", "settings_radioSettingsUpdated": "Radio settings updated", "settings_radioSettingsNotApplied": "The radio did not apply these settings", + "settings_pathHashModeNotApplied": "Radio settings were applied, but the radio did not confirm the new path hash size", "settings_regionSettings": "Regions", "settings_regionSettingsSubtitle": "Limit channel floods to an area", "settings_regionEmptyExplanation": "Regions limit flood messages to repeaters in an area. Fetch them from nearby repeaters or add one by name.", diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dart index b5e7efc5..b7d98c28 100644 --- a/lib/l10n/app_localizations.dart +++ b/lib/l10n/app_localizations.dart @@ -862,6 +862,12 @@ abstract class AppLocalizations { /// **'The radio did not apply these settings'** String get settings_radioSettingsNotApplied; + /// No description provided for @settings_pathHashModeNotApplied. + /// + /// In en, this message translates to: + /// **'Radio settings were applied, but the radio did not confirm the new path hash size'** + String get settings_pathHashModeNotApplied; + /// No description provided for @settings_regionSettings. /// /// In en, this message translates to: diff --git a/lib/l10n/app_localizations_bg.dart b/lib/l10n/app_localizations_bg.dart index b9f79a6f..62a52ade 100644 --- a/lib/l10n/app_localizations_bg.dart +++ b/lib/l10n/app_localizations_bg.dart @@ -425,6 +425,10 @@ class AppLocalizationsBg extends AppLocalizations { String get settings_radioSettingsNotApplied => 'Радиото не приложи тези настройки'; + @override + String get settings_pathHashModeNotApplied => + 'Radio settings were applied, but the radio did not confirm the new path hash size'; + @override String get settings_regionSettings => 'Региони'; diff --git a/lib/l10n/app_localizations_de.dart b/lib/l10n/app_localizations_de.dart index d7893ccf..3b45ccb5 100644 --- a/lib/l10n/app_localizations_de.dart +++ b/lib/l10n/app_localizations_de.dart @@ -427,6 +427,10 @@ class AppLocalizationsDe extends AppLocalizations { String get settings_radioSettingsNotApplied => 'Das Funkgerät hat diese Einstellungen nicht übernommen'; + @override + String get settings_pathHashModeNotApplied => + 'Radio settings were applied, but the radio did not confirm the new path hash size'; + @override String get settings_regionSettings => 'Regionen'; diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dart index 0265ac8b..da8144d5 100644 --- a/lib/l10n/app_localizations_en.dart +++ b/lib/l10n/app_localizations_en.dart @@ -421,6 +421,10 @@ class AppLocalizationsEn extends AppLocalizations { String get settings_radioSettingsNotApplied => 'The radio did not apply these settings'; + @override + String get settings_pathHashModeNotApplied => + 'Radio settings were applied, but the radio did not confirm the new path hash size'; + @override String get settings_regionSettings => 'Regions'; diff --git a/lib/l10n/app_localizations_es.dart b/lib/l10n/app_localizations_es.dart index 75c2ab0e..e40f0fa2 100644 --- a/lib/l10n/app_localizations_es.dart +++ b/lib/l10n/app_localizations_es.dart @@ -425,6 +425,10 @@ class AppLocalizationsEs extends AppLocalizations { String get settings_radioSettingsNotApplied => 'La radio no aplicó esta configuración'; + @override + String get settings_pathHashModeNotApplied => + 'Radio settings were applied, but the radio did not confirm the new path hash size'; + @override String get settings_regionSettings => 'Regiones'; diff --git a/lib/l10n/app_localizations_fr.dart b/lib/l10n/app_localizations_fr.dart index 85de8bbb..3c6ee155 100644 --- a/lib/l10n/app_localizations_fr.dart +++ b/lib/l10n/app_localizations_fr.dart @@ -427,6 +427,10 @@ class AppLocalizationsFr extends AppLocalizations { String get settings_radioSettingsNotApplied => 'La radio n\'a pas appliqué ces paramètres'; + @override + String get settings_pathHashModeNotApplied => + 'Radio settings were applied, but the radio did not confirm the new path hash size'; + @override String get settings_regionSettings => 'Régions'; diff --git a/lib/l10n/app_localizations_hu.dart b/lib/l10n/app_localizations_hu.dart index ef4b3d9b..5bf2522a 100644 --- a/lib/l10n/app_localizations_hu.dart +++ b/lib/l10n/app_localizations_hu.dart @@ -423,6 +423,10 @@ class AppLocalizationsHu extends AppLocalizations { String get settings_radioSettingsNotApplied => 'A rádió nem alkalmazta ezeket a beállításokat'; + @override + String get settings_pathHashModeNotApplied => + 'Radio settings were applied, but the radio did not confirm the new path hash size'; + @override String get settings_regionSettings => 'Tájak'; diff --git a/lib/l10n/app_localizations_it.dart b/lib/l10n/app_localizations_it.dart index 50bb49d9..bcb282ef 100644 --- a/lib/l10n/app_localizations_it.dart +++ b/lib/l10n/app_localizations_it.dart @@ -427,6 +427,10 @@ class AppLocalizationsIt extends AppLocalizations { String get settings_radioSettingsNotApplied => 'La radio non ha applicato queste impostazioni'; + @override + String get settings_pathHashModeNotApplied => + 'Radio settings were applied, but the radio did not confirm the new path hash size'; + @override String get settings_regionSettings => 'Regioni'; diff --git a/lib/l10n/app_localizations_ja.dart b/lib/l10n/app_localizations_ja.dart index 2aabf56e..7d98b2a7 100644 --- a/lib/l10n/app_localizations_ja.dart +++ b/lib/l10n/app_localizations_ja.dart @@ -407,6 +407,10 @@ class AppLocalizationsJa extends AppLocalizations { @override String get settings_radioSettingsNotApplied => 'ラジオがこれらの設定を適用しませんでした'; + @override + String get settings_pathHashModeNotApplied => + 'Radio settings were applied, but the radio did not confirm the new path hash size'; + @override String get settings_regionSettings => '地域'; diff --git a/lib/l10n/app_localizations_ko.dart b/lib/l10n/app_localizations_ko.dart index 98a81ac1..c2a268f9 100644 --- a/lib/l10n/app_localizations_ko.dart +++ b/lib/l10n/app_localizations_ko.dart @@ -407,6 +407,10 @@ class AppLocalizationsKo extends AppLocalizations { @override String get settings_radioSettingsNotApplied => '라디오가 이 설정을 적용하지 않았습니다'; + @override + String get settings_pathHashModeNotApplied => + 'Radio settings were applied, but the radio did not confirm the new path hash size'; + @override String get settings_regionSettings => '지역'; diff --git a/lib/l10n/app_localizations_nl.dart b/lib/l10n/app_localizations_nl.dart index 082f2a18..edadc900 100644 --- a/lib/l10n/app_localizations_nl.dart +++ b/lib/l10n/app_localizations_nl.dart @@ -423,6 +423,10 @@ class AppLocalizationsNl extends AppLocalizations { String get settings_radioSettingsNotApplied => 'De radio heeft deze instellingen niet toegepast'; + @override + String get settings_pathHashModeNotApplied => + 'Radio settings were applied, but the radio did not confirm the new path hash size'; + @override String get settings_regionSettings => 'Regio\'s'; diff --git a/lib/l10n/app_localizations_pl.dart b/lib/l10n/app_localizations_pl.dart index 3db02722..6662f4e0 100644 --- a/lib/l10n/app_localizations_pl.dart +++ b/lib/l10n/app_localizations_pl.dart @@ -431,6 +431,10 @@ class AppLocalizationsPl extends AppLocalizations { String get settings_radioSettingsNotApplied => 'Radio nie zastosowało tych ustawień'; + @override + String get settings_pathHashModeNotApplied => + 'Radio settings were applied, but the radio did not confirm the new path hash size'; + @override String get settings_regionSettings => 'Regiony'; diff --git a/lib/l10n/app_localizations_pt.dart b/lib/l10n/app_localizations_pt.dart index 9b89ff31..f1943007 100644 --- a/lib/l10n/app_localizations_pt.dart +++ b/lib/l10n/app_localizations_pt.dart @@ -427,6 +427,10 @@ class AppLocalizationsPt extends AppLocalizations { String get settings_radioSettingsNotApplied => 'O rádio não aplicou estas configurações'; + @override + String get settings_pathHashModeNotApplied => + 'Radio settings were applied, but the radio did not confirm the new path hash size'; + @override String get settings_regionSettings => 'Regiões'; diff --git a/lib/l10n/app_localizations_ru.dart b/lib/l10n/app_localizations_ru.dart index a1686804..c1a8ed10 100644 --- a/lib/l10n/app_localizations_ru.dart +++ b/lib/l10n/app_localizations_ru.dart @@ -426,6 +426,10 @@ class AppLocalizationsRu extends AppLocalizations { String get settings_radioSettingsNotApplied => 'Радиомодуль не применил эти настройки'; + @override + String get settings_pathHashModeNotApplied => + 'Radio settings were applied, but the radio did not confirm the new path hash size'; + @override String get settings_regionSettings => 'Регионы'; diff --git a/lib/l10n/app_localizations_sk.dart b/lib/l10n/app_localizations_sk.dart index 9cd7cc6d..a8d0887b 100644 --- a/lib/l10n/app_localizations_sk.dart +++ b/lib/l10n/app_localizations_sk.dart @@ -426,6 +426,10 @@ class AppLocalizationsSk extends AppLocalizations { String get settings_radioSettingsNotApplied => 'Rádio tieto nastavenia neuplatnilo'; + @override + String get settings_pathHashModeNotApplied => + 'Radio settings were applied, but the radio did not confirm the new path hash size'; + @override String get settings_regionSettings => 'Regiony'; diff --git a/lib/l10n/app_localizations_sl.dart b/lib/l10n/app_localizations_sl.dart index 8602eb0d..2fd1903a 100644 --- a/lib/l10n/app_localizations_sl.dart +++ b/lib/l10n/app_localizations_sl.dart @@ -425,6 +425,10 @@ class AppLocalizationsSl extends AppLocalizations { String get settings_radioSettingsNotApplied => 'Radio teh nastavitev ni uveljavil'; + @override + String get settings_pathHashModeNotApplied => + 'Radio settings were applied, but the radio did not confirm the new path hash size'; + @override String get settings_regionSettings => 'Regioni'; diff --git a/lib/l10n/app_localizations_sv.dart b/lib/l10n/app_localizations_sv.dart index 1d87483d..face6140 100644 --- a/lib/l10n/app_localizations_sv.dart +++ b/lib/l10n/app_localizations_sv.dart @@ -423,6 +423,10 @@ class AppLocalizationsSv extends AppLocalizations { String get settings_radioSettingsNotApplied => 'Radion tillämpade inte dessa inställningar'; + @override + String get settings_pathHashModeNotApplied => + 'Radio settings were applied, but the radio did not confirm the new path hash size'; + @override String get settings_regionSettings => 'Regioner'; diff --git a/lib/l10n/app_localizations_uk.dart b/lib/l10n/app_localizations_uk.dart index ebd6d5eb..47888b9e 100644 --- a/lib/l10n/app_localizations_uk.dart +++ b/lib/l10n/app_localizations_uk.dart @@ -425,6 +425,10 @@ class AppLocalizationsUk extends AppLocalizations { String get settings_radioSettingsNotApplied => 'Радіомодуль не застосував ці налаштування'; + @override + String get settings_pathHashModeNotApplied => + 'Radio settings were applied, but the radio did not confirm the new path hash size'; + @override String get settings_regionSettings => 'Ріси'; diff --git a/lib/l10n/app_localizations_zh.dart b/lib/l10n/app_localizations_zh.dart index 703a27fe..1ab063c1 100644 --- a/lib/l10n/app_localizations_zh.dart +++ b/lib/l10n/app_localizations_zh.dart @@ -401,6 +401,10 @@ class AppLocalizationsZh extends AppLocalizations { @override String get settings_radioSettingsNotApplied => '收音机未应用这些设置'; + @override + String get settings_pathHashModeNotApplied => + 'Radio settings were applied, but the radio did not confirm the new path hash size'; + @override String get settings_regionSettings => '地区'; diff --git a/lib/models/radio_settings.dart b/lib/models/radio_settings.dart index 6b3eee84..f7c4709c 100644 --- a/lib/models/radio_settings.dart +++ b/lib/models/radio_settings.dart @@ -50,7 +50,6 @@ class RadioSettings { final LoRaSpreadingFactor spreadingFactor; final LoRaCodingRate codingRate; final int txPowerDbm; - final int pathHashByteWidth; RadioSettings({ required this.frequencyMHz, @@ -58,7 +57,6 @@ class RadioSettings { required this.spreadingFactor, required this.codingRate, required this.txPowerDbm, - this.pathHashByteWidth = 1, // app default; presets override if needed }); // Regional preset configurations diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dart index dff41c0b..74ca3e2c 100644 --- a/lib/screens/settings_screen.dart +++ b/lib/screens/settings_screen.dart @@ -25,9 +25,6 @@ import '../widgets/sync_progress_overlay.dart'; import 'region_management_screen.dart'; import '../utils/share_origin.dart'; -/// Companion firmware version that added CMD_SET_PATH_HASH_MODE (v1.14.0). -const int _minFirmwareVerCodeForPathHashMode = 10; - class SettingsScreen extends StatefulWidget { const SettingsScreen({super.key}); @@ -566,14 +563,10 @@ class _SettingsScreenState extends State { title: l10n.repeater_pathHashMode, subtitle: !connected ? offline - : (connector.firmwareVerCode ?? 0) < - _minFirmwareVerCodeForPathHashMode + : !connector.supportsPathHashMode ? l10n.settings_requiresFirmware('v1.14') : _pathHashModeSubtitle(context, connector.pathHashByteWidth), - onTap: - connector.isConnected && - (connector.firmwareVerCode ?? 0) >= - _minFirmwareVerCodeForPathHashMode + onTap: connector.isConnected && connector.supportsPathHashMode ? () => _editPathHashMode(context, connector) : null, ), diff --git a/lib/widgets/radio_settings_dialog.dart b/lib/widgets/radio_settings_dialog.dart index 7f9834ab..aa00e3d9 100644 --- a/lib/widgets/radio_settings_dialog.dart +++ b/lib/widgets/radio_settings_dialog.dart @@ -30,12 +30,9 @@ bool _isAllowedRepeatFreqKHz(MeshCoreConnector connector, int freqKHz) { /// Lowest TX power companion firmware accepts (CMD_SET_RADIO_TX_POWER). const int _minTxPowerDbm = -9; -/// Companion firmware version that added CMD_SET_PATH_HASH_MODE (v1.14.0). -const int _minFirmwareVerCodeForPathHashMode = 10; - -/// Radio parameter editor (preset, frequency, bandwidth, SF, CR, TX power and -/// off-grid client repeat). Stays open when the radio rejects or fails to -/// apply the settings so the user's edits are not lost. +/// Radio parameter editor (preset, frequency, bandwidth, SF, CR, TX power, +/// path-hash size and off-grid client repeat). Stays open when the radio +/// rejects or fails to apply the settings so the user's edits are not lost. class RadioSettingsDialog extends StatefulWidget { final MeshCoreConnector connector; @@ -58,9 +55,7 @@ class _RadioSettingsDialogState extends State { String? _frequencyError; String? _txPowerError; - bool get _supportsPathHashMode => - (widget.connector.firmwareVerCode ?? 0) >= - _minFirmwareVerCodeForPathHashMode; + bool get _supportsPathHashMode => widget.connector.supportsPathHashMode; AppDebugLogService get _appLog => Provider.of(context, listen: false); @@ -284,7 +279,6 @@ class _RadioSettingsDialogState extends State { _spreadingFactor = preset.spreadingFactor; _codingRate = preset.codingRate; _txPowerController.text = preset.txPowerDbm.toString(); - _pathHashByteWidth = preset.pathHashByteWidth; _selectedPresetIndex = index; _lastNonRepeatSnapshot = baseSnapshot; // Programmatic writes skip TextField.onChanged, so clear any stale @@ -449,15 +443,34 @@ class _RadioSettingsDialogState extends State { return; } await widget.connector.sendFrame(buildSetRadioTxPowerFrame(txPower)); - if (_supportsPathHashMode && - _pathHashByteWidth != widget.connector.pathHashByteWidth) { - await widget.connector.setPathHashMode(_pathHashByteWidth - 1); + // setPathHashMode updates the local width optimistically; the refreshed + // DEVICE_INFO below overwrites it with what the radio actually stored. + final requestedPathHashWidth = + _supportsPathHashMode && + _pathHashByteWidth != widget.connector.pathHashByteWidth + ? _pathHashByteWidth + : null; + if (requestedPathHashWidth != null) { + await widget.connector.setPathHashMode(requestedPathHashWidth - 1); } final selfInfo = widget.connector.receivedFrames .firstWhere((f) => f.isNotEmpty && f[0] == respCodeSelfInfo) .timeout(const Duration(seconds: 5)); + final deviceInfo = requestedPathHashWidth == null + ? null + : widget.connector.receivedFrames + .firstWhere((f) => f.isNotEmpty && f[0] == respCodeDeviceInfo) + .timeout(const Duration(seconds: 5)); await widget.connector.refreshDeviceInfo(); - final applied = await selfInfo.then( + // Without a refreshed DEVICE_INFO the path hash change is unconfirmed + // (this also covers setPathHashMode skipping a disconnected radio). + final pathHashApplied = + deviceInfo == null || + await deviceInfo.then( + (_) => widget.connector.pathHashByteWidth == requestedPathHashWidth, + onError: (_) => false, + ); + final radioApplied = await selfInfo.then( (_) => _deviceMatches( freqHz: freqHz, bwHz: bwHz, @@ -468,7 +481,7 @@ class _RadioSettingsDialogState extends State { ), onError: (_) => true, ); - if (!applied) { + if (!radioApplied) { _logRadioSettingsState('Radio did not apply requested settings'); if (!mounted) return; showDismissibleSnackBar( @@ -477,6 +490,17 @@ class _RadioSettingsDialogState extends State { ); return; } + if (!pathHashApplied) { + // Radio params and TX power were already applied; only the path + // hash size is outstanding, so say that rather than a generic error. + _logRadioSettingsState('Radio did not apply requested path hash size'); + if (!mounted) return; + showDismissibleSnackBar( + context, + content: Text(l10n.settings_pathHashModeNotApplied), + ); + return; + } final rememberedSnapshot = _clientRepeat ? _lastNonRepeatSnapshot : _currentSnapshot(); @@ -553,6 +577,7 @@ class _RadioSettingsDialogState extends State { 'sf=${_spreadingFactor.label} ' 'cr=${_codingRate.label} ' 'tx=${_txPowerController.text}dBm ' + 'pathHash=${_pathHashByteWidth}B ' 'repeat=$_clientRepeat ' 'preset=${_presetLabel(_selectedPresetIndex)} ' 'lastNonRepeat=${_formatSnapshot(_lastNonRepeatSnapshot)}', @@ -688,29 +713,36 @@ class _RadioSettingsDialogState extends State { ), const SizedBox(height: 16), if (_supportsPathHashMode) ...[ + // Values are path hash modes (0-2, byte width - 1), matching + // the selectors in settings_screen and repeater_settings_screen. DropdownButtonFormField( - initialValue: _pathHashByteWidth, + initialValue: (_pathHashByteWidth - 1).clamp(0, 2).toInt(), decoration: InputDecoration( labelText: l10n.repeater_pathHashMode, + helperText: l10n.settings_pathHashModeHelper, + helperMaxLines: 5, border: const OutlineInputBorder(), ), items: [ DropdownMenuItem( - value: 1, + value: 0, child: Text(l10n.repeater_pathHashModeOption0), ), DropdownMenuItem( - value: 2, + value: 1, child: Text(l10n.repeater_pathHashModeOption1), ), DropdownMenuItem( - value: 3, + value: 2, child: Text(l10n.repeater_pathHashModeOption2), ), ], onChanged: (value) { if (value == null) return; - setState(() => _pathHashByteWidth = value); + setState(() => _pathHashByteWidth = value + 1); + _logRadioSettingsState( + 'Manual settings edit: path hash size', + ); }, ), const SizedBox(height: 16), diff --git a/untranslated.json b/untranslated.json index 9e26dfee..648cd980 100644 --- a/untranslated.json +++ b/untranslated.json @@ -1 +1,69 @@ -{} \ No newline at end of file +{ + "bg": [ + "settings_pathHashModeNotApplied" + ], + + "de": [ + "settings_pathHashModeNotApplied" + ], + + "es": [ + "settings_pathHashModeNotApplied" + ], + + "fr": [ + "settings_pathHashModeNotApplied" + ], + + "hu": [ + "settings_pathHashModeNotApplied" + ], + + "it": [ + "settings_pathHashModeNotApplied" + ], + + "ja": [ + "settings_pathHashModeNotApplied" + ], + + "ko": [ + "settings_pathHashModeNotApplied" + ], + + "nl": [ + "settings_pathHashModeNotApplied" + ], + + "pl": [ + "settings_pathHashModeNotApplied" + ], + + "pt": [ + "settings_pathHashModeNotApplied" + ], + + "ru": [ + "settings_pathHashModeNotApplied" + ], + + "sk": [ + "settings_pathHashModeNotApplied" + ], + + "sl": [ + "settings_pathHashModeNotApplied" + ], + + "sv": [ + "settings_pathHashModeNotApplied" + ], + + "uk": [ + "settings_pathHashModeNotApplied" + ], + + "zh": [ + "settings_pathHashModeNotApplied" + ] +} From b6c1d73bf0f8830cdac97db71d22feedf7d0c31a Mon Sep 17 00:00:00 2001 From: zjs81 Date: Sat, 24 Oct 2026 20:45:14 -0700 Subject: [PATCH 5/5] Fix review findings in low battery alerts - Respect the notifications-enabled setting - Notify only the lowest newly crossed threshold - Ignore implausible readings (boards without a battery sensor report 0 mV) - Wait for the device identity so the saved chemistry is used - Require two consecutive low readings before alerting - Re-arm and clear alerts on any link reset, not just explicit disconnect - Cancel stale notifications on re-arm and link reset - Scope notification ids per device and name the device in the body - Use the connector's shared NotificationService --- lib/connector/meshcore_connector.dart | 72 +++++++++++++++++++++++--- lib/l10n/app_en.arb | 7 ++- lib/l10n/app_localizations.dart | 6 +-- lib/l10n/app_localizations_bg.dart | 4 +- lib/l10n/app_localizations_de.dart | 4 +- lib/l10n/app_localizations_en.dart | 4 +- lib/l10n/app_localizations_es.dart | 4 +- lib/l10n/app_localizations_fr.dart | 4 +- lib/l10n/app_localizations_hu.dart | 4 +- lib/l10n/app_localizations_it.dart | 4 +- lib/l10n/app_localizations_ja.dart | 4 +- lib/l10n/app_localizations_ko.dart | 4 +- lib/l10n/app_localizations_nl.dart | 4 +- lib/l10n/app_localizations_pl.dart | 4 +- lib/l10n/app_localizations_pt.dart | 4 +- lib/l10n/app_localizations_ru.dart | 4 +- lib/l10n/app_localizations_sk.dart | 4 +- lib/l10n/app_localizations_sl.dart | 4 +- lib/l10n/app_localizations_sv.dart | 4 +- lib/l10n/app_localizations_uk.dart | 4 +- lib/l10n/app_localizations_zh.dart | 4 +- lib/services/notification_service.dart | 33 ++++++++++-- 22 files changed, 138 insertions(+), 52 deletions(-) diff --git a/lib/connector/meshcore_connector.dart b/lib/connector/meshcore_connector.dart index 4a09067b..fbdd914c 100644 --- a/lib/connector/meshcore_connector.dart +++ b/lib/connector/meshcore_connector.dart @@ -302,6 +302,18 @@ class MeshCoreConnector extends ChangeNotifier { // crossing, re-arming 5 points above the threshold after recharge. static const List _lowBatteryThresholds = [25, 10]; final Set _batteryAlertedThresholds = {}; + // Consecutive readings that newly crossed a threshold. Alerts need + // [_lowBatteryConfirmReadings] in a row so a single TX-load voltage sag + // doesn't notify. + int _lowBatteryReadingStreak = 0; + // Device key the posted low-battery notifications were scoped to, kept so + // they can still be cancelled after the session's identity is cleared. + String? _lowBatteryAlertDeviceKey; + static const int _lowBatteryConfirmReadings = 2; + // Readings below this are treated as "no battery sensor" (boards without + // one report 0 mV). Any single Li cell, including LiFePO4 (2600 mV empty), + // is protection-cut well above 2 V, so lower values are not real readings. + static const int _minPlausibleBatteryMillivolts = 2000; double? _selfLatitude; double? _selfLongitude; final List _directRepeaters = List.empty(growable: true); @@ -3722,7 +3734,6 @@ class MeshCoreConnector extends ChangeNotifier { _allowedRepeatFreqRanges = null; _autoAddMaxHops = null; _contactsStorageFull = false; - _batteryAlertedThresholds.clear(); _repeaterBatterySnapshots.clear(); _activeTransport = MeshCoreTransportType.bluetooth; @@ -6492,24 +6503,61 @@ class MeshCoreConnector extends ChangeNotifier { } void _checkLowBatteryThresholds() { + final millivolts = _batteryMillivolts; + if (millivolts == null || millivolts < _minPlausibleBatteryMillivolts) { + return; + } + // Until the device identity (and so its saved chemistry) is known, the + // percentage falls back to NMC and can read low for e.g. LiFePO4 packs. + // Skip evaluation; the next battery poll re-checks once identity is set. + if (batteryDeviceKey == null || _appSettingsService == null) return; final percent = batteryPercent; if (percent == null) return; + // Only the lowest newly crossed threshold notifies; higher ones crossed + // in the same reading are marked as alerted silently. + final newlyCrossed = []; for (final threshold in _lowBatteryThresholds) { if (percent <= threshold && !_batteryAlertedThresholds.contains(threshold)) { - _batteryAlertedThresholds.add(threshold); - NotificationService().showLowBatteryNotification( - batteryPercent: percent, - threshold: threshold, - ); + newlyCrossed.add(threshold); } else if (percent > threshold + 5 && _batteryAlertedThresholds.contains(threshold)) { // Re-arm once the battery recovers 5 points above the threshold, // so a recharge + discharge cycle alerts again without flapping. _batteryAlertedThresholds.remove(threshold); + final alertDeviceKey = _lowBatteryAlertDeviceKey; + if (alertDeviceKey != null) { + unawaited( + _notificationService.clearLowBatteryNotifications(alertDeviceKey, [ + threshold, + ]), + ); + } } } + if (newlyCrossed.isEmpty) { + _lowBatteryReadingStreak = 0; + return; + } + // Debounce: wait for consecutive low readings before alerting. + if (++_lowBatteryReadingStreak < _lowBatteryConfirmReadings) return; + _lowBatteryReadingStreak = 0; + _batteryAlertedThresholds.addAll(newlyCrossed); + final deviceKey = batteryDeviceKey!; + _lowBatteryAlertDeviceKey = deviceKey; + final lowestNewlyCrossed = newlyCrossed.reduce((a, b) => a < b ? a : b); + if (!(_appSettingsService?.settings.notificationsEnabled ?? false)) { + return; + } + unawaited( + _notificationService.showLowBatteryNotification( + deviceKey: deviceKey, + deviceName: deviceDisplayName, + batteryPercent: percent, + threshold: lowestNewlyCrossed, + ), + ); } void _checkManualAddContacts() async { @@ -8595,6 +8643,18 @@ class MeshCoreConnector extends ChangeNotifier { _hasReceivedDeviceInfo = false; _batteryMillivolts = null; _batteryRequested = false; + final alertDeviceKey = _lowBatteryAlertDeviceKey; + if (alertDeviceKey != null && _batteryAlertedThresholds.isNotEmpty) { + unawaited( + _notificationService.clearLowBatteryNotifications( + alertDeviceKey, + _batteryAlertedThresholds.toList(), + ), + ); + } + _batteryAlertedThresholds.clear(); + _lowBatteryAlertDeviceKey = null; + _lowBatteryReadingStreak = 0; _pathHashByteWidth = 1; _maxContacts = _defaultMaxContacts; _maxChannels = _defaultMaxChannels; diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 96ee02c8..8e949cab 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -2682,10 +2682,13 @@ "@notification_lowBatteryTitle": { "description": "Title of the low battery notification" }, - "notification_lowBatteryBody": "Device battery is at {percent}%", + "notification_lowBatteryBody": "{deviceName} battery is at {percent}%", "@notification_lowBatteryBody": { - "description": "Body of the low battery notification", + "description": "Body of the low battery notification; deviceName is the connected radio's node name", "placeholders": { + "deviceName": { + "type": "String" + }, "percent": { "type": "int" } diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dart index cfcb4347..58630f96 100644 --- a/lib/l10n/app_localizations.dart +++ b/lib/l10n/app_localizations.dart @@ -8114,11 +8114,11 @@ abstract class AppLocalizations { /// **'Low battery'** String get notification_lowBatteryTitle; - /// Body of the low battery notification + /// Body of the low battery notification; deviceName is the connected radio's node name /// /// In en, this message translates to: - /// **'Device battery is at {percent}%'** - String notification_lowBatteryBody(int percent); + /// **'{deviceName} battery is at {percent}%'** + String notification_lowBatteryBody(String deviceName, int percent); /// No description provided for @notification_messagesCount. /// diff --git a/lib/l10n/app_localizations_bg.dart b/lib/l10n/app_localizations_bg.dart index b0f3efc8..d8bec52f 100644 --- a/lib/l10n/app_localizations_bg.dart +++ b/lib/l10n/app_localizations_bg.dart @@ -4731,8 +4731,8 @@ class AppLocalizationsBg extends AppLocalizations { String get notification_lowBatteryTitle => 'Low battery'; @override - String notification_lowBatteryBody(int percent) { - return 'Device battery is at $percent%'; + String notification_lowBatteryBody(String deviceName, int percent) { + return '$deviceName battery is at $percent%'; } @override diff --git a/lib/l10n/app_localizations_de.dart b/lib/l10n/app_localizations_de.dart index fa451134..a03829e6 100644 --- a/lib/l10n/app_localizations_de.dart +++ b/lib/l10n/app_localizations_de.dart @@ -4742,8 +4742,8 @@ class AppLocalizationsDe extends AppLocalizations { String get notification_lowBatteryTitle => 'Low battery'; @override - String notification_lowBatteryBody(int percent) { - return 'Device battery is at $percent%'; + String notification_lowBatteryBody(String deviceName, int percent) { + return '$deviceName battery is at $percent%'; } @override diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dart index 61785365..8a4cea69 100644 --- a/lib/l10n/app_localizations_en.dart +++ b/lib/l10n/app_localizations_en.dart @@ -4666,8 +4666,8 @@ class AppLocalizationsEn extends AppLocalizations { String get notification_lowBatteryTitle => 'Low battery'; @override - String notification_lowBatteryBody(int percent) { - return 'Device battery is at $percent%'; + String notification_lowBatteryBody(String deviceName, int percent) { + return '$deviceName battery is at $percent%'; } @override diff --git a/lib/l10n/app_localizations_es.dart b/lib/l10n/app_localizations_es.dart index 11483e01..dc0b28be 100644 --- a/lib/l10n/app_localizations_es.dart +++ b/lib/l10n/app_localizations_es.dart @@ -4733,8 +4733,8 @@ class AppLocalizationsEs extends AppLocalizations { String get notification_lowBatteryTitle => 'Low battery'; @override - String notification_lowBatteryBody(int percent) { - return 'Device battery is at $percent%'; + String notification_lowBatteryBody(String deviceName, int percent) { + return '$deviceName battery is at $percent%'; } @override diff --git a/lib/l10n/app_localizations_fr.dart b/lib/l10n/app_localizations_fr.dart index 4430c9b1..f55984f5 100644 --- a/lib/l10n/app_localizations_fr.dart +++ b/lib/l10n/app_localizations_fr.dart @@ -4752,8 +4752,8 @@ class AppLocalizationsFr extends AppLocalizations { String get notification_lowBatteryTitle => 'Low battery'; @override - String notification_lowBatteryBody(int percent) { - return 'Device battery is at $percent%'; + String notification_lowBatteryBody(String deviceName, int percent) { + return '$deviceName battery is at $percent%'; } @override diff --git a/lib/l10n/app_localizations_hu.dart b/lib/l10n/app_localizations_hu.dart index 0da9db3e..e35c1981 100644 --- a/lib/l10n/app_localizations_hu.dart +++ b/lib/l10n/app_localizations_hu.dart @@ -4730,8 +4730,8 @@ class AppLocalizationsHu extends AppLocalizations { String get notification_lowBatteryTitle => 'Low battery'; @override - String notification_lowBatteryBody(int percent) { - return 'Device battery is at $percent%'; + String notification_lowBatteryBody(String deviceName, int percent) { + return '$deviceName battery is at $percent%'; } @override diff --git a/lib/l10n/app_localizations_it.dart b/lib/l10n/app_localizations_it.dart index 11c3a4df..c4a97a49 100644 --- a/lib/l10n/app_localizations_it.dart +++ b/lib/l10n/app_localizations_it.dart @@ -4739,8 +4739,8 @@ class AppLocalizationsIt extends AppLocalizations { String get notification_lowBatteryTitle => 'Low battery'; @override - String notification_lowBatteryBody(int percent) { - return 'Device battery is at $percent%'; + String notification_lowBatteryBody(String deviceName, int percent) { + return '$deviceName battery is at $percent%'; } @override diff --git a/lib/l10n/app_localizations_ja.dart b/lib/l10n/app_localizations_ja.dart index e409ad80..8066f4ec 100644 --- a/lib/l10n/app_localizations_ja.dart +++ b/lib/l10n/app_localizations_ja.dart @@ -4502,8 +4502,8 @@ class AppLocalizationsJa extends AppLocalizations { String get notification_lowBatteryTitle => 'Low battery'; @override - String notification_lowBatteryBody(int percent) { - return 'Device battery is at $percent%'; + String notification_lowBatteryBody(String deviceName, int percent) { + return '$deviceName battery is at $percent%'; } @override diff --git a/lib/l10n/app_localizations_ko.dart b/lib/l10n/app_localizations_ko.dart index 82667ffe..db66d010 100644 --- a/lib/l10n/app_localizations_ko.dart +++ b/lib/l10n/app_localizations_ko.dart @@ -4513,8 +4513,8 @@ class AppLocalizationsKo extends AppLocalizations { String get notification_lowBatteryTitle => 'Low battery'; @override - String notification_lowBatteryBody(int percent) { - return 'Device battery is at $percent%'; + String notification_lowBatteryBody(String deviceName, int percent) { + return '$deviceName battery is at $percent%'; } @override diff --git a/lib/l10n/app_localizations_nl.dart b/lib/l10n/app_localizations_nl.dart index c31460d2..470c6646 100644 --- a/lib/l10n/app_localizations_nl.dart +++ b/lib/l10n/app_localizations_nl.dart @@ -4708,8 +4708,8 @@ class AppLocalizationsNl extends AppLocalizations { String get notification_lowBatteryTitle => 'Low battery'; @override - String notification_lowBatteryBody(int percent) { - return 'Device battery is at $percent%'; + String notification_lowBatteryBody(String deviceName, int percent) { + return '$deviceName battery is at $percent%'; } @override diff --git a/lib/l10n/app_localizations_pl.dart b/lib/l10n/app_localizations_pl.dart index 27ef631c..96f15d50 100644 --- a/lib/l10n/app_localizations_pl.dart +++ b/lib/l10n/app_localizations_pl.dart @@ -4759,8 +4759,8 @@ class AppLocalizationsPl extends AppLocalizations { String get notification_lowBatteryTitle => 'Low battery'; @override - String notification_lowBatteryBody(int percent) { - return 'Device battery is at $percent%'; + String notification_lowBatteryBody(String deviceName, int percent) { + return '$deviceName battery is at $percent%'; } @override diff --git a/lib/l10n/app_localizations_pt.dart b/lib/l10n/app_localizations_pt.dart index f51d5bb3..9358590b 100644 --- a/lib/l10n/app_localizations_pt.dart +++ b/lib/l10n/app_localizations_pt.dart @@ -4735,8 +4735,8 @@ class AppLocalizationsPt extends AppLocalizations { String get notification_lowBatteryTitle => 'Low battery'; @override - String notification_lowBatteryBody(int percent) { - return 'Device battery is at $percent%'; + String notification_lowBatteryBody(String deviceName, int percent) { + return '$deviceName battery is at $percent%'; } @override diff --git a/lib/l10n/app_localizations_ru.dart b/lib/l10n/app_localizations_ru.dart index b1e9018c..f808604f 100644 --- a/lib/l10n/app_localizations_ru.dart +++ b/lib/l10n/app_localizations_ru.dart @@ -4743,8 +4743,8 @@ class AppLocalizationsRu extends AppLocalizations { String get notification_lowBatteryTitle => 'Low battery'; @override - String notification_lowBatteryBody(int percent) { - return 'Device battery is at $percent%'; + String notification_lowBatteryBody(String deviceName, int percent) { + return '$deviceName battery is at $percent%'; } @override diff --git a/lib/l10n/app_localizations_sk.dart b/lib/l10n/app_localizations_sk.dart index 00202f9c..12977b44 100644 --- a/lib/l10n/app_localizations_sk.dart +++ b/lib/l10n/app_localizations_sk.dart @@ -4716,8 +4716,8 @@ class AppLocalizationsSk extends AppLocalizations { String get notification_lowBatteryTitle => 'Low battery'; @override - String notification_lowBatteryBody(int percent) { - return 'Device battery is at $percent%'; + String notification_lowBatteryBody(String deviceName, int percent) { + return '$deviceName battery is at $percent%'; } @override diff --git a/lib/l10n/app_localizations_sl.dart b/lib/l10n/app_localizations_sl.dart index 8956df64..9b629d4a 100644 --- a/lib/l10n/app_localizations_sl.dart +++ b/lib/l10n/app_localizations_sl.dart @@ -4714,8 +4714,8 @@ class AppLocalizationsSl extends AppLocalizations { String get notification_lowBatteryTitle => 'Low battery'; @override - String notification_lowBatteryBody(int percent) { - return 'Device battery is at $percent%'; + String notification_lowBatteryBody(String deviceName, int percent) { + return '$deviceName battery is at $percent%'; } @override diff --git a/lib/l10n/app_localizations_sv.dart b/lib/l10n/app_localizations_sv.dart index 4f8d8f1f..129ddf72 100644 --- a/lib/l10n/app_localizations_sv.dart +++ b/lib/l10n/app_localizations_sv.dart @@ -4690,8 +4690,8 @@ class AppLocalizationsSv extends AppLocalizations { String get notification_lowBatteryTitle => 'Low battery'; @override - String notification_lowBatteryBody(int percent) { - return 'Device battery is at $percent%'; + String notification_lowBatteryBody(String deviceName, int percent) { + return '$deviceName battery is at $percent%'; } @override diff --git a/lib/l10n/app_localizations_uk.dart b/lib/l10n/app_localizations_uk.dart index 84d0c651..1d425252 100644 --- a/lib/l10n/app_localizations_uk.dart +++ b/lib/l10n/app_localizations_uk.dart @@ -4742,8 +4742,8 @@ class AppLocalizationsUk extends AppLocalizations { String get notification_lowBatteryTitle => 'Low battery'; @override - String notification_lowBatteryBody(int percent) { - return 'Device battery is at $percent%'; + String notification_lowBatteryBody(String deviceName, int percent) { + return '$deviceName battery is at $percent%'; } @override diff --git a/lib/l10n/app_localizations_zh.dart b/lib/l10n/app_localizations_zh.dart index d0eb24b2..fa67ef7d 100644 --- a/lib/l10n/app_localizations_zh.dart +++ b/lib/l10n/app_localizations_zh.dart @@ -4410,8 +4410,8 @@ class AppLocalizationsZh extends AppLocalizations { String get notification_lowBatteryTitle => 'Low battery'; @override - String notification_lowBatteryBody(int percent) { - return 'Device battery is at $percent%'; + String notification_lowBatteryBody(String deviceName, int percent) { + return '$deviceName battery is at $percent%'; } @override diff --git a/lib/services/notification_service.dart b/lib/services/notification_service.dart index 62802917..334240c6 100644 --- a/lib/services/notification_service.dart +++ b/lib/services/notification_service.dart @@ -600,10 +600,13 @@ class NotificationService { /// Posts a low-battery alert for the connected device. /// - /// Uses a per-threshold notification id so each alert level updates its own - /// notification instead of stacking. Bypasses the rate-limit queue, which - /// only handles message and advert notifications. + /// Uses a per-device, per-threshold notification id so each alert level + /// updates its own notification instead of stacking, and alerts for + /// different radios don't overwrite each other. Bypasses the rate-limit + /// queue, which only handles message and advert notifications. Future showLowBatteryNotification({ + required String deviceKey, + required String deviceName, required int batteryPercent, required int threshold, }) async { @@ -632,9 +635,9 @@ class NotificationService { try { await _notifications.show( - id: 'low_battery:$threshold'.hashCode, + id: _lowBatteryNotificationId(deviceKey, threshold), title: _l10n.notification_lowBatteryTitle, - body: _l10n.notification_lowBatteryBody(batteryPercent), + body: _l10n.notification_lowBatteryBody(deviceName, batteryPercent), notificationDetails: notificationDetails, payload: 'low_battery', ); @@ -699,6 +702,26 @@ class NotificationService { await _updateBadge(totalUnreadCount); } + static int _lowBatteryNotificationId(String deviceKey, int threshold) => + 'low_battery:$deviceKey:$threshold'.hashCode; + + /// Cancel a device's low-battery notifications for the given thresholds. + Future clearLowBatteryNotifications( + String deviceKey, + Iterable thresholds, + ) async { + if (!await _ensureInitialized()) return; + for (final threshold in thresholds) { + try { + await _notifications.cancel( + id: _lowBatteryNotificationId(deviceKey, threshold), + ); + } catch (e) { + debugPrint('Failed to clear low battery notification: $e'); + } + } + } + /// Cancel advert notifications for the given contact public key hexes. Future clearAdvertNotifications(List contactIds) async { if (!await _ensureInitialized()) return;