fix ab ui update on every time callback
Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
parent
5102adfd5c
commit
2279c1ce70
@ -163,7 +163,7 @@ class AbModel {
|
|||||||
void addPeer(Peer peer) {
|
void addPeer(Peer peer) {
|
||||||
final index = peers.indexWhere((e) => e.id == peer.id);
|
final index = peers.indexWhere((e) => e.id == peer.id);
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
peers[index] = merge(peer, peers[index]);
|
merge(peer, peers[index]);
|
||||||
} else {
|
} else {
|
||||||
peers.add(peer);
|
peers.add(peer);
|
||||||
}
|
}
|
||||||
@ -365,18 +365,14 @@ class AbModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Peer merge(Peer r, Peer p) {
|
void merge(Peer r, Peer p) {
|
||||||
return Peer(
|
p.hash = r.hash.isEmpty ? p.hash : r.hash;
|
||||||
id: p.id,
|
p.username = r.username.isEmpty ? p.username : r.username;
|
||||||
hash: r.hash.isEmpty ? p.hash : r.hash,
|
p.hostname = r.hostname.isEmpty ? p.hostname : r.hostname;
|
||||||
username: r.username.isEmpty ? p.username : r.username,
|
p.alias = p.alias.isEmpty ? r.alias : p.alias;
|
||||||
hostname: r.hostname.isEmpty ? p.hostname : r.hostname,
|
p.forceAlwaysRelay = r.forceAlwaysRelay;
|
||||||
platform: r.platform.isEmpty ? p.platform : r.platform,
|
p.rdpPort = r.rdpPort;
|
||||||
alias: p.alias.isEmpty ? r.alias : p.alias,
|
p.rdpUsername = r.rdpUsername;
|
||||||
tags: p.tags,
|
|
||||||
forceAlwaysRelay: r.forceAlwaysRelay,
|
|
||||||
rdpPort: r.rdpPort,
|
|
||||||
rdpUsername: r.rdpUsername);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> syncFromRecent({bool push = true}) async {
|
Future<void> syncFromRecent({bool push = true}) async {
|
||||||
@ -445,14 +441,14 @@ class AbModel {
|
|||||||
needSync = true;
|
needSync = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!r.equal(peers[index])) {
|
|
||||||
uiChanged = true;
|
|
||||||
}
|
|
||||||
Peer old = Peer.copy(peers[index]);
|
Peer old = Peer.copy(peers[index]);
|
||||||
peers[index] = merge(r, peers[index]);
|
merge(r, peers[index]);
|
||||||
if (!peerSyncEqual(peers[index], old)) {
|
if (!peerSyncEqual(peers[index], old)) {
|
||||||
needSync = true;
|
needSync = true;
|
||||||
}
|
}
|
||||||
|
if (!old.equal(peers[index])) {
|
||||||
|
uiChanged = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Be careful with loop calls
|
// Be careful with loop calls
|
||||||
|
@ -7,9 +7,9 @@ import 'package:collection/collection.dart';
|
|||||||
class Peer {
|
class Peer {
|
||||||
final String id;
|
final String id;
|
||||||
String hash;
|
String hash;
|
||||||
final String username;
|
String username;
|
||||||
final String hostname;
|
String hostname;
|
||||||
final String platform;
|
String platform;
|
||||||
String alias;
|
String alias;
|
||||||
List<dynamic> tags;
|
List<dynamic> tags;
|
||||||
bool forceAlwaysRelay = false;
|
bool forceAlwaysRelay = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user