change schedule to settings with new default interval

This commit is contained in:
Adrian Zürcher
2026-01-21 09:03:53 +01:00
parent 66c6d9a3fb
commit d1f1ad563b
6 changed files with 191 additions and 86 deletions

View File

@@ -33,7 +33,7 @@
<button id="shuffleBtn" onclick="toggleShuffle()" class="text-xs uppercase font-bold text-gray-400 hover:text-white transition-colors flex items-center gap-2">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" /></svg>
Shuffle: <span id="shuffleStatus">OFF</span>
Shuffle: <span id="shuffleStatus">ON</span>
</button>
<button onclick="toggleFullScreen()" class="text-sm hover:text-blue-400 transition-colors">Full Screen</button>
@@ -58,6 +58,18 @@
const speedInput = document.getElementById('speed');
const shuffleStatus = document.getElementById('shuffleStatus');
async function initializeSlideshow() {
// 1. Get the default interval from API
const defaultInterval = await checkDefaultInterval();
speedInput.value = defaultInterval;
// 2. Setup QR Code
setupQRCode();
// 3. Load Images (which eventually calls start())
loadImages();
}
// Fisher-Yates Shuffle Algorithm
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
@@ -75,10 +87,23 @@
index = 0;
}
async function checkSchedule() {
async function checkDefaultInterval() {
try {
const res = await fetch('/api/get-schedule');
const schedule = await res.json();
const res = await fetch('/api/get-settings');
const settings = await res.json();
// Return the saved interval, or fallback to 10 if it's missing
return settings.default_interval || "120";
} catch (err) {
console.error("Failed to fetch default interval:", err);
return "120";
}
}
async function checkSettings() {
try {
const res = await fetch('/api/get-settings');
const settings = await res.json();
const now = new Date();
const day = now.toLocaleDateString('en-US', { weekday: 'long' });
@@ -86,9 +111,9 @@
const currentTime = now.getHours().toString().padStart(2, '0') + ":" +
now.getMinutes().toString().padStart(2, '0');
const isActive = schedule[day + "_active"];
const start = schedule[day + "_start"];
const end = schedule[day + "_end"];
const isActive = settings[day + "_active"];
const start = settings[day + "_start"];
const end = settings[day + "_end"];
// Check if we should be "OFF"
if (isActive && (currentTime < start || currentTime > end)) {
@@ -131,7 +156,7 @@
async function showNext() {
if (playlist.length === 0) return;
const isRunning = await checkSchedule();
const isRunning = await checkSettings();
if (!isRunning) return;
viewer.classList.replace('fade-in', 'fade-out');
@@ -205,8 +230,7 @@
speedInput.addEventListener('change', start);
// Initial setup
setupQRCode();
loadImages();
initializeSlideshow();
</script>
</body>
</html>