From 84d0bcbd1938cf33f056c207c8159abe0fe9c89d Mon Sep 17 00:00:00 2001 From: Sleeps Date: Wed, 7 Oct 2026 14:02:09 +0100 Subject: [PATCH] Use one stateful caption control in web dashboard --- scene_search/web/index.html | 40 ++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/scene_search/web/index.html b/scene_search/web/index.html index 58dbaf6..b9a330c 100644 --- a/scene_search/web/index.html +++ b/scene_search/web/index.html @@ -111,7 +111,6 @@
-
@@ -362,11 +361,12 @@ $('captionFrames').textContent = (s.frames_completed || 0) + ' / ' + (s.frames_total || 0) + ' frames'; if (s.running) { - $('captionNow').disabled = true; - $('captionPause').disabled = s.stage === 'syncing' || s.stage === 'sync'; - $('captionPause').textContent = s.paused - ? 'Resume' - : (s.pause_requested ? 'Cancel pause' : 'Pause'); + const syncing = s.stage === 'syncing' || s.stage === 'sync'; + $('captionNow').disabled = syncing; + $('captionNow').textContent = syncing + ? 'Finishing...' + : ((s.paused || s.pause_requested) ? 'Resume' : 'Pause'); + $('forceCaption').disabled = true; $('captionStatus').className = 'status'; if (s.paused) { $('captionStatus').textContent = 'Captioning paused'; @@ -394,15 +394,15 @@ } } else if (s.stage === 'failed') { $('captionNow').disabled = false; - $('captionPause').disabled = true; - $('captionPause').textContent = 'Pause'; + $('captionNow').textContent = 'Start / resume captioning'; + $('forceCaption').disabled = false; $('captionStatus').className = 'status error'; $('captionStatus').textContent = 'Failed: ' + (s.error || 'unknown error'); $('captionDetail').textContent = ''; } else if (s.stage === 'complete') { $('captionNow').disabled = false; - $('captionPause').disabled = true; - $('captionPause').textContent = 'Pause'; + $('captionNow').textContent = 'Start / resume captioning'; + $('forceCaption').disabled = false; $('captionStatus').className = 'status ok'; $('captionStatus').textContent = 'Complete: ' + (s.frames_completed || 0) + ' saved, ' + (s.failed || 0) + ' failed'; @@ -410,8 +410,8 @@ (s.retained || 0) + ' existing captions retained'; } else { $('captionNow').disabled = false; - $('captionPause').disabled = true; - $('captionPause').textContent = 'Pause'; + $('captionNow').textContent = 'Start / resume captioning'; + $('forceCaption').disabled = false; $('captionStatus').className = 'status muted'; $('captionStatus').textContent = 'Idle'; $('captionDetail').textContent = ''; @@ -456,14 +456,23 @@ } } - async function toggleCaptionPause() { - if (!captionLastStatus || !captionLastStatus.running) return; + async function captionAction() { + if (!captionLastStatus || !captionLastStatus.running) { + await startCaption(); + return; + } + + if (captionLastStatus.stage === 'syncing' || captionLastStatus.stage === 'sync') { + return; + } + const resume = captionLastStatus.paused || captionLastStatus.pause_requested; try { const s = await api(resume ? '/api/caption/resume' : '/api/caption/pause', { method:'POST' }); renderCaptionStatus(s); + lastCaptionRunning = !!s.running; } catch (e) { $('captionStatus').className = 'status error'; $('captionStatus').textContent = e.message; @@ -532,8 +541,7 @@ $('selectAll').onclick = () => document.querySelectorAll('.libraryCheck').forEach(x => x.checked = true); $('applyLibraries').onclick = applyLibrarySelection; $('indexNow').onclick = startIndex; - $('captionNow').onclick = startCaption; - $('captionPause').onclick = toggleCaptionPause; + $('captionNow').onclick = captionAction; $('reportFailed').onclick = () => loadIndexReport('failed'); $('reportRemoved').onclick = () => loadIndexReport('removed'); $('reportIndexed').onclick = () => loadIndexReport('indexed');