new fetchID and periodic_immediate
This commit is contained in:
parent
60dcd96874
commit
6e1f8f0294
@ -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();
|
||||
});
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ class _ConnectionPageState extends State<ConnectionPage>
|
||||
}
|
||||
}();
|
||||
}
|
||||
_updateTimer = Timer.periodic(Duration(seconds: 1), (timer) {
|
||||
_updateTimer = periodic_immediate(Duration(seconds: 1), () async {
|
||||
updateStatus();
|
||||
});
|
||||
_idFocusNode.addListener(() {
|
||||
|
@ -461,7 +461,8 @@ class _DesktopHomePageState extends State<DesktopHomePage>
|
||||
void initState() {
|
||||
super.initState();
|
||||
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();
|
||||
if (updateUrl != url) {
|
||||
updateUrl = url;
|
||||
|
@ -324,7 +324,6 @@ class ServerModel with ChangeNotifier {
|
||||
parent.target?.ffiModel.updateEventListener("");
|
||||
await parent.target?.invokeMethod("init_service");
|
||||
await bind.mainStartService();
|
||||
_fetchID();
|
||||
updateClientState();
|
||||
if (!Platform.isLinux) {
|
||||
// current linux is not supported
|
||||
@ -360,26 +359,12 @@ class ServerModel with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
_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();
|
||||
if (id.isEmpty) {
|
||||
continue;
|
||||
} else {
|
||||
_serverId.id = id;
|
||||
}
|
||||
|
||||
debugPrint("fetch id again at $count:id:${_serverId.id}");
|
||||
count++;
|
||||
if (_serverId.id != old) {
|
||||
break;
|
||||
}
|
||||
fetchID() async {
|
||||
final id = await bind.mainGetMyId();
|
||||
if (id != _serverId.id) {
|
||||
_serverId.id = id;
|
||||
notifyListeners();
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
changeStatue(String name, bool value) {
|
||||
|
Loading…
Reference in New Issue
Block a user