diff --git a/htdocs/js/mympd.js b/htdocs/js/mympd.js index ff9691c..8dad859 100644 --- a/htdocs/js/mympd.js +++ b/htdocs/js/mympd.js @@ -183,6 +183,10 @@ function appGoto(a,t,v,s) { } function appRoute() { + if (settingsParsed == false) { + appInitStart(); + return; + } var hash = decodeURI(location.hash); var params; if (params = hash.match(/^\#\/(\w+)\/?(\w+)?\/?(\w+)?\!((\d+)\/([^\/]+)\/(.*))$/)) { @@ -359,6 +363,12 @@ function appRoute() { }; function appInitStart() { + document.getElementsByTagName('header')[0].classList.add('hide'); + document.getElementsByTagName('main')[0].classList.add('hide'); + document.getElementsByTagName('footer')[0].classList.add('hide'); + document.getElementById('appInitSettings').classList.add('unvisible'); + document.getElementById('appInitWebsocket').classList.add('unvisible'); + document.getElementById('appInitApply').classList.add('unvisible'); modalAppInit.show(); getSettings(); appInitWait(); @@ -388,7 +398,7 @@ function appInitWait() { } function appInit() { - //sendAPI({"cmd": "MPD_API_PLAYER_STATE"}, parseState); +// sendAPI({"cmd": "MPD_API_PLAYER_STATE"}, parseState); domCache.volumeBar.value = 0; @@ -1049,10 +1059,6 @@ function webSocketConnect() { try { socket.onopen = function() { console.log('Websocket is connected'); - showNotification('Connected to myMPD: ' + wsUrl, '', '', 'success'); - modalConnectionError.hide(); - appRoute(); - sendAPI({"cmd": "MPD_API_PLAYER_STATE"}, parseState); } socket.onmessage = function got_packet(msg) { @@ -1068,6 +1074,10 @@ function webSocketConnect() { switch (obj.type) { case 'welcome': websocketConnected = true; + showNotification('Connected to myMPD: ' + wsUrl, '', '', 'success'); + modalConnectionError.hide(); + appRoute(); + sendAPI({"cmd": "MPD_API_PLAYER_STATE"}, parseState); break; case 'update_state': parseState(obj); @@ -1649,7 +1659,7 @@ function parseState(obj) { setCounter(obj.data.currentSongId, obj.data.totalTime, obj.data.elapsedTime); //Get current song - if (lastState && lastState.data.currentSongId != obj.data.currentSongId) + if (!lastState || lastState.data.currentSongId != obj.data.currentSongId) sendAPI({"cmd": "MPD_API_PLAYER_CURRENT_SONG"}, songChange); //clear playback card if not playing if (obj.data.songPos == '-1') {