diff --git a/static/js/app.js b/static/js/app.js index ee176c0..70e91a9 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -234,19 +234,10 @@ function showAddToast() { // ---------- Slideshow screensaver ---------- -async function initSlideshow() { - try { - const res = await fetch('/api/photos'); - photos = await res.json(); - } catch (e) { - console.error('Could not load photos:', e); - } - - // Any interaction resets the inactivity timer (or dismisses the slideshow) +function initSlideshow() { ['touchstart', 'click', 'mousemove', 'keydown'].forEach(evt => { document.addEventListener(evt, handleUserActivity, { passive: true }); }); - resetInactivityTimer(); } @@ -260,21 +251,30 @@ function handleUserActivity() { function resetInactivityTimer() { clearTimeout(inactivityTimer); - if (photos.length > 0) { - inactivityTimer = setTimeout(showSlideshow, INACTIVITY_TIMEOUT); - } + inactivityTimer = setTimeout(showSlideshow, INACTIVITY_TIMEOUT); } -function showSlideshow() { +async function showSlideshow() { + // Fetch fresh each time so newly added photos appear without a restart + try { + const res = await fetch('/api/photos'); + photos = await res.json(); + } catch (e) { + console.error('Could not load photos:', e); + } + + if (!photos.length) { + resetInactivityTimer(); + return; + } + slideshowActive = true; const overlay = document.getElementById('slideshow-overlay'); overlay.classList.remove('hidden'); - // Start from a random position in the shuffled list slideIndex = Math.floor(Math.random() * photos.length); activeSlot = 'a'; - // Show first photo immediately; preload second into the inactive slot loadSlide('a', photos[slideIndex]); if (photos.length > 1) { loadSlide('b', photos[(slideIndex + 1) % photos.length]);