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) {
|
||||
final index = peers.indexWhere((e) => e.id == peer.id);
|
||||
if (index >= 0) {
|
||||
peers[index] = merge(peer, peers[index]);
|
||||
merge(peer, peers[index]);
|
||||
} else {
|
||||
peers.add(peer);
|
||||
}
|
||||
@ -365,18 +365,14 @@ class AbModel {
|
||||
}
|
||||
}
|
||||
|
||||
Peer merge(Peer r, Peer p) {
|
||||
return Peer(
|
||||
id: p.id,
|
||||
hash: r.hash.isEmpty ? p.hash : r.hash,
|
||||
username: r.username.isEmpty ? p.username : r.username,
|
||||
hostname: r.hostname.isEmpty ? p.hostname : r.hostname,
|
||||
platform: r.platform.isEmpty ? p.platform : r.platform,
|
||||
alias: p.alias.isEmpty ? r.alias : p.alias,
|
||||
tags: p.tags,
|
||||
forceAlwaysRelay: r.forceAlwaysRelay,
|
||||
rdpPort: r.rdpPort,
|
||||
rdpUsername: r.rdpUsername);
|
||||
void merge(Peer r, Peer p) {
|
||||
p.hash = r.hash.isEmpty ? p.hash : r.hash;
|
||||
p.username = r.username.isEmpty ? p.username : r.username;
|
||||
p.hostname = r.hostname.isEmpty ? p.hostname : r.hostname;
|
||||
p.alias = p.alias.isEmpty ? r.alias : p.alias;
|
||||
p.forceAlwaysRelay = r.forceAlwaysRelay;
|
||||
p.rdpPort = r.rdpPort;
|
||||
p.rdpUsername = r.rdpUsername;
|
||||
}
|
||||
|
||||
Future<void> syncFromRecent({bool push = true}) async {
|
||||
@ -445,14 +441,14 @@ class AbModel {
|
||||
needSync = true;
|
||||
}
|
||||
} else {
|
||||
if (!r.equal(peers[index])) {
|
||||
uiChanged = true;
|
||||
}
|
||||
Peer old = Peer.copy(peers[index]);
|
||||
peers[index] = merge(r, peers[index]);
|
||||
merge(r, peers[index]);
|
||||
if (!peerSyncEqual(peers[index], old)) {
|
||||
needSync = true;
|
||||
}
|
||||
if (!old.equal(peers[index])) {
|
||||
uiChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Be careful with loop calls
|
||||
|
@ -7,9 +7,9 @@ import 'package:collection/collection.dart';
|
||||
class Peer {
|
||||
final String id;
|
||||
String hash;
|
||||
final String username;
|
||||
final String hostname;
|
||||
final String platform;
|
||||
String username;
|
||||
String hostname;
|
||||
String platform;
|
||||
String alias;
|
||||
List<dynamic> tags;
|
||||
bool forceAlwaysRelay = false;
|
||||
|
Loading…
Reference in New Issue
Block a user