mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-06-07 18:02:48 +08:00
query online on load peers
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
2c56159d6d
commit
277804feef
@ -168,6 +168,7 @@ class _PeersViewState extends State<_PeersView> with WindowListener {
|
|||||||
|
|
||||||
Widget _buildPeersView(Peers peers) {
|
Widget _buildPeersView(Peers peers) {
|
||||||
_loaded = true;
|
_loaded = true;
|
||||||
|
final updateEvent = peers.event;
|
||||||
final body = ObxValue<RxList>((filters) {
|
final body = ObxValue<RxList>((filters) {
|
||||||
return FutureBuilder<List<Peer>>(
|
return FutureBuilder<List<Peer>>(
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
@ -191,7 +192,14 @@ class _PeersViewState extends State<_PeersView> with WindowListener {
|
|||||||
)
|
)
|
||||||
: SizedBox(width: mobileWidth, child: visibilityChild));
|
: SizedBox(width: mobileWidth, child: visibilityChild));
|
||||||
}
|
}
|
||||||
return Wrap(spacing: space, runSpacing: space, children: cards);
|
final child =
|
||||||
|
Wrap(spacing: space, runSpacing: space, children: cards);
|
||||||
|
if (updateEvent == UpdateEvent.load) {
|
||||||
|
_curPeers.clear();
|
||||||
|
_curPeers.addAll(peers.map((e) => e.id));
|
||||||
|
_queryOnlines(true);
|
||||||
|
}
|
||||||
|
return child;
|
||||||
} else {
|
} else {
|
||||||
return const Center(
|
return const Center(
|
||||||
child: CircularProgressIndicator(),
|
child: CircularProgressIndicator(),
|
||||||
@ -205,26 +213,19 @@ class _PeersViewState extends State<_PeersView> with WindowListener {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ignore: todo
|
final _queryInterval = const Duration(seconds: 20);
|
||||||
// TODO: variables walk through async tasks?
|
|
||||||
void _startCheckOnlines() {
|
void _startCheckOnlines() {
|
||||||
final queryInterval = const Duration(seconds: 20);
|
|
||||||
() async {
|
() async {
|
||||||
while (!_exit) {
|
while (!_exit) {
|
||||||
final now = DateTime.now();
|
final now = DateTime.now();
|
||||||
if (!setEquals(_curPeers, _lastQueryPeers)) {
|
if (!setEquals(_curPeers, _lastQueryPeers)) {
|
||||||
if (now.difference(_lastChangeTime) > const Duration(seconds: 1)) {
|
if (now.difference(_lastChangeTime) > const Duration(seconds: 1)) {
|
||||||
if (_curPeers.isNotEmpty) {
|
_queryOnlines(false);
|
||||||
platformFFI.ffiBind
|
|
||||||
.queryOnlines(ids: _curPeers.toList(growable: false));
|
|
||||||
_lastQueryPeers = {..._curPeers};
|
|
||||||
_lastQueryTime = DateTime.now().subtract(queryInterval);
|
|
||||||
_queryCount = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (_queryCount < _maxQueryCount) {
|
if (_queryCount < _maxQueryCount) {
|
||||||
if (now.difference(_lastQueryTime) >= queryInterval) {
|
if (now.difference(_lastQueryTime) >= _queryInterval) {
|
||||||
if (_curPeers.isNotEmpty) {
|
if (_curPeers.isNotEmpty) {
|
||||||
platformFFI.ffiBind
|
platformFFI.ffiBind
|
||||||
.queryOnlines(ids: _curPeers.toList(growable: false));
|
.queryOnlines(ids: _curPeers.toList(growable: false));
|
||||||
@ -239,6 +240,19 @@ class _PeersViewState extends State<_PeersView> with WindowListener {
|
|||||||
}();
|
}();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_queryOnlines(bool isLoadEvent) {
|
||||||
|
if (_curPeers.isNotEmpty) {
|
||||||
|
platformFFI.ffiBind.queryOnlines(ids: _curPeers.toList(growable: false));
|
||||||
|
_lastQueryPeers = {..._curPeers};
|
||||||
|
if (isLoadEvent) {
|
||||||
|
_lastChangeTime = DateTime.now();
|
||||||
|
} else {
|
||||||
|
_lastQueryTime = DateTime.now().subtract(_queryInterval);
|
||||||
|
}
|
||||||
|
_queryCount = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<List<Peer>>? matchPeers(
|
Future<List<Peer>>? matchPeers(
|
||||||
String searchText, String sortedBy, List<Peer> peers) async {
|
String searchText, String sortedBy, List<Peer> peers) async {
|
||||||
if (widget.peerFilter != null) {
|
if (widget.peerFilter != null) {
|
||||||
|
@ -72,10 +72,13 @@ class Peer {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum UpdateEvent { online, load }
|
||||||
|
|
||||||
class Peers extends ChangeNotifier {
|
class Peers extends ChangeNotifier {
|
||||||
final String name;
|
final String name;
|
||||||
final String loadEvent;
|
final String loadEvent;
|
||||||
List<Peer> peers;
|
List<Peer> peers;
|
||||||
|
UpdateEvent event = UpdateEvent.load;
|
||||||
static const _cbQueryOnlines = 'callback_query_onlines';
|
static const _cbQueryOnlines = 'callback_query_onlines';
|
||||||
|
|
||||||
Peers({required this.name, required this.peers, required this.loadEvent}) {
|
Peers({required this.name, required this.peers, required this.loadEvent}) {
|
||||||
@ -123,6 +126,7 @@ class Peers extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
event = UpdateEvent.online;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,6 +137,7 @@ class Peers extends ChangeNotifier {
|
|||||||
final state = onlineStates[peer.id];
|
final state = onlineStates[peer.id];
|
||||||
peer.online = state != null && state != false;
|
peer.online = state != null && state != false;
|
||||||
}
|
}
|
||||||
|
event = UpdateEvent.load;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user