fix:增加发送过程中超时的问题
This commit is contained in:
parent
b06e3b61c8
commit
617c7ad9b6
@ -34,6 +34,12 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
|
||||
final SpeechLanguageSettingsState state = SpeechLanguageSettingsState();
|
||||
StreamSubscription<Reply>? _replySubscription;
|
||||
|
||||
// 超时定时器(用于检测是否未收到回复)
|
||||
Timer? _sendTimeoutTimer;
|
||||
|
||||
// 超时标志位(可选,防止重复处理)
|
||||
bool _isTimeout = false;
|
||||
|
||||
@override
|
||||
void onInit() async {
|
||||
super.onInit();
|
||||
@ -273,7 +279,39 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
|
||||
_sendNextPackage();
|
||||
}
|
||||
|
||||
void _handleSendTimeout() {
|
||||
_isTimeout = true; // 标记超时状态
|
||||
dismissEasyLoading();
|
||||
cancelBlueConnetctToastTimer();
|
||||
showBlueConnetctToast();
|
||||
|
||||
// 重置状态,避免后续错误操作
|
||||
state.voiceSubcontractingIndex = 0;
|
||||
state.voiceSubcontractingCount = 0;
|
||||
state.data = null;
|
||||
state.progress.value = 0.0;
|
||||
_isTimeout = false; // 标记超时状态
|
||||
}
|
||||
|
||||
void _sendNextPackage() async {
|
||||
// 若已超时,直接返回
|
||||
if (_isTimeout) return;
|
||||
|
||||
// 取消上一次未完成的定时器(避免重复触发)
|
||||
_sendTimeoutTimer?.cancel();
|
||||
|
||||
// 检查是否已完成所有分包发送
|
||||
if (state.voiceSubcontractingIndex >= state.voiceSubcontractingCount) {
|
||||
print('所有分包已发送完成');
|
||||
state.progress.value = 1.0;
|
||||
return;
|
||||
}
|
||||
|
||||
// 启动 3 秒超时定时器
|
||||
_sendTimeoutTimer = Timer(Duration(seconds: 3), () {
|
||||
_handleSendTimeout(); // 触发超时处理
|
||||
});
|
||||
|
||||
if (state.voiceSubcontractingIndex >= state.voiceSubcontractingCount) {
|
||||
print('所有分包已发送完成');
|
||||
state.progress.value = 1.0; // 发送完成
|
||||
@ -320,6 +358,9 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
|
||||
|
||||
void _handlerVoicePackageConfigureProcess(
|
||||
VoicePackageConfigureProcessReply reply) {
|
||||
// 取消超时定时器(已收到回复,无需继续等待)
|
||||
_sendTimeoutTimer?.cancel();
|
||||
_isTimeout = false; // 重置超时标志
|
||||
final int status = reply.data[2];
|
||||
switch (status) {
|
||||
case 0x00:
|
||||
@ -386,7 +427,6 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
|
||||
Future<void> _executeLogic(
|
||||
VoicePackageConfigureConfirmationReply reply) async {
|
||||
await _handlerVoicePackageConfigureConfirmation(reply);
|
||||
dismissEasyLoading();
|
||||
}
|
||||
|
||||
_handlerVoicePackageConfigureConfirmation(
|
||||
|
||||
@ -31,6 +31,11 @@ class LockVoiceSettingLogic extends BaseGetXController {
|
||||
LockVoiceSettingState state = LockVoiceSettingState();
|
||||
StreamSubscription<Reply>? _replySubscription;
|
||||
bool _isThrottled = false;
|
||||
// 超时定时器(用于检测是否未收到回复)
|
||||
Timer? _sendTimeoutTimer;
|
||||
|
||||
// 超时标志位(可选,防止重复处理)
|
||||
bool _isTimeout = false;
|
||||
|
||||
@override
|
||||
void onInit() async {
|
||||
@ -168,6 +173,9 @@ class LockVoiceSettingLogic extends BaseGetXController {
|
||||
|
||||
void _handlerVoicePackageConfigureProcess(
|
||||
VoicePackageConfigureProcessReply reply) {
|
||||
// 取消超时定时器(已收到回复,无需继续等待)
|
||||
_sendTimeoutTimer?.cancel();
|
||||
_isTimeout = false; // 重置超时标志
|
||||
final int status = reply.data[2];
|
||||
switch (status) {
|
||||
case 0x00:
|
||||
@ -300,8 +308,27 @@ class LockVoiceSettingLogic extends BaseGetXController {
|
||||
state.progress.value = 0.0; // 开始前重置进度
|
||||
_sendNextPackage();
|
||||
}
|
||||
void _handleSendTimeout() {
|
||||
_isTimeout = true; // 标记超时状态
|
||||
dismissEasyLoading();
|
||||
cancelBlueConnetctToastTimer();
|
||||
showBlueConnetctToast();
|
||||
|
||||
// 重置状态,避免后续错误操作
|
||||
state.voiceSubcontractingIndex = 0;
|
||||
state.voiceSubcontractingCount = 0;
|
||||
state.data = null;
|
||||
state.progress.value = 0.0;
|
||||
_isTimeout = false; // 标记超时状态
|
||||
}
|
||||
|
||||
void _sendNextPackage() {
|
||||
// 若已超时,直接返回
|
||||
if (_isTimeout) return;
|
||||
|
||||
// 取消上一次未完成的定时器(避免重复触发)
|
||||
_sendTimeoutTimer?.cancel();
|
||||
|
||||
if (state.voiceSubcontractingIndex >= state.voiceSubcontractingCount) {
|
||||
print('所有分包已发送完成');
|
||||
state.progress.value = 1.0; // 发送完成
|
||||
@ -309,6 +336,12 @@ class LockVoiceSettingLogic extends BaseGetXController {
|
||||
return;
|
||||
}
|
||||
|
||||
// 启动 3 秒超时定时器
|
||||
_sendTimeoutTimer = Timer(Duration(seconds: 3), () {
|
||||
_handleSendTimeout(); // 触发超时处理
|
||||
});
|
||||
|
||||
|
||||
int start = state.voiceSubcontractingIndex * state.voiceSubcontractingSize;
|
||||
int end = start + state.voiceSubcontractingSize;
|
||||
if (end > state.data!.length) end = state.data!.length;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user