Skip to content

An open-source remote desktop application designed for self-hosting, as an alternative to TeamViewer.

fix ab sync judge

21pages8e9f3e2b4dd7
diff --git a/flutter/lib/models/ab_model.dart b/flutter/lib/models/ab_model.dart
index c160a139c..001e16190 100644
--- a/flutter/lib/models/ab_model.dart
+++ b/flutter/lib/models/ab_model.dart
@@ -380,12 +380,12 @@ class AbModel {
}
Future<void> _syncFromRecentWithoutLock({bool push = true}) async {
- bool shouldSync(Peer r, Peer p) {
- return r.hash != p.hash ||
- r.username != p.username ||
- r.platform != p.platform ||
- r.hostname != p.hostname ||
- (p.alias.isEmpty && r.alias.isNotEmpty);
+ bool peerSyncEqual(Peer a, Peer b) {
+ return a.hash == b.hash &&
+ a.username == b.username &&
+ a.platform == b.platform &&
+ a.hostname == b.hostname &&
+ a.alias == b.alias;
}
Future<List<Peer>> getRecentPeers() async {
@@ -425,29 +425,30 @@ class AbModel {
if (!shouldSyncAb()) return;
final recents = await getRecentPeers();
if (recents.isEmpty) return;
- bool syncChanged = false;
bool uiChanged = false;
+ bool needSync = false;
for (var i = 0; i < recents.length; i++) {
var r = recents[i];
var index = peers.indexWhere((e) => e.id == r.id);
if (index < 0) {
if (!isFull(false)) {
peers.add(r);
- syncChanged = true;
uiChanged = true;
+ needSync = true;
}
} else {
if (!r.equal(peers[index])) {
uiChanged = true;
}
- if (shouldSync(r, peers[index])) {
- syncChanged = true;
- }
+ Peer old = Peer.copy(peers[index]);
peers[index] = merge(r, peers[index]);
+ if (!peerSyncEqual(peers[index], old)) {
+ needSync = true;
+ }
}
}
// Be careful with loop calls
- if (syncChanged && push) {
+ if (needSync && push) {
pushAb(toastIfSucc: false, toastIfFail: false);
} else if (uiChanged) {
peers.refresh();
diff --git a/flutter/lib/models/peer_model.dart b/flutter/lib/models/peer_model.dart
index ddd9f8538..34afbfeaf 100644
--- a/flutter/lib/models/peer_model.dart
+++ b/flutter/lib/models/peer_model.dart
@@ -101,6 +101,19 @@ class Peer {
rdpPort == other.rdpPort &&
rdpUsername == other.rdpUsername;
}
+
+ Peer.copy(Peer other)
+ : this(
+ id: other.id,
+ hash: other.hash,
+ username: other.username,
+ hostname: other.hostname,
+ platform: other.platform,
+ alias: other.alias,
+ tags: other.tags.toList(),
+ forceAlwaysRelay: other.forceAlwaysRelay,
+ rdpPort: other.rdpPort,
+ rdpUsername: other.rdpUsername);
}
enum UpdateEvent { online, load }