Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions components/player/Queue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -492,19 +492,29 @@ watch(
);

let scheduleClockTimer: ReturnType<typeof setInterval> | 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;
});

Expand Down
9 changes: 8 additions & 1 deletion tests/station-schedule.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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\)"/);
Expand Down
Loading