Browse Source

[new]修复引力引擎问题

zk 2 tháng trước cách đây
mục cha
commit
0aa109d790
1 tập tin đã thay đổi với 13 bổ sung20 xóa
  1. 13 20
      lib/sdk/gravity/gravity_helper.dart

+ 13 - 20
lib/sdk/gravity/gravity_helper.dart

@@ -20,12 +20,15 @@ class GravityHelper {
   static const String tag = 'GravityHelper';
   static const String _keyCurrentDeviceId = "current_device_id";
   static const bool _isShowToast = false;
-  static CancelableFuture<bool>? _initFuture;
   static String? _currentClientId;
-
   static bool? _isFromPromote;
+  static bool isInit = false;
 
   static init() {
+    if (!isInit) {
+      return;
+    }
+    isInit = true;
     _initialize(false);
     _uploadClientId();
   }
@@ -44,17 +47,18 @@ class GravityHelper {
 
   static _initialize(bool refreshDeviceId,
       {GravitySuccessCallback? callback}) async {
-    _initFuture?.cancel();
-    _initFuture = AsyncUtil.retryWithExponentialBackoff<bool>(() async {
+    AsyncUtil.retryWithExponentialBackoff<bool>(() async {
       String deviceId = await _getDeviceId(refreshDeviceId);
       CancelableFuture<bool> initFuture = _gravityInitialize(deviceId);
-      _initFuture = initFuture;
       return await initFuture;
-    }, 5);
-    _initFuture?.then((isPromote) {
+    }, 5)
+        .then((isPromote) {
       _isFromPromote = isPromote;
       callback?.call();
     }).catchError((error) {
+      if (error is CancelledError) {
+        return;
+      }
       _initialize(refreshDeviceId, callback: callback);
     });
   }
@@ -98,20 +102,9 @@ class GravityHelper {
     }
   }
 
-  static void onLogin() {
-    _clearCurrentDeviceId();
-    _initialize(true, callback: () {
-      if (_currentClientId != null) {
-        GravityEngine.login(_currentClientId!);
-      }
-    });
-  }
+  static void onLogin() {}
 
-  static void onLogout() async {
-    _currentClientId = null;
-    await GravityEngine.logout();
-    _initialize(false, callback: null);
-  }
+  static void onLogout() async {}
 
   static void _clearCurrentDeviceId() {
     KVUtil.putString(_keyCurrentDeviceId, null);