diff --git a/tests/test_video_side_shell.py b/tests/test_video_side_shell.py index d2c7e38e..ad98aa22 100644 --- a/tests/test_video_side_shell.py +++ b/tests/test_video_side_shell.py @@ -192,6 +192,9 @@ def test_scan_module_referenced_and_isolated(): assert "addEventListener" in _SCAN_JS assert "soulsync:video-scan-done" in _SCAN_JS assert "/api/video/scan/request" in _SCAN_JS + # Rehydrates a running scan after a page refresh (parity with music tools). + assert "/api/video/scan/status" in _SCAN_JS + assert "resumeIfScanning" in _SCAN_JS def test_video_settings_reuses_real_music_settings_page(): diff --git a/webui/static/video/video-scan.js b/webui/static/video/video-scan.js index f01fb6bd..7c6ceb99 100644 --- a/webui/static/video/video-scan.js +++ b/webui/static/video/video-scan.js @@ -159,6 +159,24 @@ .catch(function () { /* poll will reconcile */ }); } + // Rehydrate after a page refresh: the scan keeps running server-side, so if + // one is in progress, restore the UI (Cancel button, moving bar, phase) and + // resume polling — parity with the music tools. + function resumeIfScanning() { + if (scanning) return; + fetch(STATUS_URL, { headers: { 'Accept': 'application/json' } }) + .then(function (r) { return r.json(); }) + .then(function (s) { + if (s && s.state === 'scanning' && !scanning) { + scanning = true; + reflectProgress(s); + emit('soulsync:video-scan-progress', s); + setTimeout(poll, 1200); + } + }) + .catch(function () { /* ignore */ }); + } + function init() { var triggers = document.querySelectorAll('[data-video-scan-mode],[data-video-scan]'); for (var i = 0; i < triggers.length; i++) { @@ -182,8 +200,11 @@ start((e.detail && e.detail.mode) || 'full'); }); document.addEventListener('soulsync:video-page-shown', function (e) { - if (e && e.detail === 'video-tools') loadToolStats(); + if (e && e.detail === 'video-tools') { loadToolStats(); resumeIfScanning(); } }); + // On load: if a scan is already running (page was refreshed mid-scan), + // restore the live state instead of showing Idle. + resumeIfScanning(); } if (document.readyState === 'loading') {