refactor shared flow settings and runtime cleanup
This commit is contained in:
@@ -158,8 +158,6 @@
|
||||
kiroRsKey: state.kiroRsKey,
|
||||
autoRunSkipFailures: state.autoRunSkipFailures,
|
||||
autoRunFallbackThreadIntervalMinutes: state.autoRunFallbackThreadIntervalMinutes,
|
||||
autoRunDelayEnabled: state.autoRunDelayEnabled,
|
||||
autoRunDelayMinutes: state.autoRunDelayMinutes,
|
||||
autoStepDelaySeconds: state.autoStepDelaySeconds,
|
||||
stepExecutionRangeByFlow: state.stepExecutionRangeByFlow,
|
||||
signupMethod: state.signupMethod,
|
||||
@@ -502,7 +500,6 @@
|
||||
}, {
|
||||
autoRunSessionId: 0,
|
||||
autoRunTimerPlan: null,
|
||||
scheduledAutoRunPlan: null,
|
||||
});
|
||||
clearStopRequest();
|
||||
}
|
||||
@@ -1159,7 +1156,6 @@
|
||||
autoRunSessionId: 0,
|
||||
autoRunRoundSummaries: serializeAutoRunRoundSummaries(totalRuns, roundSummaries),
|
||||
autoRunTimerPlan: null,
|
||||
scheduledAutoRunPlan: null,
|
||||
...getAutoRunStatusPayload(deps.getStopRequested() || stoppedEarly ? 'stopped' : 'complete', {
|
||||
currentRun: deps.getStopRequested() || stoppedEarly ? afterRuntime.autoRunCurrentRun : afterRuntime.autoRunTotalRuns,
|
||||
totalRuns: afterRuntime.autoRunTotalRuns,
|
||||
|
||||
@@ -209,8 +209,7 @@
|
||||
|
||||
function getAutoRunStatusPayload(phase, payload = {}) {
|
||||
return {
|
||||
autoRunning: phase === 'scheduled'
|
||||
|| phase === 'running'
|
||||
autoRunning: phase === 'running'
|
||||
|| phase === 'waiting_step'
|
||||
|| phase === 'waiting_email'
|
||||
|| phase === 'retrying'
|
||||
@@ -220,7 +219,6 @@
|
||||
autoRunTotalRuns: payload.totalRuns ?? 1,
|
||||
autoRunAttemptRun: payload.attemptRun ?? 0,
|
||||
autoRunSessionId: Math.max(0, Math.floor(Number(payload.sessionId ?? payload.autoRunSessionId) || 0)),
|
||||
scheduledAutoRunAt: Number.isFinite(Number(payload.scheduledAt)) ? Number(payload.scheduledAt) : null,
|
||||
autoRunCountdownAt: Number.isFinite(Number(payload.countdownAt)) ? Number(payload.countdownAt) : null,
|
||||
autoRunCountdownTitle: payload.countdownTitle === undefined ? '' : String(payload.countdownTitle || ''),
|
||||
autoRunCountdownNote: payload.countdownNote === undefined ? '' : String(payload.countdownNote || ''),
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
buildPersistentSettingsPayload,
|
||||
broadcastDataUpdate,
|
||||
applyIpProxySettingsFromState,
|
||||
cancelScheduledAutoRun,
|
||||
checkIcloudSession,
|
||||
clearAccountRunHistory,
|
||||
deleteAccountRunHistoryRecords,
|
||||
@@ -145,7 +144,6 @@
|
||||
normalizeMail2925Accounts,
|
||||
normalizePayPalAccounts,
|
||||
normalizeRunCount,
|
||||
AUTO_RUN_TIMER_KIND_SCHEDULED_START,
|
||||
notifyNodeComplete,
|
||||
notifyNodeError,
|
||||
patchMail2925Account,
|
||||
@@ -158,7 +156,6 @@
|
||||
handleCloudflareSecurityBlocked,
|
||||
resetState,
|
||||
resumeAutoRun,
|
||||
scheduleAutoRun,
|
||||
selectLuckmailPurchase,
|
||||
switchIpProxy,
|
||||
changeIpProxyExit,
|
||||
@@ -1324,7 +1321,7 @@
|
||||
throw new Error(autoRunStartValidation.errors?.[0]?.message || '当前设置不支持启动自动流程。');
|
||||
}
|
||||
if (getPendingAutoRunTimerPlan(state)) {
|
||||
throw new Error('已有自动运行倒计时计划,请先取消或立即开始。');
|
||||
throw new Error('已有线程间隔等待,请先停止或立即继续。');
|
||||
}
|
||||
const totalRuns = normalizeRunCount(message.payload?.totalRuns || 1);
|
||||
const autoRunSkipFailures = Boolean(message.payload?.autoRunSkipFailures);
|
||||
@@ -1334,68 +1331,6 @@
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
case 'SCHEDULE_AUTO_RUN': {
|
||||
clearStopRequest();
|
||||
if (message.source === 'sidepanel') {
|
||||
await lockAutomationWindowFromMessage(message, sender);
|
||||
}
|
||||
if (Boolean(message.payload?.accountContributionEnabled) && typeof setAccountContributionMode === 'function') {
|
||||
await setAccountContributionMode(true, {
|
||||
adapterId: message.payload?.contributionAdapterId,
|
||||
flowId: message.payload?.activeFlowId || message.payload?.flowId,
|
||||
});
|
||||
if (typeof setState === 'function') {
|
||||
const contributionNickname = String(message.payload?.contributionNickname || '').trim();
|
||||
const contributionQq = String(message.payload?.contributionQq || '').trim();
|
||||
await setState({
|
||||
contributionNickname,
|
||||
contributionQq,
|
||||
});
|
||||
}
|
||||
}
|
||||
const autoRunFlowStateUpdates = buildAutoRunFlowStateUpdates(message.payload || {});
|
||||
if (Object.keys(autoRunFlowStateUpdates).length > 0 && typeof setState === 'function') {
|
||||
await setState(autoRunFlowStateUpdates);
|
||||
}
|
||||
const state = await getState();
|
||||
const autoRunStartValidation = validateAutoRunStart(state, {
|
||||
activeFlowId: autoRunFlowStateUpdates.activeFlowId ?? state?.activeFlowId,
|
||||
targetId: autoRunFlowStateUpdates.targetId ?? state?.targetId,
|
||||
state,
|
||||
});
|
||||
if (autoRunStartValidation?.ok === false) {
|
||||
throw new Error(autoRunStartValidation.errors?.[0]?.message || '当前设置不支持启动自动流程。');
|
||||
}
|
||||
const totalRuns = normalizeRunCount(message.payload?.totalRuns || 1);
|
||||
return await scheduleAutoRun(totalRuns, {
|
||||
delayMinutes: message.payload?.delayMinutes,
|
||||
autoRunSkipFailures: Boolean(message.payload?.autoRunSkipFailures),
|
||||
mode: message.payload?.mode,
|
||||
});
|
||||
}
|
||||
|
||||
case 'START_SCHEDULED_AUTO_RUN_NOW': {
|
||||
clearStopRequest();
|
||||
if (message.source === 'sidepanel') {
|
||||
await lockAutomationWindowFromMessage(message, sender);
|
||||
}
|
||||
const started = await launchAutoRunTimerPlan('manual', {
|
||||
expectedKinds: [AUTO_RUN_TIMER_KIND_SCHEDULED_START],
|
||||
});
|
||||
if (!started) {
|
||||
throw new Error('当前没有可立即开始的倒计时计划。');
|
||||
}
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
case 'CANCEL_SCHEDULED_AUTO_RUN': {
|
||||
const cancelled = await cancelScheduledAutoRun();
|
||||
if (!cancelled) {
|
||||
throw new Error('当前没有可取消的倒计时计划。');
|
||||
}
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
case 'SKIP_AUTO_RUN_COUNTDOWN': {
|
||||
clearStopRequest();
|
||||
if (message.source === 'sidepanel') {
|
||||
|
||||
Reference in New Issue
Block a user