构建初步的设备运行悬浮状态栏,已实现初步的的悬浮和开关功能。
优化了登录链条适配多种用户的登录操作
This commit is contained in:
@@ -8,6 +8,8 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:maibu_satabot_v2/core/consts/tcp_consts.dart';
|
||||
import 'package:maibu_satabot_v2/core/network/tcp/tcp_client.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/domain/entities/device_entity.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/domain/repositories/device_repository.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/presentation/bloc/device_status_bloc.dart';
|
||||
@@ -27,6 +29,7 @@ class RemoteControlCubit extends Cubit<RemoteControlState> {
|
||||
final RemoteControlRepository _repository;
|
||||
final RequestControlPermissionUseCase _requestControlPermissionUseCase;
|
||||
final DeviceRepository _deviceRepository; // 🔥 注入设备仓库
|
||||
final TcpClient tcpClient; // 🔥 注入TCP客户端
|
||||
Timer? _timer;
|
||||
StreamSubscription? _kickOutSub; // 新增:用于管理监听生命周期
|
||||
final NetMessageDispatcher dispatcher;
|
||||
@@ -56,6 +59,7 @@ class RemoteControlCubit extends Cubit<RemoteControlState> {
|
||||
this._repository,
|
||||
this._requestControlPermissionUseCase,
|
||||
this._deviceRepository, // 🔥 注入
|
||||
this.tcpClient, // 🔥 注入TCP客户端
|
||||
this.dispatcher,
|
||||
this.deviceStatusBloc, // 🔥 注入
|
||||
) : super(
|
||||
@@ -937,25 +941,49 @@ class RemoteControlCubit extends Cubit<RemoteControlState> {
|
||||
}
|
||||
|
||||
/// 🔥 设置待控制的设备(从机器人列表点击进入时调用)
|
||||
void setTargetDevice(DeviceEntity device) {
|
||||
// debugPrint('🎯 [RemoteControl] 设置待控制设备 ${device.deviceName}');
|
||||
// _logger.logWithLevel('🎯 [RemoteControl] 设置待控制设备 ${device.deviceName}');
|
||||
void setTargetDevice(DeviceEntity device) async {
|
||||
debugPrint('🎯 [RemoteControl] ========== 开始设置目标设备 ==========');
|
||||
debugPrint('🎯 [RemoteControl] 设备名称: ${device.deviceName}');
|
||||
debugPrint('🎯 [RemoteControl] 当前TCP状态: ${tcpClient.isConnected ? "已连接" : "未连接"}');
|
||||
|
||||
// 🔥 关键修改:选择设备时才连接TCP
|
||||
if (!tcpClient.isConnected) {
|
||||
debugPrint('🔌 [RemoteControl] TCP未连接,开始建立连接...');
|
||||
try {
|
||||
debugPrint('🔌 [RemoteControl] 调用 connectBySwitch,目标: ${device.deviceName}');
|
||||
await tcpClient.connectBySwitch(
|
||||
host: TCPConsts.TCP_IP,
|
||||
port: TCPConsts.TCP_PORT,
|
||||
deviceName: device.deviceName,
|
||||
);
|
||||
debugPrint('✅ [RemoteControl] TCP连接成功!');
|
||||
debugPrint('✅ [RemoteControl] 认证流程已完成(包含发送0x03认证包和设备订阅)');
|
||||
} catch (e) {
|
||||
debugPrint('❌ [RemoteControl] TCP连接失败: $e');
|
||||
debugPrint('⚠️ [RemoteControl] 将继续执行,允许用户进入页面(但无实时数据)');
|
||||
// 即使TCP连接失败,也继续设置设备,允许用户进入页面
|
||||
}
|
||||
} else {
|
||||
debugPrint('✅ [RemoteControl] TCP已连接,跳过连接步骤');
|
||||
debugPrint('🔄 [RemoteControl] 将直接切换设备订阅');
|
||||
}
|
||||
|
||||
// 🔥 通知后端订阅该设备
|
||||
debugPrint('📡 [RemoteControl] 开始HTTP切换设备订阅...');
|
||||
_deviceRepository.switchDevice("app", device.deviceName).then((result) {
|
||||
result.fold(
|
||||
(failure) {
|
||||
// debugPrint('>>> [RemoteControl] 切换设备失败: ${failure.message}');
|
||||
// _logger.logWithLevel('>>> [RemoteControl] 切换设备失败: ${failure.message}');
|
||||
debugPrint('❌ [RemoteControl] HTTP切换设备失败: ${failure.message}');
|
||||
},
|
||||
(success) {
|
||||
// debugPrint('>>> [RemoteControl] 切换设备成功, code: $success');
|
||||
// _logger.logWithLevel('>>> [RemoteControl] 切换设备成功, code: $success');
|
||||
debugPrint('✅ [RemoteControl] HTTP切换设备成功, code: $success');
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
debugPrint('📦 [RemoteControl] 更新targetDevice状态');
|
||||
emit(state.copyWith(targetDevice: device));
|
||||
debugPrint('🎯 [RemoteControl] ========== 目标设备设置完成 ==========');
|
||||
}
|
||||
|
||||
/// 🔥 清除待控制设备(退出远程控制页时调用)
|
||||
|
||||
Reference in New Issue
Block a user