finity icon indicating copy to clipboard operation
finity copied to clipboard

Slideshow Auto-Advance Timer Fails to Start

Open iHumberto opened this issue 7 months ago • 0 comments

Hi guys,.

I installed the theme following the intructions, the slideshow renders correctly and displays the first slide, but does not advance automatically. Manual navigation via arrows or pagination dots works as expected. The auto-advance timer never starts after initialization.

In SlideshowManager.loadSlideshowData(), the SlideTimer is instantiated but never explicitly started:

STATE.slideshow.slideInterval = new SlideTimer(
    () => { if (!STATE.slideshow.isPaused) this.nextSlide(); },
    CONFIG.shuffleInterval
);
// Let VisibilityObserver start it initially  ← timer is never started

The code relies on VisibilityObserver.updateVisibility() to call .start(), but that method only does so when slideInterval.paused === true:

if (shouldBeVisible && !STATE.slideshow.isPaused) {
     if (STATE.slideshow.slideInterval.paused) {  // ← evaluates to false
         STATE.slideshow.slideInterval.start();    // ← never reached
     }
 }

The newly created SlideTimer has paused = false and timerId = null by default — an inconsistent state that bypasses the start condition entirely. Since paused is false, updateVisibility() assumes the timer is already running, but timerId is null, meaning it was never actually started.

Suggested Fix

In SlideshowManager.loadSlideshowData(), after creating the SlideTimer, explicitly set paused = true before delegating to VisibilityObserver, so the start condition is correctly evaluated:

STATE.slideshow.slideInterval = new SlideTimer(
     () => { if (!STATE.slideshow.isPaused) this.nextSlide(); },
     CONFIG.shuffleInterval
 );
 STATE.slideshow.slideInterval.paused = true; // ← ensure consistent initial state
 // VisibilityObserver will now correctly call .start()

Alternatively, call .start() directly after creation and let VisibilityObserver handle pausing if needed:

STATE.slideshow.slideInterval = new SlideTimer(
     () => { if (!STATE.slideshow.isPaused) this.nextSlide(); },
     CONFIG.shuffleInterval
 ).start(); // ← explicit start

Workaround

The following script injected into index.html after the slideshowpure.js tag resolves the issue:

<script>
(function() {
    let attempts = 0;
    function patchSlideshow() {
        attempts++;
        const sp = window.slideshowPure;
        const s = sp?.STATE?.slideshow;
        if (!s || !s.hasInitialized || s.totalItems === 0) {
            if (attempts < 30) setTimeout(patchSlideshow, 1000);
            return;
        }
        if (s.slideInterval && (s.slideInterval.paused || !s.slideInterval.timerId) && !s.isPaused) {
            s.slideInterval.remaining = s.slideInterval.interval;
            s.slideInterval.start();
        }
    }
    setTimeout(patchSlideshow, 4000);
})();
</script>

iHumberto avatar Apr 09 '26 23:04 iHumberto