diff --git a/src/main.js b/src/main.js index e6acc67..852441a 100644 --- a/src/main.js +++ b/src/main.js @@ -41,15 +41,13 @@ async function doConnect() { const user = document.getElementById('srv-user').value.trim(); const pass = document.getElementById('srv-pass').value; const _prev = (() => { try { return JSON.parse(localStorage.getItem('ns_cfg') || '{}'); } catch { return {}; } })(); - const lfKey = document.getElementById('lastfm-key')?.value.trim() || _prev.lastfmKey || ''; - const backUrl = (document.getElementById('backend-url')?.value.trim() || _prev.backendUrl || '').replace(/\/$/,''); - const spId = document.getElementById('spotify-client-id')?.value.trim() || _prev.spotifyClientId || ''; - const spSecret = document.getElementById('spotify-client-secret')?.value.trim() || _prev.spotifyClientSecret || ''; + const lfKey = document.getElementById('lastfm-key')?.value.trim() || _prev.lastfmKey || ''; + const backUrl = (document.getElementById('backend-url')?.value.trim() || _prev.backendUrl || window.NS_BACKEND_URL?.trim() || '').replace(/\/$/,''); if(!url || !user || !pass) { _showSetupError('Bitte Server-URL, Benutzernamen und Passwort ausfüllen.'); return; } const btn = document.getElementById('btn-connect'); btn.disabled=true; btn.textContent='Verbinde…'; document.getElementById('setup-error').style.display='none'; - S.cfg = {url, user, pass, lastfmKey:lfKey, backendUrl:backUrl, spotifyClientId:spId, spotifyClientSecret:spSecret}; + S.cfg = {url, user, pass, lastfmKey:lfKey, backendUrl:backUrl}; try { await api('ping'); localStorage.setItem('ns_cfg', JSON.stringify(S.cfg)); @@ -66,7 +64,7 @@ function disconnect() { localStorage.removeItem('ns_cfg'); localStorage.removeItem('ns_last_played'); sessionStorage.removeItem('ns_nav'); - S.cfg = {url:'', user:'', pass:'', lastfmKey:'', backendUrl:'', spotifyClientId:'', spotifyClientSecret:''}; + S.cfg = {url:'', user:'', pass:'', lastfmKey:'', backendUrl:''}; S.queue=[]; S.qIdx=-1; S._navStack=[]; S._navCursor=-1; S.audio.pause(); S.audio.src=''; document.getElementById('app').style.display='none'; @@ -102,9 +100,12 @@ window.addEventListener('load', () => { S.previewAudio = document.getElementById('preview-audio'); const saved = localStorage.getItem('ns_cfg'); - if(saved) { S.cfg = JSON.parse(saved); startApp(); } + if(saved) { + S.cfg = JSON.parse(saved); + if(!S.cfg.backendUrl && window.NS_BACKEND_URL?.trim()) S.cfg.backendUrl = window.NS_BACKEND_URL.trim().replace(/\/$/,''); + startApp(); + } if(window.NS_SERVER_URL?.trim()) { const el=document.getElementById('srv-url'); if(el&&!el.value) el.value=window.NS_SERVER_URL.trim(); } - if(window.NS_BACKEND_URL?.trim()) { const el=document.getElementById('backend-url'); if(el&&!el.value) el.value=window.NS_BACKEND_URL.trim(); } document.getElementById('srv-pass').addEventListener('keydown', e => { if(e.key==='Enter') doConnect(); }); S.audio.addEventListener('timeupdate', updateProgress); diff --git a/src/state.js b/src/state.js index 1508a09..36216b5 100644 --- a/src/state.js +++ b/src/state.js @@ -1,6 +1,6 @@ // Shared mutable state — imported as { S } in every module export const S = { - cfg: { url: '', user: '', pass: '', lastfmKey: '', backendUrl: '', spotifyClientId: '', spotifyClientSecret: '' }, + cfg: { url: '', user: '', pass: '', lastfmKey: '', backendUrl: '' }, // Playback queue: [],