simple refactor

Signed-off-by: dignow <linlong1265@gmail.com>
This commit is contained in:
dignow 2023-06-23 14:42:24 +08:00
parent 53cd380a23
commit 105a774135
2 changed files with 8 additions and 15 deletions

View File

@ -1,5 +1,6 @@
// main window right pane
import 'dart:async';
import 'dart:io';
import 'package:auto_size_text/auto_size_text.dart';
@ -34,6 +35,8 @@ class _ConnectionPageState extends State<ConnectionPage>
/// Nested scroll controller
final _scrollController = ScrollController();
Timer? _svcStatusTimer;
final RxBool _idInputFocused = false.obs;
final FocusNode _idFocusNode = FocusNode();
@ -54,7 +57,9 @@ class _ConnectionPageState extends State<ConnectionPage>
}
}();
}
stateGlobal.startSvcStatusTimer();
_svcStatusTimer = periodic_immediate(Duration(seconds: 1), () async {
stateGlobal.updateSvcStatus();
});
_idFocusNode.addListener(() {
_idInputFocused.value = _idFocusNode.hasFocus;
// select all to faciliate removing text, just following the behavior of address input of chrome
@ -67,7 +72,8 @@ class _ConnectionPageState extends State<ConnectionPage>
@override
void dispose() {
_idController.dispose();
stateGlobal.cancelSvcStatusTimer();
_svcStatusTimer?.cancel();
_svcStatusTimer = null;
windowManager.removeListener(this);
super.dispose();
}

View File

@ -10,7 +10,6 @@ import '../consts.dart';
import '../common.dart';
import './platform_model.dart';
import './user_model.dart';
enum SvcStatus { notReady, connecting, ready }
@ -27,7 +26,6 @@ class StateGlobal {
final svcStatus = SvcStatus.notReady.obs;
final svcIsUsingPublicServer = true.obs;
Timer? _svcStatusTimer;
// Use for desktop -> remote toolbar -> resolution
final Map<String, Map<int, String?>> _lastResolutionGroupValues = {};
@ -93,17 +91,6 @@ class StateGlobal {
}
}
startSvcStatusTimer() {
_svcStatusTimer = periodic_immediate(Duration(seconds: 1), () async {
updateSvcStatus();
});
}
cancelSvcStatusTimer() {
_svcStatusTimer?.cancel();
_svcStatusTimer = null;
}
updateSvcStatus() async {
final status =
jsonDecode(await bind.mainGetConnectStatus()) as Map<String, dynamic>;