Commit 71aab30ebfd469a43a6add20ed9c5f0a6cd939d9
1 parent
2a36f177
feat(ui):登录进入app前向原生同步信息的部分代码不用await
Showing
3 changed files
with
15 additions
and
5 deletions
| @@ -47,7 +47,7 @@ abstract final class AppBootstrap { | @@ -47,7 +47,7 @@ abstract final class AppBootstrap { | ||
| 47 | // `UserPreferencesStorage.init` runs before GetX dependencies exist. Sync | 47 | // `UserPreferencesStorage.init` runs before GetX dependencies exist. Sync |
| 48 | // here so every cold start invokes native `updateLoginInfo` after the | 48 | // here so every cold start invokes native `updateLoginInfo` after the |
| 49 | // PlatformHostApi and HealthRawDataCoreService are ready. | 49 | // PlatformHostApi and HealthRawDataCoreService are ready. |
| 50 | - await userPreferencesStorage.syncLoginInfoToNative(); | 50 | + unawaited(userPreferencesStorage.syncLoginInfoToNative()); |
| 51 | 51 | ||
| 52 | NativeHealthDataUpdateBridge.initialize(); | 52 | NativeHealthDataUpdateBridge.initialize(); |
| 53 | 53 | ||
| @@ -88,7 +88,7 @@ abstract final class AppBootstrap { | @@ -88,7 +88,7 @@ abstract final class AppBootstrap { | ||
| 88 | localStorage: local, | 88 | localStorage: local, |
| 89 | ).dependencies(); | 89 | ).dependencies(); |
| 90 | 90 | ||
| 91 | - await userPreferencesStorage.syncLoginInfoToNative(); | 91 | + unawaited(userPreferencesStorage.syncLoginInfoToNative()); |
| 92 | 92 | ||
| 93 | NativeHealthDataUpdateBridge.initialize(); | 93 | NativeHealthDataUpdateBridge.initialize(); |
| 94 | // 2. 后台无 UI,不需要初始化全局 Loading 弹窗 | 94 | // 2. 后台无 UI,不需要初始化全局 Loading 弹窗 |
| @@ -641,7 +641,9 @@ class LoginController extends GetxController { | @@ -641,7 +641,9 @@ class LoginController extends GetxController { | ||
| 641 | try { | 641 | try { |
| 642 | if (Get.isRegistered<AppEnvironmentConfig>()) { | 642 | if (Get.isRegistered<AppEnvironmentConfig>()) { |
| 643 | var env = Get.find<AppEnvironmentConfig>(); | 643 | var env = Get.find<AppEnvironmentConfig>(); |
| 644 | - await AppPlatformHostApi().updateLoginInfo( | 644 | + unawaited( |
| 645 | + AppPlatformHostApi() | ||
| 646 | + .updateLoginInfo( | ||
| 645 | jsonEncode(UserPreferences( | 647 | jsonEncode(UserPreferences( |
| 646 | accessToken: accessToken, | 648 | accessToken: accessToken, |
| 647 | meUserInfo: me, | 649 | meUserInfo: me, |
| @@ -650,7 +652,12 @@ class LoginController extends GetxController { | @@ -650,7 +652,12 @@ class LoginController extends GetxController { | ||
| 650 | ? UserPreferencesVipInfo.fromVipInfo(vip) | 652 | ? UserPreferencesVipInfo.fromVipInfo(vip) |
| 651 | : null, | 653 | : null, |
| 652 | )), | 654 | )), |
| 653 | - env.serverBaseUrl); | 655 | + env.serverBaseUrl, |
| 656 | + ) | ||
| 657 | + .catchError((Object error, StackTrace stackTrace) { | ||
| 658 | + AppLogger.e('Native login info sync failed', error, stackTrace); | ||
| 659 | + }), | ||
| 660 | + ); | ||
| 654 | } | 661 | } |
| 655 | } on Exception catch (e) { | 662 | } on Exception catch (e) { |
| 656 | AppLogger.e(e); | 663 | AppLogger.e(e); |
| 1 | +import 'dart:async'; | ||
| 1 | import 'dart:convert'; | 2 | import 'dart:convert'; |
| 2 | 3 | ||
| 3 | import 'package:doublefeel_flutter/core/config/app_environment_config.dart'; | 4 | import 'package:doublefeel_flutter/core/config/app_environment_config.dart'; |
| @@ -144,7 +145,9 @@ class UserPreferencesStorage { | @@ -144,7 +145,9 @@ class UserPreferencesStorage { | ||
| 144 | vipInfo: vip != null ? UserPreferencesVipInfo.fromVipInfo(vip) : null, | 145 | vipInfo: vip != null ? UserPreferencesVipInfo.fromVipInfo(vip) : null, |
| 145 | ); | 146 | ); |
| 146 | await _persist(userInfo); | 147 | await _persist(userInfo); |
| 147 | - await _syncLoginInfoToNative(userInfo: userInfo); | 148 | + // Native login/health database synchronization is best effort and can |
| 149 | + // trigger expensive platform work. Do not hold the login transition for it. | ||
| 150 | + unawaited(_syncLoginInfoToNative(userInfo: userInfo)); | ||
| 148 | } | 151 | } |
| 149 | 152 | ||
| 150 | Future<void> clearPartnerUserInfo() async { | 153 | Future<void> clearPartnerUserInfo() async { |
-
Please register or login to post a comment