From 30a5d1e0e1cd9d4d986efb2dbba90f32481c3fe9 Mon Sep 17 00:00:00 2001 From: 21pages Date: Sat, 27 Jul 2024 09:50:06 +0800 Subject: [PATCH] avoid call refreshCurrentUser twice at startup (#8848) refreshCurrentUser will be called at these 2 position: 1. runMainApp or runMobileApp in main.dart 2. when connect status is ready Both of these two happens at startup, when connect status is ready and startup time < 5 seconds, not call refreshCurrentUser Signed-off-by: 21pages --- flutter/lib/desktop/pages/connection_page.dart | 4 +++- flutter/lib/models/ab_model.dart | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/flutter/lib/desktop/pages/connection_page.dart b/flutter/lib/desktop/pages/connection_page.dart index 1403d4493..5b77c431b 100644 --- a/flutter/lib/desktop/pages/connection_page.dart +++ b/flutter/lib/desktop/pages/connection_page.dart @@ -34,6 +34,7 @@ class _OnlineStatusWidgetState extends State { final _svcStopped = Get.find(tag: 'stop-service'); final _svcIsUsingPublicServer = true.obs; Timer? _updateTimer; + final DateTime _appStartTime = DateTime.now(); double get em => 14.0; double? get height => bind.isIncomingOnly() ? null : em * 3; @@ -176,7 +177,8 @@ class _OnlineStatusWidgetState extends State { stateGlobal.svcStatus.value = SvcStatus.notReady; } else if (statusNum == 1) { stateGlobal.svcStatus.value = SvcStatus.ready; - if (preStatus != SvcStatus.ready) { + if (preStatus != SvcStatus.ready && + DateTime.now().difference(_appStartTime) > Duration(seconds: 5)) { gFFI.userModel.refreshCurrentUser(); } } else { diff --git a/flutter/lib/models/ab_model.dart b/flutter/lib/models/ab_model.dart index 8cd5cc922..c3fad6fe4 100644 --- a/flutter/lib/models/ab_model.dart +++ b/flutter/lib/models/ab_model.dart @@ -111,9 +111,9 @@ class AbModel { Future _pullAb( {required ForcePullAb? force, required bool quiet}) async { if (bind.isDisableAb()) return; - debugPrint("pullAb, force: $force, quiet: $quiet"); if (!gFFI.userModel.isLogin) return; if (force == null && listInitialized && current.initialized) return; + debugPrint("pullAb, force: $force, quiet: $quiet"); if (!listInitialized || force == ForcePullAb.listAndCurrent) { try { // Read personal guid every time to avoid upgrading the server without closing the main window