This commit is contained in:
2026-01-11 08:19:27 +01:00
parent f2732b36f2
commit bdd3e30f14
17 changed files with 3088 additions and 23 deletions

View File

@@ -106,7 +106,7 @@ async function loadStations() {
try {
// stop any existing pollers before reloading stations
stopCurrentSongPollers();
const resp = await fetch('stations.json');
const resp = await fetch('/stations.json');
const raw = await resp.json();
// Normalize station objects so the rest of the app can rely on `name` and `url`.
@@ -152,6 +152,11 @@ async function loadStations() {
// Append user stations after file stations
stations = stations.concat(userNormalized);
// Debug: report how many stations we have after loading
try {
console.debug('loadStations: loaded stations count:', stations.length);
} catch (e) {}
if (stations.length > 0) {
// Try to restore last selected station by id
const lastId = getLastStationId();
@@ -163,6 +168,7 @@ async function loadStations() {
currentIndex = 0;
}
console.debug('loadStations: loading station index', currentIndex);
loadStation(currentIndex);
// start polling for currentSong endpoints (if any)
startCurrentSongPollers();
@@ -414,10 +420,9 @@ function updateNowPlayingUI() {
if (!station) return;
if (nowPlayingEl && nowArtistEl && nowTitleEl) {
// Show now-playing if we have either an artist or a title (some stations only provide title)
if (station.currentSongInfo && (station.currentSongInfo.artist || station.currentSongInfo.title)) {
nowArtistEl.textContent = station.currentSongInfo.artist || '';
nowTitleEl.textContent = station.currentSongInfo.title || '';
if (station.currentSongInfo && station.currentSongInfo.artist && station.currentSongInfo.title) {
nowArtistEl.textContent = station.currentSongInfo.artist;
nowTitleEl.textContent = station.currentSongInfo.title;
nowPlayingEl.classList.remove('hidden');
} else {
nowArtistEl.textContent = '';
@@ -680,13 +685,14 @@ function loadStation(index) {
}
});
} else {
// Fallback: show the full station name when no logo is provided
// Fallback to single-letter/logo text
logoImgEl.src = '';
logoImgEl.classList.add('hidden');
try {
logoTextEl.textContent = (station.name || '').trim();
} catch (e) {
logoTextEl.textContent = '';
const numberMatch = station.name.match(/\d+/);
if (numberMatch) {
logoTextEl.textContent = numberMatch[0];
} else {
logoTextEl.textContent = station.name.charAt(0).toUpperCase();
}
logoTextEl.classList.remove('hidden');
}
@@ -922,6 +928,15 @@ async function selectCastDevice(deviceName) {
window.addEventListener('DOMContentLoaded', init);
// Register Service Worker for PWA installation (non-disruptive)
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('sw.js')
.then((reg) => console.log('ServiceWorker registered:', reg.scope))
.catch((err) => console.debug('ServiceWorker registration failed:', err));
});
}
// Open overlay and show list of stations (used by menu/hamburger)
async function openStationsOverlay() {
castOverlay.classList.remove('hidden');