mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-04-02 17:41:29 +03:00
refact: optimize, ID search peers (#10853)
* refact: optimize, preload peers Signed-off-by: fufesou <linlong1266@gmail.com> * Update dialogs.dart --------- Signed-off-by: fufesou <linlong1266@gmail.com> Co-authored-by: RustDesk <71636191+rustdesk@users.noreply.github.com>
This commit is contained in:
@@ -205,7 +205,7 @@ class _ConnectionPageState extends State<ConnectionPage>
|
||||
|
||||
bool isWindowMinimized = false;
|
||||
|
||||
AllPeersLoader allPeersLoader = AllPeersLoader();
|
||||
final AllPeersLoader _allPeersLoader = AllPeersLoader();
|
||||
|
||||
// https://github.com/flutter/flutter/issues/157244
|
||||
Iterable<Peer> _autocompleteOpts = [];
|
||||
@@ -213,6 +213,7 @@ class _ConnectionPageState extends State<ConnectionPage>
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_allPeersLoader.init(setState);
|
||||
_idFocusNode.addListener(onFocusChanged);
|
||||
if (_idController.text.isEmpty) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
@@ -232,6 +233,7 @@ class _ConnectionPageState extends State<ConnectionPage>
|
||||
void dispose() {
|
||||
_idController.dispose();
|
||||
windowManager.removeListener(this);
|
||||
_allPeersLoader.clear();
|
||||
_idFocusNode.removeListener(onFocusChanged);
|
||||
_idFocusNode.dispose();
|
||||
_idEditingController.dispose();
|
||||
@@ -280,8 +282,8 @@ class _ConnectionPageState extends State<ConnectionPage>
|
||||
|
||||
void onFocusChanged() {
|
||||
_idInputFocused.value = _idFocusNode.hasFocus;
|
||||
if (_idFocusNode.hasFocus && !allPeersLoader.isPeersLoading) {
|
||||
allPeersLoader.getAllPeers(setState);
|
||||
if (_idFocusNode.hasFocus && !_allPeersLoader.isPeersLoading) {
|
||||
_allPeersLoader.getAllPeers();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,8 +338,8 @@ class _ConnectionPageState extends State<ConnectionPage>
|
||||
optionsBuilder: (TextEditingValue textEditingValue) {
|
||||
if (textEditingValue.text == '') {
|
||||
_autocompleteOpts = const Iterable<Peer>.empty();
|
||||
} else if (allPeersLoader.peers.isEmpty &&
|
||||
!allPeersLoader.isLoaded) {
|
||||
} else if (_allPeersLoader.peers.isEmpty &&
|
||||
!_allPeersLoader.isPeersLoaded) {
|
||||
Peer emptyPeer = Peer(
|
||||
id: '',
|
||||
username: '',
|
||||
@@ -364,7 +366,7 @@ class _ConnectionPageState extends State<ConnectionPage>
|
||||
);
|
||||
}
|
||||
String textToFind = textEditingValue.text.toLowerCase();
|
||||
_autocompleteOpts = allPeersLoader.peers
|
||||
_autocompleteOpts = _allPeersLoader.peers
|
||||
.where((peer) =>
|
||||
peer.id.toLowerCase().contains(textToFind) ||
|
||||
peer.username
|
||||
@@ -471,8 +473,8 @@ class _ConnectionPageState extends State<ConnectionPage>
|
||||
maxHeight: maxHeight,
|
||||
maxWidth: 319,
|
||||
),
|
||||
child: allPeersLoader.peers.isEmpty &&
|
||||
!allPeersLoader.isLoaded
|
||||
child: _allPeersLoader.peers.isEmpty &&
|
||||
!_allPeersLoader.isPeersLoaded
|
||||
? Container(
|
||||
height: 80,
|
||||
child: Center(
|
||||
|
||||
Reference in New Issue
Block a user