|
1 | 1 | /* ============================================================ |
2 | | - OpenCut CEP Panel - Main Controller v1.9.21 |
| 2 | + OpenCut CEP Panel - Main Controller v1.9.22 |
3 | 3 | 6-Tab Professional Toolkit |
4 | 4 | ============================================================ */ |
5 | 5 | (function () { |
|
68 | 68 | if (_wsReconnectTimer) { clearTimeout(_wsReconnectTimer); _wsReconnectTimer = null; } |
69 | 69 | } |
70 | 70 |
|
| 71 | + // ---- Background poller restart hook ---- |
| 72 | + // |
| 73 | + // cleanupTimers() nukes mediaScanTimer / _statusTimer on every disconnect. |
| 74 | + // Without this hook only the initial init path would restart them, so |
| 75 | + // after the first disconnect/reconnect cycle the media scan and system |
| 76 | + // status bar would stop polling forever. Called from checkHealth() on |
| 77 | + // every reconnect and from the DOMContentLoaded bootstrap. |
| 78 | + var MEDIA_POLL_MS = 20000; // 20 seconds |
| 79 | + function startBackgroundPollers() { |
| 80 | + if (!mediaScanTimer) { |
| 81 | + mediaScanTimer = setInterval(function () { |
| 82 | + if (!currentJob && (inPremiere || connected)) { |
| 83 | + scanProjectMedia(); |
| 84 | + } |
| 85 | + }, MEDIA_POLL_MS); |
| 86 | + } |
| 87 | + // initStatusBar() is idempotent — it guards against duplicate timers |
| 88 | + // via its own _statusTimer check, so it is safe to call on reconnect. |
| 89 | + if (typeof initStatusBar === "function" && !_statusTimer) { |
| 90 | + initStatusBar(); |
| 91 | + } |
| 92 | + } |
| 93 | + |
71 | 94 | // ---- Style Preview CSS Map (loaded from backend) ---- |
72 | 95 | var stylePreviewMap = {}; |
73 | 96 |
|
|
1482 | 1505 | el.backendPort.textContent = BACKEND.replace("http://127.0.0.1:", "Port "); |
1483 | 1506 | updateButtons(); |
1484 | 1507 | loadCapabilities(); |
| 1508 | + // Restart media scan + status bar pollers after a reconnect. |
| 1509 | + // cleanupTimers() killed them on the preceding disconnect and |
| 1510 | + // without this they would never come back until full reload. |
| 1511 | + startBackgroundPollers(); |
1485 | 1512 | // Auto-connect WebSocket if available |
1486 | 1513 | if (!_wsConnected && capabilities.websocket !== false) { |
1487 | 1514 | wsConnect(); |
|
7705 | 7732 | // ================================================================ |
7706 | 7733 | // Status Bar — Health Monitoring (Phase 4.3) |
7707 | 7734 | // ================================================================ |
7708 | | - var _statusTimer = null; |
| 7735 | + // NOTE: _statusTimer is declared once at module scope (line ~49) so |
| 7736 | + // cleanupTimers() can clear it. Do NOT redeclare it here. |
7709 | 7737 | var _STATUS_POLL_MS = 5000; |
7710 | 7738 |
|
7711 | 7739 | var _statusBarRetries = 0; |
|
7718 | 7746 | } |
7719 | 7747 | return; |
7720 | 7748 | } |
| 7749 | + // Idempotent: skip if a poller is already running (re-entry from |
| 7750 | + // startBackgroundPollers() on reconnect, or from a second init call). |
| 7751 | + if (_statusTimer) return; |
| 7752 | + _statusBarRetries = 0; |
7721 | 7753 | pollSystemStatus(); |
7722 | 7754 | _statusTimer = setInterval(pollSystemStatus, _STATUS_POLL_MS); |
7723 | 7755 | } |
@@ -10695,13 +10727,10 @@ |
10695 | 10727 | populateRecentFiles(); |
10696 | 10728 |
|
10697 | 10729 | // Periodic soft re-scan: picks up media imported outside OpenCut |
10698 | | - // (e.g. user dragging files into Premiere, or Media Browser imports) |
10699 | | - var MEDIA_POLL_MS = 20000; // 20 seconds |
10700 | | - mediaScanTimer = setInterval(function () { |
10701 | | - if (!currentJob && (inPremiere || connected)) { |
10702 | | - scanProjectMedia(); |
10703 | | - } |
10704 | | - }, MEDIA_POLL_MS); |
| 10730 | + // (e.g. user dragging files into Premiere, or Media Browser imports). |
| 10731 | + // Shared helper so the reconnect path can restart this after |
| 10732 | + // cleanupTimers() kills it on disconnect. |
| 10733 | + startBackgroundPollers(); |
10705 | 10734 |
|
10706 | 10735 | // Re-scan when panel regains focus or becomes visible |
10707 | 10736 | document.addEventListener("visibilitychange", function () { |
|
0 commit comments