clear contacts and channels before restoring.

This commit is contained in:
ericz committed 2026-11-08 03:15:32 +01:00
1 parent 79109c2c5c
commit 76232c1ad7
23 files changed
+85 -36

No files matched your search

+1 -1
View File
@@ -212,7 +212,7 @@ The settings card links to **Backup & Restore** and **Export** subpages.
### Backup & Restore
Choose individual items to include in a backup or restore. Location settings include the saved coordinates, GPS enable state and interval, contact discovery options, and privacy/adverts settings. When importing, only items found in the selected file can be selected. Backups from the official MeshCore app are supported; those files do not include app preferences, groups, filters, or message history, so those choices are unavailable. A radio connection is required to restore radio settings and contact or channel lists. Contact and channel lists are restored to the connected radio; message history and groups are restored in the app.
Choose individual items to include in a backup or restore. Location settings include the saved coordinates, GPS enable state and interval, contact discovery options, and privacy/adverts settings. When importing, only items found in the selected file can be selected. Backups from the official MeshCore app are supported; those files do not include app preferences, groups, filters, or message history, so those choices are unavailable. A radio connection is required to restore radio settings and contact or channel lists. Restoring contacts or channels replaces the selected list on the radio, then reloads it from the device. If you also restore the radio identity, reconnect afterward to reload its data. Message history and groups are restored in the app.
The private-key option is off by default because it changes the radio's identity. Select it only when you intend to restore that identity; the app asks for confirmation before proceeding. Some radios do not allow identity backup or restore, and the app will let you know if this feature is unavailable.
+1 -1
View File
@@ -234,7 +234,7 @@
"backupRestore_backup": "Create Backup",
"backupRestore_restore": "Restore Selected",
"backupRestore_backupComplete": "Backup file created.",
"backupRestore_restoreComplete": "Restore complete. Reconnect the radio to refresh its data.",
"backupRestore_restoreComplete": "Restore complete. Reconnect if you restored the radio identity.",
"backupRestore_failed": "Backup operation failed: {error}",
"@backupRestore_failed": {
"placeholders": {
+1 -1
View File
@@ -1081,7 +1081,7 @@ abstract class AppLocalizations {
/// No description provided for @backupRestore_restoreComplete.
///
/// In en, this message translates to:
/// **'Restore complete. Reconnect the radio to refresh its data.'**
/// **'Restore complete. Reconnect if you restored the radio identity.'**
String get backupRestore_restoreComplete;
/// No description provided for @backupRestore_failed.
+1 -1
View File
@@ -542,7 +542,7 @@ class AppLocalizationsBg extends AppLocalizations {
@override
String get backupRestore_restoreComplete =>
'Restore complete. Reconnect the radio to refresh its data.';
'Restore complete. Reconnect if you restored the radio identity.';
@override
String backupRestore_failed(String error) {
+1 -1
View File
@@ -545,7 +545,7 @@ class AppLocalizationsDe extends AppLocalizations {
@override
String get backupRestore_restoreComplete =>
'Restore complete. Reconnect the radio to refresh its data.';
'Restore complete. Reconnect if you restored the radio identity.';
@override
String backupRestore_failed(String error) {
+1 -1
View File
@@ -538,7 +538,7 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get backupRestore_restoreComplete =>
'Restore complete. Reconnect the radio to refresh its data.';
'Restore complete. Reconnect if you restored the radio identity.';
@override
String backupRestore_failed(String error) {
+1 -1
View File
@@ -543,7 +543,7 @@ class AppLocalizationsEs extends AppLocalizations {
@override
String get backupRestore_restoreComplete =>
'Restore complete. Reconnect the radio to refresh its data.';
'Restore complete. Reconnect if you restored the radio identity.';
@override
String backupRestore_failed(String error) {
+1 -1
View File
@@ -545,7 +545,7 @@ class AppLocalizationsFr extends AppLocalizations {
@override
String get backupRestore_restoreComplete =>
'Restore complete. Reconnect the radio to refresh its data.';
'Restore complete. Reconnect if you restored the radio identity.';
@override
String backupRestore_failed(String error) {
+1 -1
View File
@@ -541,7 +541,7 @@ class AppLocalizationsHu extends AppLocalizations {
@override
String get backupRestore_restoreComplete =>
'Restore complete. Reconnect the radio to refresh its data.';
'Restore complete. Reconnect if you restored the radio identity.';
@override
String backupRestore_failed(String error) {
+1 -1
View File
@@ -545,7 +545,7 @@ class AppLocalizationsIt extends AppLocalizations {
@override
String get backupRestore_restoreComplete =>
'Restore complete. Reconnect the radio to refresh its data.';
'Restore complete. Reconnect if you restored the radio identity.';
@override
String backupRestore_failed(String error) {
+1 -1
View File
@@ -526,7 +526,7 @@ class AppLocalizationsJa extends AppLocalizations {
@override
String get backupRestore_restoreComplete =>
'Restore complete. Reconnect the radio to refresh its data.';
'Restore complete. Reconnect if you restored the radio identity.';
@override
String backupRestore_failed(String error) {
+1 -1
View File
@@ -526,7 +526,7 @@ class AppLocalizationsKo extends AppLocalizations {
@override
String get backupRestore_restoreComplete =>
'Restore complete. Reconnect the radio to refresh its data.';
'Restore complete. Reconnect if you restored the radio identity.';
@override
String backupRestore_failed(String error) {
+1 -1
View File
@@ -541,7 +541,7 @@ class AppLocalizationsNl extends AppLocalizations {
@override
String get backupRestore_restoreComplete =>
'Restore complete. Reconnect the radio to refresh its data.';
'Restore complete. Reconnect if you restored the radio identity.';
@override
String backupRestore_failed(String error) {
+1 -1
View File
@@ -548,7 +548,7 @@ class AppLocalizationsPl extends AppLocalizations {
@override
String get backupRestore_restoreComplete =>
'Restore complete. Reconnect the radio to refresh its data.';
'Restore complete. Reconnect if you restored the radio identity.';
@override
String backupRestore_failed(String error) {
+1 -1
View File
@@ -544,7 +544,7 @@ class AppLocalizationsPt extends AppLocalizations {
@override
String get backupRestore_restoreComplete =>
'Restore complete. Reconnect the radio to refresh its data.';
'Restore complete. Reconnect if you restored the radio identity.';
@override
String backupRestore_failed(String error) {
+1 -1
View File
@@ -544,7 +544,7 @@ class AppLocalizationsRu extends AppLocalizations {
@override
String get backupRestore_restoreComplete =>
'Restore complete. Reconnect the radio to refresh its data.';
'Restore complete. Reconnect if you restored the radio identity.';
@override
String backupRestore_failed(String error) {
+1 -1
View File
@@ -544,7 +544,7 @@ class AppLocalizationsSk extends AppLocalizations {
@override
String get backupRestore_restoreComplete =>
'Restore complete. Reconnect the radio to refresh its data.';
'Restore complete. Reconnect if you restored the radio identity.';
@override
String backupRestore_failed(String error) {
+1 -1
View File
@@ -543,7 +543,7 @@ class AppLocalizationsSl extends AppLocalizations {
@override
String get backupRestore_restoreComplete =>
'Restore complete. Reconnect the radio to refresh its data.';
'Restore complete. Reconnect if you restored the radio identity.';
@override
String backupRestore_failed(String error) {
+1 -1
View File
@@ -539,7 +539,7 @@ class AppLocalizationsSv extends AppLocalizations {
@override
String get backupRestore_restoreComplete =>
'Restore complete. Reconnect the radio to refresh its data.';
'Restore complete. Reconnect if you restored the radio identity.';
@override
String backupRestore_failed(String error) {
+1 -1
View File
@@ -543,7 +543,7 @@ class AppLocalizationsUk extends AppLocalizations {
@override
String get backupRestore_restoreComplete =>
'Restore complete. Reconnect the radio to refresh its data.';
'Restore complete. Reconnect if you restored the radio identity.';
@override
String backupRestore_failed(String error) {
+1 -1
View File
@@ -520,7 +520,7 @@ class AppLocalizationsZh extends AppLocalizations {
@override
String get backupRestore_restoreComplete =>
'Restore complete. Reconnect the radio to refresh its data.';
'Restore complete. Reconnect if you restored the radio identity.';
@override
String backupRestore_failed(String error) {
+2
View File
@@ -46,6 +46,8 @@ class _BackupRestoreScreenState extends State<BackupRestoreScreen> {
BackupItem.location,
BackupItem.contactSettings,
BackupItem.privacySettings,
BackupItem.contacts,
BackupItem.channels,
};
static const Set<BackupItem> _defaultUncheckedOnRestore = {
..._defaultUncheckedItems,
+62 -15
View File
@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:convert';
import 'dart:math';
import 'dart:typed_data';
@@ -6,8 +7,8 @@ import 'package:cryptography/cryptography.dart';
import '../connector/meshcore_connector.dart';
import '../connector/meshcore_protocol.dart';
import '../connector/pending_command_replies.dart';
import '../models/app_settings.dart';
import '../models/contact.dart';
import 'app_settings_service.dart';
import '../storage/channel_store.dart';
import '../storage/contact_store.dart';
@@ -302,6 +303,8 @@ class BackupService {
final restoreChannels = selectedItems.any(
(item) => _sectionForItem(item) == BackupSection.channels,
);
final replaceContacts = selectedItems.contains(BackupItem.contacts);
final replaceChannels = selectedItems.contains(BackupItem.channels);
if (importingIdentity &&
(sourcePublicKey.isEmpty ||
_normalizePublicKey(node?['publicKey'] as String? ?? '') !=
@@ -315,6 +318,9 @@ class BackupService {
throw StateError('Wait for radio identity to finish loading');
}
}
if (replaceContacts) await _clearRadioContacts(connector);
if (replaceChannels) await _clearRadioChannels(connector);
if (node != null) {
final name = node['name'];
if (selectedItems.contains(BackupItem.deviceName) && name is String) {
@@ -474,12 +480,61 @@ class BackupService {
);
}
}
if (selectedItems.contains(BackupItem.contacts)) {
if (replaceContacts) {
await _restoreRadioContacts(connector, destinationPublicKey);
}
if (selectedItems.contains(BackupItem.channels)) {
if (replaceChannels) {
await _restoreRadioChannels(connector, destinationPublicKey);
}
if (!importingIdentity) {
if (replaceContacts) await _refreshContactsFromRadio(connector);
if (replaceChannels) await connector.getChannels(force: true);
}
}
Future<void> _clearRadioContacts(MeshCoreConnector connector) async {
await _refreshContactsFromRadio(connector);
for (final contact in connector.contacts.toList()) {
try {
await connector.sendFrame(
buildRemoveContactFrame(contact.publicKey),
waitForGenericAck: true,
);
} on FirmwareCommandException {
// A contact removed on the radio since its last sync is already clear.
}
}
}
Future<void> _clearRadioChannels(MeshCoreConnector connector) async {
await connector.getChannels(force: true);
for (final channel in connector.channels) {
if (channel.isEmpty) continue;
await connector.sendFrame(
buildSetChannelFrame(channel.index, '', Uint8List(16)),
waitForGenericAck: true,
);
}
}
Future<void> _refreshContactsFromRadio(MeshCoreConnector connector) async {
final refreshed = Completer<void>();
void checkComplete() {
if (connector.hasLoadedContacts &&
!connector.isLoadingContacts &&
!refreshed.isCompleted) {
refreshed.complete();
}
}
connector.addListener(checkComplete);
try {
await connector.getContacts();
checkComplete();
await refreshed.future.timeout(const Duration(seconds: 30));
} finally {
connector.removeListener(checkComplete);
}
}
Future<void> _restoreRadioContacts(
@@ -492,22 +547,14 @@ class BackupService {
if (contact.publicKeyHex.toUpperCase() == publicKey.toUpperCase()) {
continue;
}
Contact? existing;
for (final candidate in connector.contacts) {
if (candidate.publicKeyHex == contact.publicKeyHex) {
existing = candidate;
break;
}
}
final pathLengthValue = existing?.pathLength ?? contact.pathLength;
final pathHashWidth = existing?.pathHashWidth ?? contact.pathHashWidth;
final pathLength = pathLengthValue < 0
final pathLength = contact.pathLength < 0
? 0xff
: (pathLengthValue & 0x3f) | (((pathHashWidth - 1) & 0x03) << 6);
: (contact.pathLength & 0x3f) |
(((contact.pathHashWidth - 1) & 0x03) << 6);
await connector.sendFrame(
buildUpdateContactPathFrame(
contact.publicKey,
existing?.path ?? contact.path,
contact.path,
pathLength,
type: contact.type,
flags: contact.flags,