Skip to content

Commit d7c3193

Browse files
committed
Fix auto ping timer management to prevent premature firing during manual ping and ensure proper countdown resumption
1 parent 24f3473 commit d7c3193

1 file changed

Lines changed: 35 additions & 3 deletions

File tree

content/wardrive.js

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,15 @@ function pauseAutoCountdown() {
537537
state.pausedAutoTimerRemainingMs = null;
538538
}
539539
}
540-
// Stop the auto ping timer (but keep autoTimerId so we know auto mode is active)
540+
541+
// CRITICAL: Clear the actual ping timer to prevent it from firing during manual ping
542+
if (state.autoTimerId) {
543+
debugLog(`[TIMER] Clearing ping timer (id=${state.autoTimerId}) during pause`);
544+
clearTimeout(state.autoTimerId);
545+
state.autoTimerId = null;
546+
}
547+
548+
// Stop the UI countdown display
541549
autoCountdownTimer.stop();
542550
state.nextAutoPingTime = null;
543551
}
@@ -547,8 +555,32 @@ function resumeAutoCountdown() {
547555
if (state.pausedAutoTimerRemainingMs !== null) {
548556
// Validate paused time is still reasonable before resuming
549557
if (state.pausedAutoTimerRemainingMs > MIN_PAUSE_THRESHOLD_MS && state.pausedAutoTimerRemainingMs < MAX_REASONABLE_TIMER_MS) {
550-
debugLog(`[TIMER] Resuming auto countdown with ${state.pausedAutoTimerRemainingMs}ms remaining`);
551-
startAutoCountdown(state.pausedAutoTimerRemainingMs);
558+
const remainingMs = state.pausedAutoTimerRemainingMs;
559+
debugLog(`[TIMER] Resuming auto countdown with ${remainingMs}ms remaining`);
560+
561+
// Start the UI countdown display
562+
startAutoCountdown(remainingMs);
563+
564+
// CRITICAL: Also schedule the actual ping timer with the remaining time
565+
state.autoTimerId = setTimeout(() => {
566+
debugLog(`[TX/RX AUTO] Resumed auto ping timer fired (id=${state.autoTimerId})`);
567+
568+
// Double-check guards before sending ping
569+
if (!state.txRxAutoRunning) {
570+
debugLog("[TX/RX AUTO] Auto mode no longer running, ignoring timer");
571+
return;
572+
}
573+
if (state.pingInProgress) {
574+
debugLog("[TX/RX AUTO] Ping already in progress, ignoring timer");
575+
return;
576+
}
577+
578+
state.skipReason = null;
579+
debugLog("[TX/RX AUTO] Sending auto ping (resumed)");
580+
sendPing(false).catch(console.error);
581+
}, remainingMs);
582+
debugLog(`[TIMER] Resumed ping timer scheduled (id=${state.autoTimerId})`);
583+
552584
state.pausedAutoTimerRemainingMs = null;
553585
return true;
554586
} else {

0 commit comments

Comments
 (0)