集成双 MQTT 客户端实现设备实时数据监控(未测试)
1.集成两个独立的 MQTT 客户端,支持 WebSocket 和 TCP 协议 2.实现无人机/机场 OSD 实时监控(ws://1.95.137.212:8083/mqtt) 3.实现任务状态消息订阅(tcp://1.95.137.212:59020) 4.采用清洁架构设计,分层清晰(Domain → Data → Presentation)
This commit is contained in:
@@ -15,6 +15,7 @@ import 'package:maibu_satabot_v2/core/update/update_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/core/update/version_check_service.dart';
|
||||
import 'package:maibu_satabot_v2/core/update/update_dialog.dart';
|
||||
import 'package:maibu_satabot_v2/core/update/update_state.dart';
|
||||
import 'package:maibu_satabot_v2/core/network/mqtt/mqtt_manager.dart';
|
||||
import 'package:maibu_satabot_v2/features/auth/presentation/bloc/auth_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/presentation/bloc/devices_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/main_container/presentation/cubit/tab_config_cubit.dart';
|
||||
@@ -26,6 +27,7 @@ import 'core/localization/locale_cubit.dart';
|
||||
import 'features/auth/presentation/bloc/auth_state.dart';
|
||||
import 'features/auth/presentation/bloc/login_cubit.dart';
|
||||
import 'features/devices/presentation/bloc/device_status_bloc.dart';
|
||||
import 'features/devices/presentation/bloc/device_task_cubit.dart'; // 🔥 添加 DeviceTaskCubit
|
||||
import 'features/home/presentation/bloc/permission_request_bloc.dart';
|
||||
import 'features/remote_control/presentation/bloc/remote_control_cubit.dart';
|
||||
|
||||
@@ -43,6 +45,11 @@ void main() async {
|
||||
await logger.init();
|
||||
Bloc.observer = AppBlocObserver(logger);
|
||||
|
||||
// 🔥 初始化 MQTT 连接(异步,不阻塞启动)
|
||||
MqttManager().initialize().catchError((e) {
|
||||
debugPrint('⚠️ [Main] MQTT 初始化失败,但不影响应用启动: $e');
|
||||
});
|
||||
|
||||
// ⚠️ 注意:不要在启动时清除补丁版本记录!
|
||||
// 补丁版本记录只在整包更新成功后才清除
|
||||
// 如果在启动时清除,会导致差量更新后划掉App再进入时循环更新
|
||||
@@ -73,7 +80,16 @@ class MyApp extends StatelessWidget {
|
||||
create: (_) {
|
||||
final user = sl<AppUserCubit>().state.user;
|
||||
final devicesCubit = sl<DevicesCubit>();
|
||||
if (user != null) devicesCubit.fetchAllDevices(user.username);
|
||||
|
||||
// 🔥 修复:检查是否已有 targetDevice,如果有则不需要加载设备列表
|
||||
final remoteControlCubit = sl<RemoteControlCubit>();
|
||||
if (user != null && remoteControlCubit.state.targetDevice == null) {
|
||||
debugPrint('📱 [Main] 无 targetDevice,开始加载设备列表');
|
||||
devicesCubit.fetchAllDevices(user.username);
|
||||
} else if (user != null) {
|
||||
debugPrint('✅ [Main] 已有 targetDevice: ${remoteControlCubit.state.targetDevice!.deviceName},跳过设备列表加载');
|
||||
}
|
||||
|
||||
return devicesCubit;
|
||||
},
|
||||
),
|
||||
@@ -89,6 +105,9 @@ class MyApp extends StatelessWidget {
|
||||
BlocProvider<RemoteControlCubit>(
|
||||
create: (_) => sl<RemoteControlCubit>(),
|
||||
),
|
||||
BlocProvider<DeviceTaskCubit>(
|
||||
create: (_) => sl<DeviceTaskCubit>(),
|
||||
),
|
||||
],
|
||||
child: BlocBuilder<LocaleCubit, Locale>(
|
||||
bloc: localeCubit,
|
||||
|
||||
Reference in New Issue
Block a user