Skip to content

An open-source remote desktop application designed for self-hosting, as an alternative to TeamViewer.

fix: mobile, query onlines, on active (#8796)

dignow614086a216c3
diff --git a/flutter/lib/common/widgets/peer_tab_page.dart b/flutter/lib/common/widgets/peer_tab_page.dart
index 21a276f0d..3b92ab1eb 100644
--- a/flutter/lib/common/widgets/peer_tab_page.dart
+++ b/flutter/lib/common/widgets/peer_tab_page.dart
@@ -875,11 +875,14 @@ class _PeerSortDropdownState extends State<PeerSortDropdown> {
@override
void initState() {
if (!PeerSortType.values.contains(peerSort.value)) {
- peerSort.value = PeerSortType.remoteId;
- bind.setLocalFlutterOption(
- k: kOptionPeerSorting,
- v: peerSort.value,
- );
+ Future.delayed(Duration.zero, () {
+ // do not change obx directly in initState, so do in future.
+ peerSort.value = PeerSortType.remoteId;
+ bind.setLocalFlutterOption(
+ k: kOptionPeerSorting,
+ v: peerSort.value,
+ );
+ });
}
super.initState();
}
diff --git a/flutter/lib/common/widgets/peers_view.dart b/flutter/lib/common/widgets/peers_view.dart
index 01727c86c..ec173e294 100644
--- a/flutter/lib/common/widgets/peers_view.dart
+++ b/flutter/lib/common/widgets/peers_view.dart
@@ -70,7 +70,8 @@ class _PeersView extends StatefulWidget {
}
/// State for the peer widget.
-class _PeersViewState extends State<_PeersView> with WindowListener {
+class _PeersViewState extends State<_PeersView>
+ with WindowListener, WidgetsBindingObserver {
static const int _maxQueryCount = 3;
final HashMap<String, String> _emptyMessages = HashMap.from({
LoadEvent.recent: 'empty_recent_tip',
@@ -85,6 +86,7 @@ class _PeersViewState extends State<_PeersView> with WindowListener {
var _lastQueryTime = DateTime.now();
var _queryCount = 0;
var _exit = false;
+ bool _isActive = true;
final _scrollController = ScrollController();
@@ -95,12 +97,14 @@ class _PeersViewState extends State<_PeersView> with WindowListener {
@override
void initState() {
windowManager.addListener(this);
+ WidgetsBinding.instance.addObserver(this);
super.initState();
}
@override
void dispose() {
windowManager.removeListener(this);
+ WidgetsBinding.instance.removeObserver(this);
_exit = true;
super.dispose();
}
@@ -115,6 +119,20 @@ class _PeersViewState extends State<_PeersView> with WindowListener {
_queryCount = _maxQueryCount;
}
+ // This function is required for mobile.
+ // `onWindowFocus` works fine for desktop.
+ @override
+ void didChangeAppLifecycleState(AppLifecycleState state) {
+ super.didChangeAppLifecycleState(state);
+ if (isDesktop) return;
+ if (state == AppLifecycleState.resumed) {
+ _isActive = true;
+ _queryCount = 0;
+ } else if (state == AppLifecycleState.inactive) {
+ _isActive = false;
+ }
+ }
+
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider<Peers>(
@@ -268,7 +286,7 @@ class _PeersViewState extends State<_PeersView> with WindowListener {
_queryOnlines(false);
}
} else {
- if (_queryCount < _maxQueryCount || !p) {
+ if (_isActive && (_queryCount < _maxQueryCount || !p)) {
if (now.difference(_lastQueryTime) >= _queryInterval) {
if (_curPeers.isNotEmpty) {
bind.queryOnlines(ids: _curPeers.toList(growable: false));
@@ -286,14 +304,14 @@ class _PeersViewState extends State<_PeersView> with WindowListener {
_queryOnlines(bool isLoadEvent) {
if (_curPeers.isNotEmpty) {
bind.queryOnlines(ids: _curPeers.toList(growable: false));
- _lastQueryPeers = {..._curPeers};
- if (isLoadEvent) {
- _lastChangeTime = DateTime.now();
- } else {
- _lastQueryTime = DateTime.now().subtract(_queryInterval);
- }
_queryCount = 0;
}
+ _lastQueryPeers = {..._curPeers};
+ if (isLoadEvent) {
+ _lastChangeTime = DateTime.now();
+ } else {
+ _lastQueryTime = DateTime.now().subtract(_queryInterval);
+ }
}
Future<List<Peer>>? matchPeers(
diff --git a/flutter/lib/models/model.dart b/flutter/lib/models/model.dart
index b10488b29..a9962a58a 100644
--- a/flutter/lib/models/model.dart
+++ b/flutter/lib/models/model.dart
@@ -384,7 +384,7 @@ class FfiModel with ChangeNotifier {
} else if (name == 'use_texture_render') {
_handleUseTextureRender(evt, sessionId, peerId);
} else {
- debugPrint('Unknown event name: $name');
+ debugPrint('Event is not handled in the fixed branch: $name');
}
};
}