mirror of
https://github.com/rustdesk/rustdesk.git
synced 2024-11-27 23:19:02 +08:00
commit
be55926cfe
@ -380,12 +380,12 @@ class AbModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _syncFromRecentWithoutLock({bool push = true}) async {
|
Future<void> _syncFromRecentWithoutLock({bool push = true}) async {
|
||||||
bool shouldSync(Peer r, Peer p) {
|
bool peerSyncEqual(Peer a, Peer b) {
|
||||||
return r.hash != p.hash ||
|
return a.hash == b.hash &&
|
||||||
r.username != p.username ||
|
a.username == b.username &&
|
||||||
r.platform != p.platform ||
|
a.platform == b.platform &&
|
||||||
r.hostname != p.hostname ||
|
a.hostname == b.hostname &&
|
||||||
(p.alias.isEmpty && r.alias.isNotEmpty);
|
a.alias == b.alias;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<Peer>> getRecentPeers() async {
|
Future<List<Peer>> getRecentPeers() async {
|
||||||
@ -425,29 +425,30 @@ class AbModel {
|
|||||||
if (!shouldSyncAb()) return;
|
if (!shouldSyncAb()) return;
|
||||||
final recents = await getRecentPeers();
|
final recents = await getRecentPeers();
|
||||||
if (recents.isEmpty) return;
|
if (recents.isEmpty) return;
|
||||||
bool syncChanged = false;
|
|
||||||
bool uiChanged = false;
|
bool uiChanged = false;
|
||||||
|
bool needSync = false;
|
||||||
for (var i = 0; i < recents.length; i++) {
|
for (var i = 0; i < recents.length; i++) {
|
||||||
var r = recents[i];
|
var r = recents[i];
|
||||||
var index = peers.indexWhere((e) => e.id == r.id);
|
var index = peers.indexWhere((e) => e.id == r.id);
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
if (!isFull(false)) {
|
if (!isFull(false)) {
|
||||||
peers.add(r);
|
peers.add(r);
|
||||||
syncChanged = true;
|
|
||||||
uiChanged = true;
|
uiChanged = true;
|
||||||
|
needSync = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!r.equal(peers[index])) {
|
if (!r.equal(peers[index])) {
|
||||||
uiChanged = true;
|
uiChanged = true;
|
||||||
}
|
}
|
||||||
if (shouldSync(r, peers[index])) {
|
Peer old = Peer.copy(peers[index]);
|
||||||
syncChanged = true;
|
|
||||||
}
|
|
||||||
peers[index] = merge(r, peers[index]);
|
peers[index] = merge(r, peers[index]);
|
||||||
|
if (!peerSyncEqual(peers[index], old)) {
|
||||||
|
needSync = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Be careful with loop calls
|
// Be careful with loop calls
|
||||||
if (syncChanged && push) {
|
if (needSync && push) {
|
||||||
pushAb(toastIfSucc: false, toastIfFail: false);
|
pushAb(toastIfSucc: false, toastIfFail: false);
|
||||||
} else if (uiChanged) {
|
} else if (uiChanged) {
|
||||||
peers.refresh();
|
peers.refresh();
|
||||||
|
@ -101,6 +101,19 @@ class Peer {
|
|||||||
rdpPort == other.rdpPort &&
|
rdpPort == other.rdpPort &&
|
||||||
rdpUsername == other.rdpUsername;
|
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 }
|
enum UpdateEvent { online, load }
|
||||||
|
Loading…
Reference in New Issue
Block a user