|
|
|
@ -1,6 +1,7 @@ |
|
|
|
import 'dart:async'; |
|
|
|
import 'package:get/get.dart'; |
|
|
|
import 'package:classic_bluetooth/classic_bluetooth.dart'; |
|
|
|
import 'package:get_storage/get_storage.dart'; |
|
|
|
import '../../core/utils/logger.dart'; |
|
|
|
import '../../routes/app_routes.dart'; |
|
|
|
import 'ble_manager.dart'; |
|
|
|
@ -21,6 +22,7 @@ class BluetoothManager extends GetxService { |
|
|
|
final Rx<BluetoothDevice?> currentDeviceRx = Rx<BluetoothDevice?>(null); |
|
|
|
BluetoothDevice? get currentDevice => currentDeviceRx.value; |
|
|
|
final BleManager _bleManager = Get.find<BleManager>(); |
|
|
|
final GetStorage _storage = GetStorage(); |
|
|
|
// 订阅 |
|
|
|
StreamSubscription<BluetoothEvent>? _bluetoothSubscription; |
|
|
|
|
|
|
|
@ -76,7 +78,8 @@ class BluetoothManager extends GetxService { |
|
|
|
currentDeviceRx.value = newDevice; |
|
|
|
|
|
|
|
// 检查当前是否在OTA升级界面,如果是则不跳转 |
|
|
|
if (!_isInOtaUpgradePage() && |
|
|
|
if (_isLoggedIn() && |
|
|
|
!_isInOtaUpgradePage() && |
|
|
|
!_bleManager.isConnected && |
|
|
|
Get.currentRoute != Routes.pairing) { |
|
|
|
Get.toNamed(Routes.pairing, arguments: newDevice); |
|
|
|
@ -161,4 +164,14 @@ class BluetoothManager extends GetxService { |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// 是否已登录 |
|
|
|
bool _isLoggedIn() { |
|
|
|
try { |
|
|
|
final token = _storage.read('logintoken'); |
|
|
|
return token != null && token is String && token.isNotEmpty; |
|
|
|
} catch (e) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|