diff --git a/lib/data/services/bluetooth_manager.dart b/lib/data/services/bluetooth_manager.dart index 654cfa603..4c4f58ffd 100644 --- a/lib/data/services/bluetooth_manager.dart +++ b/lib/data/services/bluetooth_manager.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'package:get/get.dart'; import 'package:classic_bluetooth/classic_bluetooth.dart'; import '../../core/utils/logger.dart'; +import '../../routes/app_routes.dart'; // 重新导出蓝牙设备类型,让外部可以通过BluetoothManager访问 export 'package:classic_bluetooth/classic_bluetooth.dart' show BluetoothDevice; @@ -58,6 +59,7 @@ class BluetoothManager extends GetxService { try { _bluetoothSubscription = ClassicBluetooth.events.listen( (event) { + print("_setupBluetoothListener$event"); if (event.type == 'stateChanged' && event.state != null) { _bluetoothState.value = event.state!; Logger.info('蓝牙状态变更: ${event.state}'); @@ -70,9 +72,15 @@ class BluetoothManager extends GetxService { // 直接从事件中获取设备信息 final newDevice = event.device!; - // 更新当前设备 currentDeviceRx.value = newDevice; + // 检查当前是否在OTA升级界面,如果是则不跳转 + if (!_isInOtaUpgradePage()) { + Get.toNamed(Routes.pairing, arguments: newDevice); + } else { + Logger.info('当前在OTA升级界面,跳过配对页面跳转'); + } + // 正常模式:更新当前设备并触发监听器 Logger.info('经典蓝牙设备已连接: ${newDevice.name} (${newDevice.address})'); } else if (event.type == 'deviceDisconnected' && event.device != null) { @@ -138,4 +146,16 @@ class BluetoothManager extends GetxService { return false; } } + + /// 检查当前是否在OTA升级界面 + /// 返回true表示当前在OTA界面,不应该跳转到配对页面 + bool _isInOtaUpgradePage() { + try { + final currentRoute = Get.currentRoute; + return currentRoute == Routes.OTA_UPGRADE; + } catch (e) { + Logger.error('检查当前路由失败: ${e.toString()}'); + return false; + } + } } diff --git a/lib/modules/ota_upgrade/controllers/ota_upgrade_controller.dart b/lib/modules/ota_upgrade/controllers/ota_upgrade_controller.dart index 9e56c02d8..f306bde15 100644 --- a/lib/modules/ota_upgrade/controllers/ota_upgrade_controller.dart +++ b/lib/modules/ota_upgrade/controllers/ota_upgrade_controller.dart @@ -123,6 +123,10 @@ class OtaUpgradeController extends GetxController { /// 开始更新流程的公共方法 /// 供视图调用的更新入口点 Future startUpdate() async { + //立即给用户状态反馈 + showDetailedStatus.value = true; + detailedStatus.value = '正在检查设备状态...'; + await _startUpdateProcess(); } diff --git a/lib/modules/translation/controllers/translation_controller.dart b/lib/modules/translation/controllers/translation_controller.dart index 9b54119e4..f1bfff331 100644 --- a/lib/modules/translation/controllers/translation_controller.dart +++ b/lib/modules/translation/controllers/translation_controller.dart @@ -116,6 +116,11 @@ class TranslationController extends GetxController with WidgetsBindingObserver { StreamSubscription? _voiceInteractionSubscription; Timer? _translationDebounceTimer; + // 播放防重复机制 + String? _lastPlayedItemKey; // 最后播放的项目标识 + int _lastPlayTime = 0; // 最后播放时间 + static const int _playDebounceInterval = 500; // 防抖间隔:500毫秒 + // 底部控制栏高度 double _bottomBarHeight = 0.0; @@ -1083,7 +1088,30 @@ class TranslationController extends GetxController with WidgetsBindingObserver { Future playTranslationItem(TranslationItem item) async { if (item.translatedText.isEmpty) return; + // 防重复点击:如果短时间内重复点击同一项,忽略后续点击 + final currentTime = DateTime.now().millisecondsSinceEpoch; + final itemKey = + '${item.sessionId}_${item.timestamp.millisecondsSinceEpoch}'; + + // 检查是否是重复点击同一项 + if (_lastPlayedItemKey == itemKey && + currentTime - _lastPlayTime < _playDebounceInterval) { + Logger.info('防重复播放:忽略短时间内的重复点击'); + return; + } + + // 如果正在播放,先停止当前播放 + if (_ttsService.isSpeaking) { + await _ttsService.stop(); + // 短暂延迟确保停止完成 + await Future.delayed(const Duration(milliseconds: 100)); + } + try { + // 更新播放记录 + _lastPlayedItemKey = itemKey; + _lastPlayTime = currentTime; + final voiceName = _languageManager.getTtsVoiceNameByAsrCode(item.targetLanguageCode) ?? 'en-US-AriaNeural'; @@ -1100,7 +1128,29 @@ class TranslationController extends GetxController with WidgetsBindingObserver { Future playText(String text, {String? languageCode}) async { if (text.isEmpty) return; + // 防重复点击:基于文本内容和语言代码生成唯一标识 + final currentTime = DateTime.now().millisecondsSinceEpoch; + final textKey = '${text}_${languageCode ?? targetLanguageCode.value}'; + + // 检查是否是重复点击同一文本 + if (_lastPlayedItemKey == textKey && + currentTime - _lastPlayTime < _playDebounceInterval) { + Logger.info('防重复播放:忽略短时间内的重复文本播放请求'); + return; + } + + // 如果正在播放,先停止当前播放 + if (_ttsService.isSpeaking) { + await _ttsService.stop(); + // 短暂延迟确保停止完成 + await Future.delayed(const Duration(milliseconds: 100)); + } + try { + // 更新播放记录 + _lastPlayedItemKey = textKey; + _lastPlayTime = currentTime; + final voiceName = languageCode != null ? _languageManager.getTtsVoiceNameByAsrCode(languageCode) ?? 'en-US-AriaNeural'