fix: URL param auto-launch now awaits slideshow start, uses 'in' operator for ?favorites/?random, adds console logging for debug

This commit is contained in:
2026-05-19 16:35:03 +10:00
parent cac179754c
commit 4f7d30d3d2
+73 -20
View File
@@ -22,6 +22,16 @@
return p;
}
// --- Auto-launch helper: sets source and immediately starts slideshow ---
async function autoLaunch(source, albumId, personId) {
urlDriven = true;
selectedSource = source;
selectedAlbumId = albumId || null;
selectedPersonId = personId || null;
console.log('Frambe: auto-launching source=' + source + (albumId ? ' album=' + albumId : '') + (personId ? ' person=' + personId : ''));
await doStartSlideshow();
}
async function init() {
document.body.classList.add('setup-mode');
try {
@@ -31,13 +41,19 @@
if (!si.ok) { showError('Cannot reach Immich server: ' + si.error); return; }
$connectionStatus.textContent = 'Connected to Immich v' + si.version.major + '.' + si.version.minor + '.' + si.version.patch;
$connectionStatus.classList.add('connected');
// Check URL parameters for direct launch (zero-touch)
var params = getUrlParams();
if (params.album) { urlDriven = true; selectedSource = 'album'; selectedAlbumId = params.album; $btnStart.disabled = false; startSlideshow(); return; }
if (params.person) { urlDriven = true; selectedSource = 'person'; selectedPersonId = params.person; $btnStart.disabled = false; startSlideshow(); return; }
if (params.favorites === '' || params.favorites === 'true' || params.favorites === '1') { urlDriven = true; selectedSource = 'favorites'; $btnStart.disabled = false; startSlideshow(); return; }
if (params.random === '' || params.random === 'true' || params.random === '1') { urlDriven = true; selectedSource = 'random'; $btnStart.disabled = false; startSlideshow(); return; }
if (config.albumId) { selectedSource = 'album'; selectedAlbumId = config.albumId; $btnStart.disabled = false; startSlideshow(); return; }
if (config.showFavoritesOnly) { selectedSource = 'favorites'; $btnStart.disabled = false; startSlideshow(); return; }
if (params.album) { await autoLaunch('album', params.album, null); return; }
if (params.person) { await autoLaunch('person', null, params.person); return; }
if ('favorites' in params) { await autoLaunch('favorites', null, null); return; }
if ('random' in params) { await autoLaunch('random', null, null); return; }
// Check env-based auto-start
if (config.albumId) { await autoLaunch('album', config.albumId, null); return; }
if (config.showFavoritesOnly) { await autoLaunch('favorites', null, null); return; }
// No auto-start — show setup screen with album picker
await loadAlbums();
} catch (err) { showError('Failed to initialize: ' + err.message); }
}
@@ -77,11 +93,27 @@
};
async function loadAssets() {
if (selectedSource === 'album' && selectedAlbumId) { var al = await (await fetch('/api/albums/' + selectedAlbumId)).json(); assets = al.assets || []; }
else if (selectedSource === 'person' && selectedPersonId) { assets = await (await fetch('/api/people/' + selectedPersonId)).json(); }
else if (selectedSource === 'favorites') { assets = await (await fetch('/api/assets/favorites')).json(); }
else { assets = await (await fetch('/api/assets/random?count=100')).json(); }
var res;
if (selectedSource === 'album' && selectedAlbumId) {
res = await fetch('/api/albums/' + selectedAlbumId);
if (!res.ok) throw new Error('Album fetch failed: ' + res.status);
var al = await res.json();
assets = al.assets || [];
} else if (selectedSource === 'person' && selectedPersonId) {
res = await fetch('/api/people/' + selectedPersonId);
if (!res.ok) throw new Error('Person fetch failed: ' + res.status);
assets = await res.json();
} else if (selectedSource === 'favorites') {
res = await fetch('/api/assets/favorites');
if (!res.ok) throw new Error('Favorites fetch failed: ' + res.status);
assets = await res.json();
} else {
res = await fetch('/api/assets/random?count=100');
if (!res.ok) throw new Error('Random fetch failed: ' + res.status);
assets = await res.json();
}
if (config.shuffle) shuffleArray(assets);
console.log('Frambe: loaded ' + assets.length + ' photo(s) from ' + selectedSource);
}
function startRefreshTimer() {
@@ -101,24 +133,45 @@
}, (config.refreshInterval || 300) * 1000);
}
window.startSlideshow = async function () {
// --- Core slideshow start (used by both button click and auto-launch) ---
async function doStartSlideshow() {
if (!selectedSource) return;
$btnStart.disabled = true; $btnStart.innerHTML = '<span class="spinner"></span> Loading…';
try {
await loadAssets();
if (!assets.length) { $btnStart.textContent = 'No photos found'; setTimeout(function () { $btnStart.textContent = '▶ Start Slideshow'; $btnStart.disabled = false; }, 2000); return; }
$setupScreen.style.display = 'none'; $slideshowScreen.style.display = 'block';
document.body.classList.remove('setup-mode'); isRunning = true;
if (!assets.length) {
$btnStart.textContent = 'No photos found';
setTimeout(function () { $btnStart.textContent = '▶ Start Slideshow'; $btnStart.disabled = false; }, 2000);
return;
}
// Switch to slideshow view
$setupScreen.style.display = 'none';
$slideshowScreen.style.display = 'block';
document.body.classList.remove('setup-mode');
isRunning = true;
var t = (config.transitionDuration || 2) * 1000;
$layerA.style.transition = 'opacity ' + t + 'ms ease'; $layerB.style.transition = 'opacity ' + t + 'ms ease';
$layerA.style.transition = 'opacity ' + t + 'ms ease';
$layerB.style.transition = 'opacity ' + t + 'ms ease';
$bgBlur.style.transition = 'opacity ' + (t * 0.75) + 'ms ease';
if (!config.showClock) $clock.style.display = 'none'; if (!config.showDate) $dateDisplay.style.display = 'none';
if (!config.showExif) $exifInfo.style.display = 'none'; if (!config.showProgress) $progressBar.style.display = 'none';
if (!config.showClock) $clock.style.display = 'none';
if (!config.showDate) $dateDisplay.style.display = 'none';
if (!config.showExif) $exifInfo.style.display = 'none';
if (!config.showProgress) $progressBar.style.display = 'none';
if (!config.backgroundBlur) $bgBlur.style.display = 'none';
updateClock(); setInterval(updateClock, 1000);
currentIndex = -1; showNextPhoto(); scheduleOverlayHide(); startRefreshTimer();
} catch (err) { $btnStart.textContent = 'Error: ' + err.message; setTimeout(function () { $btnStart.textContent = '▶ Start Slideshow'; $btnStart.disabled = false; }, 3000); }
};
currentIndex = -1;
showNextPhoto();
scheduleOverlayHide();
startRefreshTimer();
} catch (err) {
console.error('Frambe: slideshow start failed', err);
$btnStart.textContent = 'Error: ' + err.message;
setTimeout(function () { $btnStart.textContent = '▶ Start Slideshow'; $btnStart.disabled = false; }, 3000);
}
}
// Exposed for the button onclick
window.startSlideshow = function () { doStartSlideshow(); };
window.exitSlideshow = function () {
if (urlDriven) { window.location.href = window.location.pathname; return; }