fix: 修复前端捕获按钮的问题
This commit is contained in:
parent
bcee42d8c1
commit
822091243e
|
@ -298,9 +298,8 @@ const [useProvideLogicAnalyzer, useLogicAnalyzerState] = createInjectionState(
|
|||
return;
|
||||
}
|
||||
|
||||
const release = await operationMutex.acquire();
|
||||
isCapturing.value = true;
|
||||
|
||||
const release = await operationMutex.acquire();
|
||||
try {
|
||||
const client = AuthManager.createAuthenticatedLogicAnalyzerClient();
|
||||
|
||||
|
@ -313,17 +312,14 @@ const [useProvideLogicAnalyzer, useLogicAnalyzerState] = createInjectionState(
|
|||
alert?.info("开始捕获信号...", 2000);
|
||||
|
||||
// 2. 轮询捕获状态
|
||||
const pollCaptureStatus = async (): Promise<boolean> => {
|
||||
// 如果不再处于捕获状态,说明被停止了
|
||||
if (!isCapturing.value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let captureCompleted = false;
|
||||
while (isCapturing.value) {
|
||||
const status = await client.getCaptureStatus();
|
||||
|
||||
// 检查是否捕获完成
|
||||
if (status === CaptureStatus.CaptureDone) {
|
||||
return true;
|
||||
captureCompleted = true;
|
||||
break;
|
||||
}
|
||||
|
||||
// 检查是否仍在捕获中
|
||||
|
@ -334,15 +330,12 @@ const [useProvideLogicAnalyzer, useLogicAnalyzerState] = createInjectionState(
|
|||
) {
|
||||
// 等待500毫秒后继续轮询
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
return await pollCaptureStatus();
|
||||
continue;
|
||||
}
|
||||
|
||||
// 其他状态视为错误
|
||||
throw new Error(`捕获状态异常: ${status}`);
|
||||
};
|
||||
|
||||
// 等待捕获完成
|
||||
const captureCompleted = await pollCaptureStatus();
|
||||
// throw new Error(`捕获状态异常: ${status}`);
|
||||
}
|
||||
|
||||
// 如果捕获被停止,不继续处理数据
|
||||
if (!captureCompleted) {
|
||||
|
@ -371,27 +364,45 @@ const [useProvideLogicAnalyzer, useLogicAnalyzerState] = createInjectionState(
|
|||
return;
|
||||
}
|
||||
|
||||
// 设置捕获状态为false,这会使轮询停止
|
||||
isCapturing.value = false;
|
||||
|
||||
const release = await operationMutex.acquire();
|
||||
try {
|
||||
const client = AuthManager.createAuthenticatedLogicAnalyzerClient();
|
||||
|
||||
// 执行强制捕获来停止当前捕获
|
||||
const forceSuccess = await client.setCaptureMode(false, true);
|
||||
const forceSuccess = await client.setCaptureMode(false, false);
|
||||
if (!forceSuccess) {
|
||||
throw new Error("无法执行强制捕获");
|
||||
throw new Error("无法停止捕获");
|
||||
}
|
||||
|
||||
// 设置捕获状态为false,这会使轮询停止
|
||||
isCapturing.value = false;
|
||||
|
||||
alert.info("已停止强制捕获...", 2000);
|
||||
} catch (error) {
|
||||
console.error("停止捕获失败:", error);
|
||||
alert.error(
|
||||
`停止捕获失败: ${error instanceof Error ? error.message : "未知错误"}`,
|
||||
3000,
|
||||
);
|
||||
} finally {
|
||||
release();
|
||||
}
|
||||
};
|
||||
|
||||
const forceCapture = async () => {
|
||||
// 设置捕获状态为false,这会使轮询停止
|
||||
isCapturing.value = false;
|
||||
|
||||
const release = await operationMutex.acquire();
|
||||
try {
|
||||
await stopCapture();
|
||||
const client = AuthManager.createAuthenticatedLogicAnalyzerClient();
|
||||
|
||||
// 执行强制捕获来停止当前捕获
|
||||
const forceSuccess = await client.setCaptureMode(true, true);
|
||||
if (!forceSuccess) {
|
||||
throw new Error("无法执行强制捕获");
|
||||
}
|
||||
|
||||
await getCaptureData();
|
||||
alert.success(`捕获完成!`, 3000);
|
||||
} catch (error) {
|
||||
|
@ -400,6 +411,8 @@ const [useProvideLogicAnalyzer, useLogicAnalyzerState] = createInjectionState(
|
|||
`强制捕获失败: ${error instanceof Error ? error.message : "未知错误"}`,
|
||||
3000,
|
||||
);
|
||||
} finally{
|
||||
release();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -46,9 +46,6 @@
|
|||
'from-red-500 to-red-600 hover:from-red-600 hover:to-red-700 focus:ring-red-300':
|
||||
analyzer.isCapturing.value,
|
||||
}"
|
||||
:disabled="
|
||||
analyzer.isOperationInProgress.value && !analyzer.isCapturing.value
|
||||
"
|
||||
@click="
|
||||
analyzer.isCapturing.value
|
||||
? analyzer.stopCapture()
|
||||
|
@ -71,7 +68,6 @@
|
|||
<button
|
||||
v-if="analyzer.isCapturing.value"
|
||||
class="group relative px-8 py-3 bg-gradient-to-r from-orange-500 to-orange-600 hover:from-orange-600 hover:to-orange-700 text-white font-medium rounded-lg shadow-lg hover:shadow-xl transform hover:scale-105 transition-all duration-200 ease-in-out focus:outline-none focus:ring-4 focus:ring-orange-300 active:scale-95"
|
||||
:disabled="analyzer.isOperationInProgress.value"
|
||||
@click="analyzer.forceCapture()"
|
||||
>
|
||||
<span class="flex items-center gap-2">
|
||||
|
|
Loading…
Reference in New Issue