From ef53b8f390f0b72f070c6734e85159414b8b3c60 Mon Sep 17 00:00:00 2001 From: zjs81 Date: Wed, 7 Oct 2026 21:12:59 -0700 Subject: [PATCH] Default discovered-contact eviction on and harden the auto-add dialog - Default evictDiscoveredContactsEnabled to true so the 500-entry cap stays in effect unless the user opts out - Evict until under the cap when adding, so an oversized list recovers - Pass the cap into the localized subtitle instead of hard-coding 500 - Fix German title and subtitle wording - Save: block double taps, send radio config first, show an error if persisting the setting fails - Restore untranslated.json to match dev --- lib/connector/meshcore_connector.dart | 23 ++-- lib/l10n/app_de.arb | 11 +- lib/l10n/app_en.arb | 9 +- lib/l10n/app_localizations.dart | 4 +- lib/l10n/app_localizations_bg.dart | 5 +- lib/l10n/app_localizations_de.dart | 7 +- lib/l10n/app_localizations_en.dart | 5 +- lib/l10n/app_localizations_es.dart | 5 +- lib/l10n/app_localizations_fr.dart | 5 +- lib/l10n/app_localizations_hu.dart | 5 +- lib/l10n/app_localizations_it.dart | 5 +- lib/l10n/app_localizations_ja.dart | 5 +- lib/l10n/app_localizations_ko.dart | 5 +- lib/l10n/app_localizations_nl.dart | 5 +- lib/l10n/app_localizations_pl.dart | 5 +- lib/l10n/app_localizations_pt.dart | 5 +- lib/l10n/app_localizations_ru.dart | 5 +- lib/l10n/app_localizations_sk.dart | 5 +- lib/l10n/app_localizations_sl.dart | 5 +- lib/l10n/app_localizations_sv.dart | 5 +- lib/l10n/app_localizations_uk.dart | 5 +- lib/l10n/app_localizations_zh.dart | 5 +- lib/models/app_settings.dart | 4 +- lib/screens/settings_screen.dart | 57 ++++++---- test/models/model_changes_test.dart | 4 +- untranslated.json | 149 +------------------------- 26 files changed, 130 insertions(+), 223 deletions(-) diff --git a/lib/connector/meshcore_connector.dart b/lib/connector/meshcore_connector.dart index 123016eb..d5eb2282 100644 --- a/lib/connector/meshcore_connector.dart +++ b/lib/connector/meshcore_connector.dart @@ -180,7 +180,7 @@ class MeshCoreConnector extends ChangeNotifier { // continuously from the whole mesh, so without a bound this list grows for // as long as the app stays connected. When full, the stalest node (oldest // lastSeen) is evicted to make room for a newly heard one. - static const int _maxDiscoveredContacts = 500; + static const int maxDiscoveredContacts = 500; MeshCoreConnectionState _state = MeshCoreConnectionState.disconnected; BluetoothDevice? _device; @@ -1356,9 +1356,10 @@ class MeshCoreConnector extends ChangeNotifier { Future _loadDiscoveredContactCache() async { final cached = await _discoveryContactStore.loadContacts(); - // Trim a previously-saved oversized list down to the freshest entries so a - // device that grew unbounded before the cap existed recovers on load. - if (_appSettingsService?.settings.evictDiscoveredContactsEnabled == true && + // When eviction is enabled, trim a previously-saved oversized list down to + // the freshest entries so a device that grew unbounded before the cap + // existed recovers on load. + if (_evictDiscoveredContactsEnabled && _trimDiscoveredContactsToLimit(cached)) { unawaited(_discoveryContactStore.saveContacts(cached)); } @@ -1367,10 +1368,13 @@ class MeshCoreConnector extends ChangeNotifier { ..addAll(cached); } + bool get _evictDiscoveredContactsEnabled => + _appSettingsService?.settings.evictDiscoveredContactsEnabled ?? true; + bool _trimDiscoveredContactsToLimit(List contacts) { - if (contacts.length <= _maxDiscoveredContacts) return false; + if (contacts.length <= maxDiscoveredContacts) return false; contacts.sort((a, b) => b.lastSeen.compareTo(a.lastSeen)); - contacts.removeRange(_maxDiscoveredContacts, contacts.length); + contacts.removeRange(maxDiscoveredContacts, contacts.length); return true; } @@ -8194,9 +8198,10 @@ class MeshCoreConnector extends ChangeNotifier { flags: 0, ); - if (_appSettingsService?.settings.evictDiscoveredContactsEnabled == true && - _discoveredContacts.length >= _maxDiscoveredContacts) { - _evictStalestDiscoveredContact(); + if (_evictDiscoveredContactsEnabled) { + while (_discoveredContacts.length >= maxDiscoveredContacts) { + _evictStalestDiscoveredContact(); + } } _discoveredContacts.add(disContact); diff --git a/lib/l10n/app_de.arb b/lib/l10n/app_de.arb index 733c35cc..ff4527fc 100644 --- a/lib/l10n/app_de.arb +++ b/lib/l10n/app_de.arb @@ -2145,8 +2145,15 @@ "discoveredContacts_copyContact": "Kontakt in die Zwischenablage kopieren", "contactsSettings_overwriteOldestTitle": "Überschreiben des Ältesten", "contactsSettings_overwriteOldestSubtitle": "Wenn die Kontaktliste voll ist, wird der älteste nicht favorisierte Kontakt ersetzt.", - "contactsSettings_evictDiscoveredContactsTitle": "Kürze entdeckte Kontakte Liste", - "contactsSettings_evictDiscoveredContactsSubtitle": "Wenn aktiviert, wird die Liste der entdeckten Kontackte auf 500 Kontakten begrenzt.", + "contactsSettings_evictDiscoveredContactsTitle": "Liste entdeckter Kontakte kürzen", + "contactsSettings_evictDiscoveredContactsSubtitle": "Wenn aktiviert, wird die Liste der entdeckten Kontakte auf {limit} Kontakte begrenzt.", + "@contactsSettings_evictDiscoveredContactsSubtitle": { + "placeholders": { + "limit": { + "type": "int" + } + } + }, "common_deleteAll": "Alles löschen", "discoveredContacts_deleteContactAllContent": "Sind Sie sicher, dass Sie alle gefundenen Kontakte löschen möchten?", "discoveredContacts_deleteContactAll": "Alle entdeckten Kontakte löschen", diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index ace29877..06ae5d01 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -2649,7 +2649,14 @@ "contactsSettings_overwriteOldestTitle": "Overwrite Oldest", "contactsSettings_overwriteOldestSubtitle": "When the contact list is full, the oldest non-favorited contact will be replaced.", "contactsSettings_evictDiscoveredContactsTitle": "Evict discovered contacts", - "contactsSettings_evictDiscoveredContactsSubtitle": "When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of 500 entries.", + "contactsSettings_evictDiscoveredContactsSubtitle": "When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of {limit} entries.", + "@contactsSettings_evictDiscoveredContactsSubtitle": { + "placeholders": { + "limit": { + "type": "int" + } + } + }, "discoveredContacts_Title": "Discovered Contacts", "discoveredContacts_noMatching": "No matching contacts", "discoveredContacts_searchHint": "Search discovered contacts", diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dart index 81a34f45..a1ccd08c 100644 --- a/lib/l10n/app_localizations.dart +++ b/lib/l10n/app_localizations.dart @@ -8215,8 +8215,8 @@ abstract class AppLocalizations { /// No description provided for @contactsSettings_evictDiscoveredContactsSubtitle. /// /// In en, this message translates to: - /// **'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of 500 entries.'** - String get contactsSettings_evictDiscoveredContactsSubtitle; + /// **'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of {limit} entries.'** + String contactsSettings_evictDiscoveredContactsSubtitle(int limit); /// No description provided for @discoveredContacts_Title. /// diff --git a/lib/l10n/app_localizations_bg.dart b/lib/l10n/app_localizations_bg.dart index a12ec148..1bd49aad 100644 --- a/lib/l10n/app_localizations_bg.dart +++ b/lib/l10n/app_localizations_bg.dart @@ -4794,8 +4794,9 @@ class AppLocalizationsBg extends AppLocalizations { 'Evict discovered contacts'; @override - String get contactsSettings_evictDiscoveredContactsSubtitle => - 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of 500 entries.'; + String contactsSettings_evictDiscoveredContactsSubtitle(int limit) { + return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.'; + } @override String get discoveredContacts_Title => 'Открити контакти'; diff --git a/lib/l10n/app_localizations_de.dart b/lib/l10n/app_localizations_de.dart index bd0c4afc..1fd2b632 100644 --- a/lib/l10n/app_localizations_de.dart +++ b/lib/l10n/app_localizations_de.dart @@ -4803,11 +4803,12 @@ class AppLocalizationsDe extends AppLocalizations { @override String get contactsSettings_evictDiscoveredContactsTitle => - 'Kürze entdeckte Kontakte Liste'; + 'Liste entdeckter Kontakte kürzen'; @override - String get contactsSettings_evictDiscoveredContactsSubtitle => - 'Wenn aktiviert, wird die Liste der entdeckten Kontackte auf 500 Kontakten begrenzt.'; + String contactsSettings_evictDiscoveredContactsSubtitle(int limit) { + return 'Wenn aktiviert, wird die Liste der entdeckten Kontakte auf $limit Kontakte begrenzt.'; + } @override String get discoveredContacts_Title => 'Entdeckte Kontakte'; diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dart index b297ecfc..4af5d2f0 100644 --- a/lib/l10n/app_localizations_en.dart +++ b/lib/l10n/app_localizations_en.dart @@ -4725,8 +4725,9 @@ class AppLocalizationsEn extends AppLocalizations { 'Evict discovered contacts'; @override - String get contactsSettings_evictDiscoveredContactsSubtitle => - 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of 500 entries.'; + String contactsSettings_evictDiscoveredContactsSubtitle(int limit) { + return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.'; + } @override String get discoveredContacts_Title => 'Discovered Contacts'; diff --git a/lib/l10n/app_localizations_es.dart b/lib/l10n/app_localizations_es.dart index 01605a9a..2c35a02b 100644 --- a/lib/l10n/app_localizations_es.dart +++ b/lib/l10n/app_localizations_es.dart @@ -4797,8 +4797,9 @@ class AppLocalizationsEs extends AppLocalizations { 'Evict discovered contacts'; @override - String get contactsSettings_evictDiscoveredContactsSubtitle => - 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of 500 entries.'; + String contactsSettings_evictDiscoveredContactsSubtitle(int limit) { + return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.'; + } @override String get discoveredContacts_Title => 'Contactos descubiertos'; diff --git a/lib/l10n/app_localizations_fr.dart b/lib/l10n/app_localizations_fr.dart index be24acc8..76e862d4 100644 --- a/lib/l10n/app_localizations_fr.dart +++ b/lib/l10n/app_localizations_fr.dart @@ -4819,8 +4819,9 @@ class AppLocalizationsFr extends AppLocalizations { 'Evict discovered contacts'; @override - String get contactsSettings_evictDiscoveredContactsSubtitle => - 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of 500 entries.'; + String contactsSettings_evictDiscoveredContactsSubtitle(int limit) { + return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.'; + } @override String get discoveredContacts_Title => 'Contacts découverts'; diff --git a/lib/l10n/app_localizations_hu.dart b/lib/l10n/app_localizations_hu.dart index 25de36d7..44b737a2 100644 --- a/lib/l10n/app_localizations_hu.dart +++ b/lib/l10n/app_localizations_hu.dart @@ -4793,8 +4793,9 @@ class AppLocalizationsHu extends AppLocalizations { 'Evict discovered contacts'; @override - String get contactsSettings_evictDiscoveredContactsSubtitle => - 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of 500 entries.'; + String contactsSettings_evictDiscoveredContactsSubtitle(int limit) { + return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.'; + } @override String get discoveredContacts_Title => 'Felfedezett kapcsolatok'; diff --git a/lib/l10n/app_localizations_it.dart b/lib/l10n/app_localizations_it.dart index 3c681e76..d48917c7 100644 --- a/lib/l10n/app_localizations_it.dart +++ b/lib/l10n/app_localizations_it.dart @@ -4803,8 +4803,9 @@ class AppLocalizationsIt extends AppLocalizations { 'Evict discovered contacts'; @override - String get contactsSettings_evictDiscoveredContactsSubtitle => - 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of 500 entries.'; + String contactsSettings_evictDiscoveredContactsSubtitle(int limit) { + return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.'; + } @override String get discoveredContacts_Title => 'Contatti scoperti'; diff --git a/lib/l10n/app_localizations_ja.dart b/lib/l10n/app_localizations_ja.dart index 49bad245..872deafe 100644 --- a/lib/l10n/app_localizations_ja.dart +++ b/lib/l10n/app_localizations_ja.dart @@ -4559,8 +4559,9 @@ class AppLocalizationsJa extends AppLocalizations { 'Evict discovered contacts'; @override - String get contactsSettings_evictDiscoveredContactsSubtitle => - 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of 500 entries.'; + String contactsSettings_evictDiscoveredContactsSubtitle(int limit) { + return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.'; + } @override String get discoveredContacts_Title => '連絡先が見つかった'; diff --git a/lib/l10n/app_localizations_ko.dart b/lib/l10n/app_localizations_ko.dart index 25ae2f8c..18fa4cd9 100644 --- a/lib/l10n/app_localizations_ko.dart +++ b/lib/l10n/app_localizations_ko.dart @@ -4569,8 +4569,9 @@ class AppLocalizationsKo extends AppLocalizations { 'Evict discovered contacts'; @override - String get contactsSettings_evictDiscoveredContactsSubtitle => - 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of 500 entries.'; + String contactsSettings_evictDiscoveredContactsSubtitle(int limit) { + return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.'; + } @override String get discoveredContacts_Title => '연락처 찾기'; diff --git a/lib/l10n/app_localizations_nl.dart b/lib/l10n/app_localizations_nl.dart index 0f258b4b..f5959632 100644 --- a/lib/l10n/app_localizations_nl.dart +++ b/lib/l10n/app_localizations_nl.dart @@ -4771,8 +4771,9 @@ class AppLocalizationsNl extends AppLocalizations { 'Evict discovered contacts'; @override - String get contactsSettings_evictDiscoveredContactsSubtitle => - 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of 500 entries.'; + String contactsSettings_evictDiscoveredContactsSubtitle(int limit) { + return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.'; + } @override String get discoveredContacts_Title => 'Ontdekte contacten'; diff --git a/lib/l10n/app_localizations_pl.dart b/lib/l10n/app_localizations_pl.dart index d330c3ce..fab6a476 100644 --- a/lib/l10n/app_localizations_pl.dart +++ b/lib/l10n/app_localizations_pl.dart @@ -4826,8 +4826,9 @@ class AppLocalizationsPl extends AppLocalizations { 'Evict discovered contacts'; @override - String get contactsSettings_evictDiscoveredContactsSubtitle => - 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of 500 entries.'; + String contactsSettings_evictDiscoveredContactsSubtitle(int limit) { + return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.'; + } @override String get discoveredContacts_Title => 'Odkryte Kontakty'; diff --git a/lib/l10n/app_localizations_pt.dart b/lib/l10n/app_localizations_pt.dart index 6f80b835..da2d61b0 100644 --- a/lib/l10n/app_localizations_pt.dart +++ b/lib/l10n/app_localizations_pt.dart @@ -4798,8 +4798,9 @@ class AppLocalizationsPt extends AppLocalizations { 'Evict discovered contacts'; @override - String get contactsSettings_evictDiscoveredContactsSubtitle => - 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of 500 entries.'; + String contactsSettings_evictDiscoveredContactsSubtitle(int limit) { + return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.'; + } @override String get discoveredContacts_Title => 'Contatos Descobertos'; diff --git a/lib/l10n/app_localizations_ru.dart b/lib/l10n/app_localizations_ru.dart index 3f4060c3..d63112b2 100644 --- a/lib/l10n/app_localizations_ru.dart +++ b/lib/l10n/app_localizations_ru.dart @@ -4810,8 +4810,9 @@ class AppLocalizationsRu extends AppLocalizations { 'Evict discovered contacts'; @override - String get contactsSettings_evictDiscoveredContactsSubtitle => - 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of 500 entries.'; + String contactsSettings_evictDiscoveredContactsSubtitle(int limit) { + return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.'; + } @override String get discoveredContacts_Title => 'Обнаруженные контакты'; diff --git a/lib/l10n/app_localizations_sk.dart b/lib/l10n/app_localizations_sk.dart index ec95f35f..f939911e 100644 --- a/lib/l10n/app_localizations_sk.dart +++ b/lib/l10n/app_localizations_sk.dart @@ -4780,8 +4780,9 @@ class AppLocalizationsSk extends AppLocalizations { 'Evict discovered contacts'; @override - String get contactsSettings_evictDiscoveredContactsSubtitle => - 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of 500 entries.'; + String contactsSettings_evictDiscoveredContactsSubtitle(int limit) { + return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.'; + } @override String get discoveredContacts_Title => 'Objavené kontakty'; diff --git a/lib/l10n/app_localizations_sl.dart b/lib/l10n/app_localizations_sl.dart index 31a4da7d..77349499 100644 --- a/lib/l10n/app_localizations_sl.dart +++ b/lib/l10n/app_localizations_sl.dart @@ -4780,8 +4780,9 @@ class AppLocalizationsSl extends AppLocalizations { 'Evict discovered contacts'; @override - String get contactsSettings_evictDiscoveredContactsSubtitle => - 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of 500 entries.'; + String contactsSettings_evictDiscoveredContactsSubtitle(int limit) { + return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.'; + } @override String get discoveredContacts_Title => 'Odkriti stiki'; diff --git a/lib/l10n/app_localizations_sv.dart b/lib/l10n/app_localizations_sv.dart index ef46c8f1..eaacb8f3 100644 --- a/lib/l10n/app_localizations_sv.dart +++ b/lib/l10n/app_localizations_sv.dart @@ -4755,8 +4755,9 @@ class AppLocalizationsSv extends AppLocalizations { 'Evict discovered contacts'; @override - String get contactsSettings_evictDiscoveredContactsSubtitle => - 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of 500 entries.'; + String contactsSettings_evictDiscoveredContactsSubtitle(int limit) { + return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.'; + } @override String get discoveredContacts_Title => 'Upptäckta kontakter'; diff --git a/lib/l10n/app_localizations_uk.dart b/lib/l10n/app_localizations_uk.dart index dcf31ac6..6bbb580b 100644 --- a/lib/l10n/app_localizations_uk.dart +++ b/lib/l10n/app_localizations_uk.dart @@ -4809,8 +4809,9 @@ class AppLocalizationsUk extends AppLocalizations { 'Evict discovered contacts'; @override - String get contactsSettings_evictDiscoveredContactsSubtitle => - 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of 500 entries.'; + String contactsSettings_evictDiscoveredContactsSubtitle(int limit) { + return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.'; + } @override String get discoveredContacts_Title => 'Виявлені контакти'; diff --git a/lib/l10n/app_localizations_zh.dart b/lib/l10n/app_localizations_zh.dart index 8525ffe9..2b7dcffb 100644 --- a/lib/l10n/app_localizations_zh.dart +++ b/lib/l10n/app_localizations_zh.dart @@ -4444,8 +4444,9 @@ class AppLocalizationsZh extends AppLocalizations { 'Evict discovered contacts'; @override - String get contactsSettings_evictDiscoveredContactsSubtitle => - 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of 500 entries.'; + String contactsSettings_evictDiscoveredContactsSubtitle(int limit) { + return 'When enabled, the app removes the oldest discovered contacts once the discovery list reaches its limit of $limit entries.'; + } @override String get discoveredContacts_Title => '已发现的联系人'; diff --git a/lib/models/app_settings.dart b/lib/models/app_settings.dart index f64aa573..547b1e3e 100644 --- a/lib/models/app_settings.dart +++ b/lib/models/app_settings.dart @@ -227,7 +227,7 @@ class AppSettings { this.unitSystem = UnitSystem.metric, Set? mutedChannels, this.mapShowDiscoveryContacts = true, - this.evictDiscoveredContactsEnabled = false, + this.evictDiscoveredContactsEnabled = true, this.tcpServerAddress = '', this.tcpServerPort = 0, this.jumpToOldestUnread = false, @@ -411,7 +411,7 @@ class AppSettings { mapShowDiscoveryContacts: json['map_show_discovery_contacts'] as bool? ?? true, evictDiscoveredContactsEnabled: - json['evict_discovered_contacts_enabled'] as bool? ?? false, + json['evict_discovered_contacts_enabled'] as bool? ?? true, tcpServerAddress: json['tcp_server_address'] as String? ?? '', tcpServerPort: json['tcp_server_port'] as int? ?? 0, jumpToOldestUnread: json['jump_to_oldest_unread'] as bool? ?? false, diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dart index 25c0ea21..a43d6051 100644 --- a/lib/screens/settings_screen.dart +++ b/lib/screens/settings_screen.dart @@ -1234,6 +1234,7 @@ class _SettingsScreenState extends State { final appSettingsService = context.read(); bool evictDiscoveredContactsEnabled = appSettingsService.settings.evictDiscoveredContactsEnabled; + bool saving = false; final connector = context.read(); autoAddChat = connector.autoAddUsers ?? false; @@ -1298,8 +1299,10 @@ class _SettingsScreenState extends State { const Divider(height: 4), FeatureToggleRow( title: l10n.contactsSettings_evictDiscoveredContactsTitle, - subtitle: - l10n.contactsSettings_evictDiscoveredContactsSubtitle, + subtitle: l10n + .contactsSettings_evictDiscoveredContactsSubtitle( + MeshCoreConnector.maxDiscoveredContacts, + ), value: evictDiscoveredContactsEnabled, onChanged: (value) { setDialogState( @@ -1316,24 +1319,38 @@ class _SettingsScreenState extends State { child: Text(l10n.common_cancel), ), TextButton( - onPressed: () async { - await appSettingsService.setEvictDiscoveredContactsEnabled( - evictDiscoveredContactsEnabled, - ); - if (evictDiscoveredContactsEnabled) { - await connector.trimDiscoveredContactsToLimit(); - } - _sendSettings( - connector, - autoAddChat, - autoAddRepeater, - autoAddRoomServer, - autoAddSensor, - overwriteOldest, - ); - if (!context.mounted) return; - Navigator.pop(context); - }, + onPressed: saving + ? null + : () async { + setDialogState(() => saving = true); + _sendSettings( + connector, + autoAddChat, + autoAddRepeater, + autoAddRoomServer, + autoAddSensor, + overwriteOldest, + ); + try { + await appSettingsService + .setEvictDiscoveredContactsEnabled( + evictDiscoveredContactsEnabled, + ); + if (evictDiscoveredContactsEnabled) { + await connector.trimDiscoveredContactsToLimit(); + } + } catch (e) { + if (!context.mounted) return; + showDismissibleSnackBar( + context, + content: Text(l10n.settings_error(e.toString())), + ); + setDialogState(() => saving = false); + return; + } + if (!context.mounted) return; + Navigator.pop(context); + }, child: Text(l10n.common_save), ), ], diff --git a/test/models/model_changes_test.dart b/test/models/model_changes_test.dart index fcac50bb..b96666e3 100644 --- a/test/models/model_changes_test.dart +++ b/test/models/model_changes_test.dart @@ -405,7 +405,7 @@ void main() { expect(settings.routeWeightSuccessIncrement, equals(0.5)); expect(settings.routeWeightFailureDecrement, equals(0.2)); expect(settings.maxMessageRetries, equals(5)); - expect(settings.evictDiscoveredContactsEnabled, isFalse); + expect(settings.evictDiscoveredContactsEnabled, isTrue); }); test('toJson includes all new fields', () { @@ -422,7 +422,7 @@ void main() { expect(json['route_weight_success_increment'], equals(0.5)); expect(json['route_weight_failure_decrement'], equals(0.2)); expect(json['max_message_retries'], equals(5)); - expect(json['evict_discovered_contacts_enabled'], isFalse); + expect(json['evict_discovered_contacts_enabled'], isTrue); }); test('fromJson reads all new fields', () { diff --git a/untranslated.json b/untranslated.json index 0d526645..9e26dfee 100644 --- a/untranslated.json +++ b/untranslated.json @@ -1,148 +1 @@ -{ - "bg": [ - "urlImage_enable", - "urlImage_possible", - "settings_publicKeyCopied", - "reaction_report", - "contactsSettings_evictDiscoveredContactsTitle", - "contactsSettings_evictDiscoveredContactsSubtitle" - ], - - "de": [ - "settings_publicKeyCopied", - "reaction_report" - ], - - "es": [ - "urlImage_enable", - "urlImage_possible", - "settings_publicKeyCopied", - "reaction_report", - "contactsSettings_evictDiscoveredContactsTitle", - "contactsSettings_evictDiscoveredContactsSubtitle" - ], - - "fr": [ - "urlImage_enable", - "urlImage_possible", - "settings_publicKeyCopied", - "reaction_report", - "contactsSettings_evictDiscoveredContactsTitle", - "contactsSettings_evictDiscoveredContactsSubtitle" - ], - - "hu": [ - "urlImage_enable", - "urlImage_possible", - "settings_publicKeyCopied", - "reaction_report", - "contactsSettings_evictDiscoveredContactsTitle", - "contactsSettings_evictDiscoveredContactsSubtitle" - ], - - "it": [ - "urlImage_enable", - "urlImage_possible", - "reaction_report", - "contactsSettings_evictDiscoveredContactsTitle", - "contactsSettings_evictDiscoveredContactsSubtitle" - ], - - "ja": [ - "urlImage_enable", - "urlImage_possible", - "settings_publicKeyCopied", - "reaction_report", - "contactsSettings_evictDiscoveredContactsTitle", - "contactsSettings_evictDiscoveredContactsSubtitle" - ], - - "ko": [ - "urlImage_enable", - "urlImage_possible", - "settings_publicKeyCopied", - "reaction_report", - "contactsSettings_evictDiscoveredContactsTitle", - "contactsSettings_evictDiscoveredContactsSubtitle" - ], - - "nl": [ - "urlImage_enable", - "urlImage_possible", - "settings_publicKeyCopied", - "reaction_report", - "contactsSettings_evictDiscoveredContactsTitle", - "contactsSettings_evictDiscoveredContactsSubtitle" - ], - - "pl": [ - "urlImage_enable", - "urlImage_possible", - "settings_publicKeyCopied", - "reaction_report", - "contactsSettings_evictDiscoveredContactsTitle", - "contactsSettings_evictDiscoveredContactsSubtitle" - ], - - "pt": [ - "urlImage_enable", - "urlImage_possible", - "settings_publicKeyCopied", - "reaction_report", - "contactsSettings_evictDiscoveredContactsTitle", - "contactsSettings_evictDiscoveredContactsSubtitle" - ], - - "ru": [ - "urlImage_enable", - "urlImage_possible", - "settings_publicKeyCopied", - "reaction_report", - "contactsSettings_evictDiscoveredContactsTitle", - "contactsSettings_evictDiscoveredContactsSubtitle" - ], - - "sk": [ - "urlImage_enable", - "urlImage_possible", - "settings_publicKeyCopied", - "reaction_report", - "contactsSettings_evictDiscoveredContactsTitle", - "contactsSettings_evictDiscoveredContactsSubtitle" - ], - - "sl": [ - "urlImage_enable", - "urlImage_possible", - "settings_publicKeyCopied", - "reaction_report", - "contactsSettings_evictDiscoveredContactsTitle", - "contactsSettings_evictDiscoveredContactsSubtitle" - ], - - "sv": [ - "urlImage_enable", - "urlImage_possible", - "settings_publicKeyCopied", - "contactsSettings_evictDiscoveredContactsTitle", - "contactsSettings_evictDiscoveredContactsSubtitle" - ], - - "uk": [ - "urlImage_enable", - "urlImage_possible", - "settings_publicKeyCopied", - "reaction_report", - "contactsSettings_evictDiscoveredContactsTitle", - "contactsSettings_evictDiscoveredContactsSubtitle" - ], - - "zh": [ - "urlImage_enable", - "urlImage_possible", - "settings_publicKeyCopied", - "reaction_report", - "contactsSettings_evictDiscoveredContactsTitle", - "contactsSettings_evictDiscoveredContactsSubtitle" - ] -} +{} \ No newline at end of file