1:修复远程遥控控制状态显示不正确的问题
2:更换端口映射为测试服的8081-59003,9001-59004
This commit is contained in:
@@ -5,6 +5,7 @@ import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
|
||||
import 'package:maibu_satabot_v2/core/consts/tcp_consts.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
|
||||
@@ -129,18 +130,23 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
// 🔥 离开安全模式:启动 90 秒倒计时
|
||||
GetIt.I<AuthCubit>().exitSafeMode();
|
||||
|
||||
// 释放远程控制权限
|
||||
_cubit.releasePermission("app");
|
||||
//print("远程控制要推出啦");
|
||||
//final deviceState = _devicesCubit?.state;
|
||||
//if (deviceState?.selectedDevice != null) {
|
||||
// _cubit.releasePermission("app");
|
||||
// }
|
||||
// 释放远程控制权限(type=2:退出远程遥控页面释放)
|
||||
final deviceId = _cubit.state.targetDevice?.deviceName;
|
||||
if (deviceId != null && deviceId.isNotEmpty) {
|
||||
_cubit.releasePermission(deviceId: deviceId, type: 2).then((success) {
|
||||
CapsuleToast.show(
|
||||
success ? '已释放远程控制权限' : '控制权限释放失败',
|
||||
showCheck: success,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
_permissionSubscription?.cancel(); // 🔥 取消订阅
|
||||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||
_cubit.stopControlLoop();
|
||||
// 🔥 重置权限状态,避免单例 hasPermission 残留导致下次进入不再查询接口
|
||||
_cubit.resetPermissionState();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -149,7 +155,6 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
// 🔥 只监听 RemoteControlCubit,避免其他状态变化导致频繁 rebuild
|
||||
final remoteCubit = context.read<RemoteControlCubit>();
|
||||
final targetDevice = remoteCubit.state.targetDevice;
|
||||
final hasPermission = remoteCubit.state.hasPermission;
|
||||
|
||||
// 🔥 调试日志:检查设备状态
|
||||
debugPrint('🔍 [RemoteControlPage] build - targetDevice: ${targetDevice?.deviceName}');
|
||||
@@ -159,26 +164,22 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
return _buildOfflineScaffold();
|
||||
}
|
||||
|
||||
// 🔥 只在没有权限时自动请求,避免重复调用
|
||||
if (!hasPermission && _isLoadingPermission) {
|
||||
// 🔥 只使用 targetDevice
|
||||
final deviceName = remoteCubit.state.targetDevice?.deviceName;
|
||||
|
||||
if (deviceName != null && deviceName.isNotEmpty) {
|
||||
// debugPrint('🔑 [RemoteControl] 检测到无权限,自动发送权限请求 - deviceName: $deviceName');
|
||||
setState(() => _isLoadingPermission = false); // 🔥 标记为已请求
|
||||
remoteCubit.requestControlPermissionS(deviceName, "app").then((_) {
|
||||
if (mounted) {
|
||||
setState(() => _isLoadingPermission = false); // 🔥 请求完成后重置
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// debugPrint('❌ [RemoteControl] 无法发送权限请求 - targetDevice 为空');
|
||||
// debugPrint(' targetDevice: ${remoteCubit.state.targetDevice}');
|
||||
setState(() => _isLoadingPermission = false);
|
||||
}
|
||||
} else {
|
||||
// debugPrint('✅ [RemoteControl] 已有权限或已请求过,跳过');
|
||||
// 🔥 进入页面只查询一次真实权限状态(不抢占),按接口 remoteControl 如实展示
|
||||
if (_isLoadingPermission) {
|
||||
// 直接置标志位,不在 build 期间调用 setState
|
||||
_isLoadingPermission = false;
|
||||
final deviceName = targetDevice.deviceName;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted && deviceName.isNotEmpty) {
|
||||
debugPrint('🔑 [RemoteControlPage] 进入页面,仅查询权限状态 - deviceName: $deviceName');
|
||||
remoteCubit.requestControlPermissionS(
|
||||
deviceName,
|
||||
'app',
|
||||
source: '进入页面查询',
|
||||
grabControl: false,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
|
||||
Reference in New Issue
Block a user