|
206 | 206 | let debugEntries = []; |
207 | 207 | let debugActive = false; |
208 | 208 | let debugLatestSeq = 0; |
209 | | - let debugPollHandle = null; |
| 209 | + let debugAutoRefreshHandle = null; |
210 | 210 | let debugLimit = 5000; |
211 | 211 | let debugStatusEl = null; |
212 | 212 | let debugInfoCounter = null; |
|
219 | 219 | try { |
220 | 220 | if (window.localStorage) { |
221 | 221 | const stored = window.localStorage.getItem(debugAutoStorageKey); |
222 | | - if (stored === 'false') return false; |
223 | 222 | if (stored === 'true') return true; |
| 223 | + if (stored === 'false') return false; |
224 | 224 | } |
225 | 225 | } catch (error) { } |
226 | | - return true; |
| 226 | + return false; |
227 | 227 | }; |
228 | 228 |
|
229 | 229 | const storeDebugAutoPreference = (value) => { |
|
308 | 308 | } |
309 | 309 | }; |
310 | 310 |
|
311 | | - const scheduleNextDebugFetch = (delay = DEBUG_REFRESH_INTERVAL) => { |
312 | | - if (debugPollHandle) { |
313 | | - clearTimeout(debugPollHandle); |
314 | | - debugPollHandle = null; |
| 311 | + const stopDebugAutoRefresh = () => { |
| 312 | + if (debugAutoRefreshHandle) { |
| 313 | + clearInterval(debugAutoRefreshHandle); |
| 314 | + debugAutoRefreshHandle = null; |
315 | 315 | } |
316 | | - const safeDelay = Math.max(0, Number(delay) || 0); |
317 | | - debugPollHandle = setTimeout(() => { |
318 | | - debugPollHandle = null; |
319 | | - if (!debugActive) return; |
320 | | - if (!debugAutoCheckbox || !debugAutoCheckbox.is(':checked')) return; |
321 | | - if (debugFetching) { |
322 | | - scheduleNextDebugFetch(DEBUG_REFRESH_INTERVAL); |
323 | | - return; |
324 | | - } |
325 | | - fetchDebugLog({ triggeredByTimer: true }); |
326 | | - }, safeDelay); |
327 | | - }; |
328 | | - |
329 | | - const startDebugTimer = () => { |
330 | | - scheduleNextDebugFetch(0); |
331 | 316 | }; |
332 | 317 |
|
333 | | - const stopDebugTimer = () => { |
334 | | - if (debugPollHandle) { |
335 | | - clearTimeout(debugPollHandle); |
336 | | - debugPollHandle = null; |
337 | | - } |
| 318 | + const ensureDebugAutoRefresh = () => { |
| 319 | + if (debugAutoRefreshHandle) return; |
| 320 | + if (!debugAutoCheckbox || !debugAutoCheckbox.is(':checked')) return; |
| 321 | + debugAutoRefreshHandle = setInterval(() => { |
| 322 | + if (!debugAutoCheckbox || !debugAutoCheckbox.is(':checked')) { |
| 323 | + stopDebugAutoRefresh(); |
| 324 | + return; |
| 325 | + } |
| 326 | + if (!debugActive) return; |
| 327 | + if (debugFetching) return; |
| 328 | + fetchDebugLog({ triggeredByTimer: true, forceFull: true }); |
| 329 | + }, DEBUG_REFRESH_INTERVAL); |
338 | 330 | }; |
339 | 331 |
|
340 | 332 | const copyDebugToClipboard = () => { |
|
426 | 418 | }).always(function () { |
427 | 419 | debugFetching = false; |
428 | 420 | if (debugActive && debugAutoCheckbox && debugAutoCheckbox.is(':checked')) { |
429 | | - scheduleNextDebugFetch(DEBUG_REFRESH_INTERVAL); |
| 421 | + ensureDebugAutoRefresh(); |
430 | 422 | } else { |
431 | | - stopDebugTimer(); |
| 423 | + stopDebugAutoRefresh(); |
432 | 424 | } |
433 | 425 | if (debugPendingForceRefresh) { |
434 | 426 | debugPendingForceRefresh = false; |
|
465 | 457 | const enabled = $(this).is(':checked'); |
466 | 458 | storeDebugAutoPreference(enabled); |
467 | 459 | if (enabled) { |
468 | | - if (debugActive) { |
469 | | - fetchDebugLog({ incremental: true }); |
470 | | - startDebugTimer(); |
471 | | - } |
| 460 | + debugActive = true; |
| 461 | + fetchDebugLog({ forceFull: true }); |
| 462 | + ensureDebugAutoRefresh(); |
472 | 463 | } else { |
473 | | - stopDebugTimer(); |
| 464 | + stopDebugAutoRefresh(); |
474 | 465 | } |
475 | 466 | }); |
476 | 467 |
|
|
496 | 487 | const shouldForceFull = debugEntries.length === 0; |
497 | 488 | fetchDebugLog({ forceFull: shouldForceFull }); |
498 | 489 | if (debugAutoCheckbox && debugAutoCheckbox.is(':checked')) { |
499 | | - startDebugTimer(); |
| 490 | + ensureDebugAutoRefresh(); |
500 | 491 | } |
501 | 492 | } else { |
502 | | - stopDebugTimer(); |
| 493 | + stopDebugAutoRefresh(); |
503 | 494 | } |
504 | 495 | } |
505 | 496 | }); |
|
0 commit comments