mirror of
https://github.com/dz0ny/meshcore-sar.git
synced 2026-08-11 16:30:28 +00:00
fix: Profile duplication on device connect
DeviceKey resolver was falling back to deviceId when publicKey wasn't yet available during early connection. This created two different keys (id:xxx then pk:yyy) for the same device, causing a new profile to be created each time. Now returns null until publicKey is available, so profile sync waits for the stable identifier.
This commit is contained in:
@@ -5,25 +5,17 @@ class ProfileDeviceKeyResolver {
|
|||||||
required DeviceInfo deviceInfo,
|
required DeviceInfo deviceInfo,
|
||||||
required ConnectionMode connectionMode,
|
required ConnectionMode connectionMode,
|
||||||
}) {
|
}) {
|
||||||
|
// Always prefer the public key — it's the only truly stable identifier.
|
||||||
|
// Don't fall back to deviceId to avoid creating duplicate profiles when
|
||||||
|
// publicKey arrives late (after initial connection but before DeviceInfo).
|
||||||
final publicKey = deviceInfo.publicKey;
|
final publicKey = deviceInfo.publicKey;
|
||||||
if (publicKey != null && publicKey.isNotEmpty) {
|
if (publicKey == null || publicKey.isEmpty) {
|
||||||
final hex = publicKey
|
return null; // Wait until publicKey is available
|
||||||
.map((byte) => byte.toRadixString(16).padLeft(2, '0'))
|
|
||||||
.join();
|
|
||||||
if (hex.isNotEmpty) {
|
|
||||||
return 'pk:$hex';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final deviceId = deviceInfo.deviceId?.trim();
|
final hex = publicKey
|
||||||
if (deviceId == null || deviceId.isEmpty) {
|
.map((byte) => byte.toRadixString(16).padLeft(2, '0'))
|
||||||
return null;
|
.join();
|
||||||
}
|
return hex.isNotEmpty ? 'pk:$hex' : null;
|
||||||
|
|
||||||
if (connectionMode == ConnectionMode.usb && deviceId == 'usb') {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 'id:$deviceId';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user