|
|
|
@ -14,6 +14,8 @@ import 'package:ble_service/ble_service.dart'; |
|
|
|
class PairingController extends GetxController { |
|
|
|
static PairingController get to => Get.find(); |
|
|
|
|
|
|
|
// 需要设备 |
|
|
|
final bool needdeivice = false; |
|
|
|
// 状态标志 |
|
|
|
final isLoading = false.obs; |
|
|
|
|
|
|
|
@ -243,7 +245,8 @@ class PairingController extends GetxController { |
|
|
|
await _checkDevicePairingStatus(); |
|
|
|
|
|
|
|
// 如果还未配对且设备合规,启动配对流程 |
|
|
|
if (!_companionAssociated.value && _isValidDeviceName(currentDevice!.name)) { |
|
|
|
if (!_companionAssociated.value && |
|
|
|
_isValidDeviceName(currentDevice!.name)) { |
|
|
|
_startCompanionAssociation(); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -271,9 +274,11 @@ class PairingController extends GetxController { |
|
|
|
|
|
|
|
if (isDeviceConnected) { |
|
|
|
if (Platform.isAndroid && !isCompanionAssociated && _isAssociating) { |
|
|
|
statusDescription.value = '${'associatingDevice'.tr} ${currentDevice!.name}'; |
|
|
|
statusDescription.value = |
|
|
|
'${'associatingDevice'.tr} ${currentDevice!.name}'; |
|
|
|
} else { |
|
|
|
statusDescription.value = '${'connectedDevice'.tr} ${currentDevice!.name}'; |
|
|
|
statusDescription.value = |
|
|
|
'${'connectedDevice'.tr} ${currentDevice!.name}'; |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
@ -286,7 +291,6 @@ class PairingController extends GetxController { |
|
|
|
statusDescription.value = 'notFound'.tr; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// 启动Companion设备关联流程 |
|
|
|
Future<void> _startCompanionAssociation() async { |
|
|
|
// 如果不是Android平台,已跳转,已完成关联或正在进行关联,直接返回 |
|
|
|
@ -339,7 +343,6 @@ class PairingController extends GetxController { |
|
|
|
await _bleService.registerBackgroundScan( |
|
|
|
macAddress: currentDevice!.address); |
|
|
|
|
|
|
|
|
|
|
|
// 关联成功后跳转 |
|
|
|
_autoNavigateToHome(); |
|
|
|
} else { |
|
|
|
@ -359,7 +362,7 @@ class PairingController extends GetxController { |
|
|
|
|
|
|
|
/// 自动跳转到主页 |
|
|
|
Future<void> _autoNavigateToHome() async { |
|
|
|
if (_isNavigatingToHome || !isDeviceConnected) return; |
|
|
|
if (needdeivice && (_isNavigatingToHome || !isDeviceConnected)) return; |
|
|
|
|
|
|
|
// 启动BLE后台服务 |
|
|
|
await _startAgentService(); |
|
|
|
@ -375,7 +378,7 @@ class PairingController extends GetxController { |
|
|
|
/// 启动BLE后台服务 |
|
|
|
Future<void> _startAgentService() async { |
|
|
|
try { |
|
|
|
if (!isDeviceConnected) return; |
|
|
|
if (needdeivice && !isDeviceConnected) return; |
|
|
|
|
|
|
|
final result = await BleManager.to.startAgentService(); |
|
|
|
Logger.info(result ? 'BLE后台服务启动成功' : 'BLE后台服务启动失败'); |
|
|
|
@ -435,7 +438,7 @@ class PairingController extends GetxController { |
|
|
|
} |
|
|
|
|
|
|
|
/// 跳过连接 |
|
|
|
void skipConnecting() async{ |
|
|
|
void skipConnecting() async { |
|
|
|
// 启动BLE后台服务 |
|
|
|
await _startAgentService(); |
|
|
|
_isNavigatingToHome = true; |
|
|
|
|