From b6a850062b8c084bcd43b84505d1527fa8dab74e Mon Sep 17 00:00:00 2001 From: QLHazyCoder <2825305047@qq.com> Date: Sat, 11 Apr 2026 00:22:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=89=93=E5=8D=B0=E6=97=A5?= =?UTF-8?q?=E5=BF=97=EF=BC=8C=E4=BB=A5=E5=88=86=E6=9E=90=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=B5=81=E7=A8=8B=E4=B8=AD=E6=96=AD=E8=80=8C=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E4=B8=8D=E6=96=AD=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + background.js | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2f88269 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/docs diff --git a/background.js b/background.js index 7f94768..747da50 100644 --- a/background.js +++ b/background.js @@ -1147,6 +1147,8 @@ async function handleStepData(step, payload) { // Map of step -> { resolve, reject } for waiting on step completion const stepWaiters = new Map(); let resumeWaiter = null; +const AUTO_RUN_SIGNAL_COMPLETION_TIMEOUT_MS = 120000; +const AUTO_RUN_BACKGROUND_COMPLETED_STEPS = new Set([4, 7, 8]); function waitForStepComplete(step, timeoutMs = 120000) { return new Promise((resolve, reject) => { @@ -1281,9 +1283,35 @@ async function executeStep(step) { */ async function executeStepAndWait(step, delayAfter = 2000) { throwIfStopped(); - const promise = waitForStepComplete(step, 120000); - await executeStep(step); - await promise; + + if (AUTO_RUN_BACKGROUND_COMPLETED_STEPS.has(step)) { + await addLog(`自动运行:步骤 ${step} 由后台流程负责收尾,执行函数返回后将直接进入下一步。`, 'info'); + await executeStep(step); + const latestState = await getState(); + await addLog(`自动运行:步骤 ${step} 已执行返回,当前状态为 ${latestState.stepStatuses?.[step] || 'pending'},准备继续后续步骤。`, 'info'); + } else { + await addLog(`自动运行:步骤 ${step} 已发起,正在等待完成信号(超时 ${AUTO_RUN_SIGNAL_COMPLETION_TIMEOUT_MS / 1000} 秒)。`, 'info'); + const completionResultPromise = waitForStepComplete(step, AUTO_RUN_SIGNAL_COMPLETION_TIMEOUT_MS).then( + payload => ({ ok: true, payload }), + error => ({ ok: false, error }), + ); + + try { + await executeStep(step); + } catch (err) { + notifyStepError(step, getErrorMessage(err)); + await completionResultPromise; + throw err; + } + + const completionResult = await completionResultPromise; + if (!completionResult.ok) { + throw completionResult.error; + } + + await addLog(`自动运行:步骤 ${step} 已收到完成信号,准备继续后续步骤。`, 'info'); + } + // Extra delay for page transitions / DOM updates if (delayAfter > 0) { await sleepWithStop(delayAfter + Math.floor(Math.random() * 1200));