feat: 添加邮箱就绪时自动恢复运行的功能,优化自动运行流程
This commit is contained in:
+31
-6
@@ -112,6 +112,9 @@ function broadcastDataUpdate(payload) {
|
|||||||
async function setEmailState(email) {
|
async function setEmailState(email) {
|
||||||
await setState({ email });
|
await setState({ email });
|
||||||
broadcastDataUpdate({ email });
|
broadcastDataUpdate({ email });
|
||||||
|
if (email) {
|
||||||
|
await resumeAutoRunIfWaitingForEmail();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setPasswordState(password) {
|
async function setPasswordState(password) {
|
||||||
@@ -1081,6 +1084,25 @@ let autoRunCurrentRun = 0;
|
|||||||
let autoRunTotalRuns = 1;
|
let autoRunTotalRuns = 1;
|
||||||
let autoRunAttemptRun = 0;
|
let autoRunAttemptRun = 0;
|
||||||
|
|
||||||
|
async function resumeAutoRunIfWaitingForEmail(options = {}) {
|
||||||
|
const { silent = false } = options;
|
||||||
|
const state = await getState();
|
||||||
|
if (!state.email || !isAutoRunPausedState(state)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resumeWaiter) {
|
||||||
|
if (!silent) {
|
||||||
|
await addLog('邮箱已就绪,自动继续后续步骤...', 'info');
|
||||||
|
}
|
||||||
|
resumeWaiter.resolve();
|
||||||
|
resumeWaiter = null;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Outer loop: keep retrying until the target number of successful runs is reached.
|
// Outer loop: keep retrying until the target number of successful runs is reached.
|
||||||
async function autoRunLoop(totalRuns, options = {}) {
|
async function autoRunLoop(totalRuns, options = {}) {
|
||||||
if (autoRunActive) {
|
if (autoRunActive) {
|
||||||
@@ -1268,9 +1290,15 @@ async function autoRunLoop(totalRuns, options = {}) {
|
|||||||
clearStopRequest();
|
clearStopRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
function waitForResume() {
|
async function waitForResume() {
|
||||||
|
throwIfStopped();
|
||||||
|
const state = await getState();
|
||||||
|
if (state.email) {
|
||||||
|
await addLog('邮箱已就绪,自动继续后续步骤...', 'info');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
throwIfStopped();
|
|
||||||
resumeWaiter = { resolve, reject };
|
resumeWaiter = { resolve, reject };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1282,10 +1310,7 @@ async function resumeAutoRun() {
|
|||||||
await addLog('无法继续:当前没有邮箱地址,请先在侧边栏填写邮箱。', 'error');
|
await addLog('无法继续:当前没有邮箱地址,请先在侧边栏填写邮箱。', 'error');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (resumeWaiter) {
|
await resumeAutoRunIfWaitingForEmail({ silent: true });
|
||||||
resumeWaiter.resolve();
|
|
||||||
resumeWaiter = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================
|
// ============================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user