From 0a4acffb00542a5a0d788f166d170c51a6de42ec Mon Sep 17 00:00:00 2001 From: QLHazyCoder <2825305047@qq.com> Date: Fri, 1 May 2026 01:27:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E8=BF=90=E8=A1=8C=E7=8A=B6=E6=80=81=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=89=8B=E5=8A=A8=E8=BF=90=E8=A1=8C=E8=AE=A1?= =?UTF-8?q?=E6=95=B0=E8=BE=93=E5=85=A5=E7=9A=84=E8=A1=8C=E4=B8=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sidepanel/sidepanel.js | 16 ++++--- tests/run-count-unlimited.test.js | 80 +++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 6 deletions(-) diff --git a/sidepanel/sidepanel.js b/sidepanel/sidepanel.js index 36615b6..b5d8e29 100644 --- a/sidepanel/sidepanel.js +++ b/sidepanel/sidepanel.js @@ -3845,7 +3845,13 @@ function applyAutoRunStatus(payload = currentAutoRun) { setSettingsCardLocked(settingsCardLocked); - inputRunCount.disabled = currentAutoRun.autoRunning || shouldLockRunCountToEmailPool(); + const lockedRunCount = getLockedRunCountFromEmailPool(); + const shouldSyncAutoRunTotalRuns = currentAutoRun.autoRunning + || locked + || paused + || scheduled; + + inputRunCount.disabled = currentAutoRun.autoRunning || lockedRunCount > 0; btnAutoRun.disabled = currentAutoRun.autoRunning; btnFetchEmail.disabled = locked || isCustomMailProvider() @@ -3853,7 +3859,9 @@ function applyAutoRunStatus(payload = currentAutoRun) { inputEmail.disabled = locked; inputAutoSkipFailures.disabled = scheduled; - if (currentAutoRun.totalRuns > 0) { + if (lockedRunCount > 0) { + inputRunCount.value = String(lockedRunCount); + } else if (shouldSyncAutoRunTotalRuns && currentAutoRun.totalRuns > 0) { inputRunCount.value = String(currentAutoRun.totalRuns); } @@ -4273,10 +4281,6 @@ function applySettingsState(state) { if (typeof updateHeroSmsRuntimeDisplay === 'function') { updateHeroSmsRuntimeDisplay(state); } - if (state?.autoRunTotalRuns) { - inputRunCount.value = String(state.autoRunTotalRuns); - } - applyAutoRunStatus(state); markSettingsDirty(false); updateAutoDelayInputState(); diff --git a/tests/run-count-unlimited.test.js b/tests/run-count-unlimited.test.js index ccfc81b..1d20cb0 100644 --- a/tests/run-count-unlimited.test.js +++ b/tests/run-count-unlimited.test.js @@ -77,6 +77,86 @@ return { assert.equal(api.getRunCountValue(), 1); }); +test('sidepanel idle auto-run status does not reset manual run count input', () => { + const source = fs.readFileSync('sidepanel/sidepanel.js', 'utf8'); + const bundle = [ + extractFunction(source, 'hasOwnStateValue'), + extractFunction(source, 'readAutoRunStateValue'), + extractFunction(source, 'syncAutoRunState'), + extractFunction(source, 'isAutoRunLockedPhase'), + extractFunction(source, 'isAutoRunPausedPhase'), + extractFunction(source, 'isAutoRunScheduledPhase'), + extractFunction(source, 'applyAutoRunStatus'), + ].join('\n'); + + const api = new Function(` +let currentAutoRun = { + autoRunning: false, + phase: 'idle', + currentRun: 0, + totalRuns: 1, + attemptRun: 0, + scheduledAt: null, + countdownAt: null, + countdownTitle: '', + countdownNote: '', +}; +let lockedRunCount = 0; +const inputRunCount = { value: '8', disabled: false }; +const btnAutoRun = { disabled: false, innerHTML: '' }; +const btnFetchEmail = { disabled: false }; +const inputEmail = { disabled: false }; +const inputAutoSkipFailures = { disabled: false }; +const autoContinueBar = { style: { display: '' } }; + +function setSettingsCardLocked() {} +function getAutoRunLabel() { return ''; } +function getLockedRunCountFromEmailPool() { return lockedRunCount; } +function isCustomMailProvider() { return false; } +function usesCustomEmailPoolGenerator() { return false; } +function setDefaultAutoRunButton() {} +function updateAutoDelayInputState() {} +function updateFallbackThreadIntervalInputState() {} +function syncScheduledCountdownTicker() {} +function updateStopButtonState() {} +function getStepStatuses() { return {}; } +function updateConfigMenuControls() {} +function renderContributionMode() {} + +${bundle} + +return { + applyAutoRunStatus, + getValue() { + return inputRunCount.value; + }, + isDisabled() { + return inputRunCount.disabled; + }, + setValue(value) { + inputRunCount.value = value; + }, + setLockedRunCount(value) { + lockedRunCount = value; + }, +}; +`)(); + + api.applyAutoRunStatus({ autoRunning: false, autoRunPhase: 'idle', autoRunTotalRuns: 1 }); + assert.equal(api.getValue(), '8'); + assert.equal(api.isDisabled(), false); + + api.applyAutoRunStatus({ autoRunPhase: 'running', autoRunTotalRuns: 4 }); + assert.equal(api.getValue(), '4'); + assert.equal(api.isDisabled(), true); + + api.setValue('9'); + api.setLockedRunCount(2); + api.applyAutoRunStatus({ autoRunning: false, autoRunPhase: 'idle', autoRunTotalRuns: 1 }); + assert.equal(api.getValue(), '2'); + assert.equal(api.isDisabled(), true); +}); + test('background normalizeRunCount no longer clamps values to 50', () => { const source = fs.readFileSync('background.js', 'utf8'); const bundle = extractFunction(source, 'normalizeRunCount');