new fetchID and periodic_immediate

This commit is contained in:
rustdesk 2022-11-29 22:36:35 +08:00
parent 60dcd96874
commit 6e1f8f0294
4 changed files with 15 additions and 22 deletions

View File

@ -1403,3 +1403,10 @@ void onActiveWindowChanged() async {
} }
} }
} }
Timer periodic_immediate(Duration duration, Future<void> Function() callback) {
Future.delayed(Duration.zero, callback);
return Timer.periodic(duration, (timer) async {
await callback();
});
}

View File

@ -61,7 +61,7 @@ class _ConnectionPageState extends State<ConnectionPage>
} }
}(); }();
} }
_updateTimer = Timer.periodic(Duration(seconds: 1), (timer) { _updateTimer = periodic_immediate(Duration(seconds: 1), () async {
updateStatus(); updateStatus();
}); });
_idFocusNode.addListener(() { _idFocusNode.addListener(() {

View File

@ -461,7 +461,8 @@ class _DesktopHomePageState extends State<DesktopHomePage>
void initState() { void initState() {
super.initState(); super.initState();
bind.mainStartGrabKeyboard(); bind.mainStartGrabKeyboard();
_updateTimer = Timer.periodic(const Duration(seconds: 1), (timer) async { _updateTimer = periodic_immediate(const Duration(seconds: 1), () async {
await gFFI.serverModel.fetchID();
final url = await bind.mainGetSoftwareUpdateUrl(); final url = await bind.mainGetSoftwareUpdateUrl();
if (updateUrl != url) { if (updateUrl != url) {
updateUrl = url; updateUrl = url;

View File

@ -324,7 +324,6 @@ class ServerModel with ChangeNotifier {
parent.target?.ffiModel.updateEventListener(""); parent.target?.ffiModel.updateEventListener("");
await parent.target?.invokeMethod("init_service"); await parent.target?.invokeMethod("init_service");
await bind.mainStartService(); await bind.mainStartService();
_fetchID();
updateClientState(); updateClientState();
if (!Platform.isLinux) { if (!Platform.isLinux) {
// current linux is not supported // current linux is not supported
@ -360,27 +359,13 @@ class ServerModel with ChangeNotifier {
} }
} }
_fetchID() async { fetchID() async {
final old = _serverId.id;
var count = 0;
const maxCount = 10;
while (count < maxCount) {
await Future.delayed(Duration(seconds: 1));
final id = await bind.mainGetMyId(); final id = await bind.mainGetMyId();
if (id.isEmpty) { if (id != _serverId.id) {
continue;
} else {
_serverId.id = id; _serverId.id = id;
}
debugPrint("fetch id again at $count:id:${_serverId.id}");
count++;
if (_serverId.id != old) {
break;
}
}
notifyListeners(); notifyListeners();
} }
}
changeStatue(String name, bool value) { changeStatue(String name, bool value) {
debugPrint("changeStatue value $value"); debugPrint("changeStatue value $value");