diff --git a/components/player/Queue.vue b/components/player/Queue.vue index 5333f769..aeffd408 100644 --- a/components/player/Queue.vue +++ b/components/player/Queue.vue @@ -492,19 +492,29 @@ watch( ); let scheduleClockTimer: ReturnType | null = null; +const needsScheduleClock = computed(() => + activeTab.value === 'schedule' && props.visible && props.scheduleIsReference && props.program.length > 0, +); +const stopScheduleClock = () => { + if (scheduleClockTimer === null) return; + clearInterval(scheduleClockTimer); + scheduleClockTimer = null; +}; onMounted(() => { scheduleNow.value = Math.floor(Date.now() / 1000); - scheduleClockTimer = setInterval(() => { - // Clock and the timeline fill move once per second. Only update the - // visible reference guide; real-time provider EPG is unaffected. - if (activeTab.value === 'schedule' && props.visible && props.scheduleIsReference) { + watch(needsScheduleClock, (active) => { + stopScheduleClock(); + if (!active) return; + scheduleNow.value = Math.floor(Date.now() / 1000); + scheduleClockTimer = setInterval(() => { + // Do not wake the queue when hidden, showing stations or without a guide. scheduleNow.value = Math.floor(Date.now() / 1000); - } - }, 1_000); + }, 1_000); + }, { immediate: true }); if (activeTab.value === 'schedule' && props.visible) void jumpToSchedulePosition(); }); onBeforeUnmount(() => { - if (scheduleClockTimer !== null) clearInterval(scheduleClockTimer); + stopScheduleClock(); scrollGeneration += 1; }); diff --git a/tests/station-schedule.test.mjs b/tests/station-schedule.test.mjs index 145cfa66..b770b263 100644 --- a/tests/station-schedule.test.mjs +++ b/tests/station-schedule.test.mjs @@ -157,9 +157,16 @@ test('live time bar is wired to a one-second clock only for visible reference gu const q = await readFile(new URL('../components/player/Queue.vue', import.meta.url), 'utf8'); const gap = await readFile(new URL('../components/player/ScheduleGap.vue', import.meta.url), 'utf8'); assert.match(q, /scheduleTimelineProgress\(item\.startTime, item\.endTime, scheduleNow\.value\)/); + assert.match(q, /watch\(needsScheduleClock, \(active\) => \{/); assert.match(q, /scheduleClockTimer = setInterval\(/); assert.match(q, /\}, 1_000\)/); - assert.match(q, /props\.visible && props\.scheduleIsReference/); + assert.match(q, /activeTab\.value === 'schedule' && props\.visible && props\.scheduleIsReference && props\.program\.length > 0/); + assert.match(q, /if \(!active\) return/); + assert.match(q, /stopScheduleClock\(\)/); + assert.match(q, /onBeforeUnmount\(\(\) => \{\s*stopScheduleClock\(\)/); + const intervalBody = q.match(/scheduleClockTimer = setInterval\(\(\) => \{([\s\S]*?)\}, 1_000\)/)?.[1]; + assert.ok(intervalBody, 'one-second callback exists only behind the eligibility watcher'); + assert.doesNotMatch(intervalBody, /if \(activeTab\.value === 'schedule'/); assert.match(q, /data-schedule-clock role="timer"/); assert.match(q, /data-schedule-time-progress/); assert.match(q, /:start-time="gapStartTime\(scheduleGap\.insertIndex\)"/);