完成解决日志sentry日志代码被覆盖的问题

完成切换后台App获取列表和TCP连接后数据响应慢的问题。
This commit is contained in:
2026-03-06 13:52:14 +08:00
parent 3b7445e850
commit c39eb6037d
8 changed files with 183 additions and 43 deletions

View File

@@ -28,7 +28,7 @@ class AuthTcpDatasourceImpl implements AuthTcpDatasource {
@override
Future<void> sendAuthPacket() async {
if (!_tcpClient.isConnected) {
throw Exception('TCP 未连接,无法发送认证包');
throw Exception('TCP 未连接,无法发送认证包sendAuthPacket');
}
final user = await _userStorage.getUser();
@@ -40,7 +40,7 @@ class AuthTcpDatasourceImpl implements AuthTcpDatasource {
final token = user.token!;
final authString = '$username:app:$token';
debugPrint('🔑 [AuthTcp] 准备发送认证包:$authString');
debugPrint('🔑 sendAuthPacket[AuthTcp] 准备发送认证包:$authString');
final authBytes = utf8.encode(authString);
@@ -57,7 +57,7 @@ class AuthTcpDatasourceImpl implements AuthTcpDatasource {
..addByte(0xAB);
_tcpClient.sendRawBytes(builder.takeBytes()); // 假设 TcpClient 增加了此方法,或用 socket.add
debugPrint('✅ [AuthTcp] 认证包已发送');
debugPrint('✅ sendAuthPacket[AuthTcp] 认证包已发送');
// 获取用户设备列表
try {
@@ -70,36 +70,36 @@ class AuthTcpDatasourceImpl implements AuthTcpDatasource {
await eitherResult.fold(
(failure) {
// 处理失败:打印日志或抛出异常
debugPrint('❌ [AuthTcp] 获取设备列表失败:$failure');
debugPrint('❌ sendAuthPacket [AuthTcp] 获取设备列表失败:$failure');
throw Exception('获取设备列表失败:$failure');
},
(devices) async {
// 处理成功:devices 现在是真正的 List<DeviceEntity>
if (devices.isEmpty) {
debugPrint('⚠️ [AuthTcp] 当前用户无可用设备,跳过切换步骤');
debugPrint('⚠️ sendAuthPacket[AuthTcp] 当前用户无可用设备,跳过切换步骤');
return;
}
// 取第一个设备
final DeviceEntity targetDevice = devices.first;
debugPrint('📱 [AuthTcp] 准备切换至默认设备:${targetDevice.deviceName}');
debugPrint('📱 sendAuthPacket[AuthTcp] 准备切换至默认设备:${targetDevice.deviceName}');
// 切换设备 (同样,如果 switchDeviceUseCase 也返回 Either,也需要 fold 处理)
final switchResult = await switchDeviceUseCase.deviceRepository.switchDevice("app",targetDevice.deviceName);
await switchResult.fold(
(failure) {
debugPrint('❌ [AuthTcp] 切换设备失败:$failure');
debugPrint('❌ sendAuthPacket[AuthTcp] 切换设备失败:$failure');
throw Exception('切换设备失败:$failure');
},
(success) {
debugPrint('✅ [AuthTcp] 设备切换成功,服务端应开始推送数据');
debugPrint('✅ sendAuthPacket[AuthTcp] 设备切换成功,服务端应开始推送数据');
},
);
},
);
} catch (e) {
debugPrint('❌ [AuthTcp] 设备订阅流程异常:$e');
debugPrint('❌ sendAuthPacket[AuthTcp] 设备订阅流程异常:$e');
rethrow;
}
}