More robust initial resource loading in UI

This commit is contained in:
Aircoookie 2021-07-07 23:45:53 +02:00
parent 14b7ec2a80
commit 17d2fb80f2
7 changed files with 813 additions and 787 deletions

View File

@ -2,6 +2,12 @@
### Builds after release 0.12.0
#### Build 2107070
- More robust initial resource loading in UI
- Fixed preset saving over websocket
- Alpha ESP32 S2 support (filesystem does not work) (PR #2067)
#### Build 2107041
- Restored support for "PL=~" mistakenly removed in 2106300

View File

@ -670,10 +670,11 @@ class PolyBus {
uint8_t offset = 0; //0 = RMT (num 0-7) 8 = I2S0 9 = I2S1
#ifndef CONFIG_IDF_TARGET_ESP32S2
if (num > 9) return I_NONE;
#else
if (num > 8) return I_NONE;
#endif
if (num > 7) offset = num -7;
#else //ESP32 S2 only has 4 RMT channels
if (num > 5) return I_NONE;
if (num > 4) offset = num -4;
#endif
switch (busType) {
case TYPE_WS2812_RGB:
case TYPE_WS2812_WWA:

View File

@ -365,8 +365,22 @@ function presetError(empty)
if (hasBackup) d.getElementById('bck').value = bckstr;
}
function loadPresets()
function loadPresets(callback = null)
{
//1st boot (because there is a callback)
if (callback && pmt == pmtLS && pmt > 0) {
//we have a copy of the presets in local storage and don't need to fetch another one
populatePresets(true);
pmtLast = pmt;
callback();
return;
}
//afterwards
if (!callback && pmt == pmtLast) return;
pmtLast = pmt;
var url = '/presets.json';
if (loc) {
url = `http://${locip}/presets.json`;
@ -390,6 +404,9 @@ function loadPresets()
showToast(error, true);
console.log(error);
presetError(false);
})
.finally(() => {
if (callback) setTimeout(callback,99);
});
}
@ -1025,7 +1042,7 @@ function readState(s,command=false) {
var jsonTimeout;
var reqsLegal = false;
function requestJson(command, rinfo = true, verbose = true) {
function requestJson(command, rinfo = true) {
d.getElementById('connind').style.backgroundColor = "#a90";
if (command && !reqsLegal) return; //stop post requests from chrome onchange event on page restore
lastUpdate = new Date();
@ -1040,7 +1057,7 @@ function requestJson(command, rinfo = true, verbose = true) {
var type = command ? 'post':'get';
if (command)
{
command.v = verbose;
command.v = true; //get complete API response
command.time = Math.floor(Date.now() / 1000);
req = JSON.stringify(command);
}
@ -1079,17 +1096,18 @@ function requestJson(command, rinfo = true, verbose = true) {
if (!command || rinfo) { //we have info object
if (!rinfo) { //entire JSON (on load)
pmt = json.info.fs.pmt;
if (pmt != pmtLS || pmt == 0) {
setTimeout(loadPresets,99);
}
else {
populatePresets(true);
}
pmtLast = pmt;
populateEffects(json.effects);
populatePalettes(json.palettes);
//load palette previews, presets, and open websocket sequentially
setTimeout(function(){
loadPresets(function(){
loadPalettesData(function(){
if (!ws && json.info.ws > -1) makeWS();
});
});
},25);
reqsLegal = true;
}
@ -1111,12 +1129,9 @@ function requestJson(command, rinfo = true, verbose = true) {
syncTglRecv = info.str;
maxSeg = info.leds.maxseg;
pmt = info.fs.pmt;
if (!ws && info.ws > -1) setTimeout(makeWS,1000);
if (!command && pmt != pmtLast) {
setTimeout(loadPresets,99);
}
pmtLast = pmt;
if (!command && rinfo) setTimeout(loadPresets, 99);
d.getElementById('buttonNodes').style.display = (info.ndc > 0 && window.innerWidth > 770) ? "block":"none";
lastinfo = info;
if (isInfo) {
@ -1124,8 +1139,6 @@ function requestJson(command, rinfo = true, verbose = true) {
}
s = json.state;
displayRover(info, s);
if (!rinfo) loadPalettesData();
}
readState(s,command);
@ -1784,7 +1797,7 @@ function rSegs()
requestJson(obj);
}
function loadPalettesData()
function loadPalettesData(callback = null)
{
if (palettesData) return;
const lsKey = "wledPalx";
@ -1795,6 +1808,8 @@ function loadPalettesData()
var d = new Date();
if (palettesDataJson && palettesDataJson.vid == lastinfo.vid) {
palettesData = palettesDataJson.p;
//redrawPalPrev() //?
if (callback) callback();
return;
}
} catch (e) {}
@ -1807,6 +1822,7 @@ function loadPalettesData()
vid: lastinfo.vid
}));
redrawPalPrev();
if (callback) setTimeout(callback, 99); //go on to connect websocket
});
}
@ -1840,7 +1856,6 @@ function getPalettesData(page, callback)
.catch(function (error) {
showToast(error, true);
console.log(error);
presetError(false);
});
}

View File

@ -397,7 +397,7 @@ type="submit">Save & Reboot</button></form></body></html>)=====";
// Autogenerated from wled00/data/settings_um.htm, do not edit!!
const char PAGE_settings_um[] PROGMEM = R"=====(<!DOCTYPE html><html><head lang="en"><meta charset="utf-8"><meta
name="viewport" content="width=500"><title>Usermod Settings</title><script>
var owner,locip,urows,d=document,umCfg={},pins=[6,7,8,9,10,11],pinO=["rsvd","rsvd","rsvd","rsvd","rsvd","rsvd"],loc=!1,numM=0;function gId(e){return d.getElementById(e)}function isO(e){return e&&"object"==typeof e&&!Array.isArray(e)}function H(){window.open("https://github.com/Aircoookie/WLED/wiki/Settings#usermod-settings")}function B(){window.open("/settings","_self")}function S(){"file:"==window.location.protocol&&(loc=!0,(locip=localStorage.getItem("locIp"))||(locip=prompt("File Mode. Please enter WLED IP!"),localStorage.setItem("locIp",locip))),GetV(),numM>0||locip?ldS():gId("um").innerHTML="No Usermods installed."}function isF(e){return e===+e&&e!==(0|e)}function isI(e){return e===+e&&e===(0|e)}function check(e,n){var i=e.name.replace("[]","").substr(-3);if("number"==e.type&&"pin"==i.substr(0,3))for(var t=0;t<pins.length;t++)if(n!=pinO[t]){if(e.value==pins[t]||e.value<-1||e.value>39){e.style.color="red";break}e.style.color=e.value>33?"orange":"#fff"}}function getPins(e){if(isO(e))for(const[i,t]of Object.entries(e))if(isO(t))owner=i,getPins(t);else if("pin"==i.replace("[]","").substr(-3))if(Array.isArray(t))for(var n=0;n<t.length;n++)t[n]>=0&&(pins.push(t[n]),pinO.push(owner));else t>=0&&(pins.push(t),pinO.push(owner));else if(Array.isArray(t))for(n=0;n<t.length;n++)getPins(t[n])}function addField(e,n,i,t=!1){if(isO(i))for(const[t,o]of Object.entries(i))"unknown"===n||e.includes(":")?addField(e,t,o):addField(e+":"+n,t,o);else if(Array.isArray(i))for(var o=0;o<i.length;o++)addField(e,n,i[o],!0);else{var s,r=typeof i;switch(r){case"boolean":r="checkbox",s='value="true"'+(i?" checked":"");break;case"number":s=`value="${i}"`,"pin"===n.substr(-3)?(s+=' max="39" min="-1" style="width:40px;"',r="int"):s+=' step="0.00001" style="width:80px;"';break;default:r="text",s=`value="${i}" style="width:250px;"`}e.includes(":")&&(urows+=e.substr(e.indexOf(":")+1)),urows+=` ${n}: `,"checkbox"==r?urows+=`<input type="hidden" name="${e}:${n}${t?"[]":""}" value="false">`:t||(urows+=`<input type="hidden" name="${e}:${n}${t?"[]":""}" value="${r}">`),urows+=`<input type="${"int"===r?"number":r}" name="${e}:${n}${t?"[]":""}" ${s} oninput="check(this,'${e.substr(e.indexOf(":")+1)}')"><br>`}}function ldS(){fetch((loc?"http://"+locip:"")+"/cfg.json",{method:"get"}).then(e=>(e.ok||(gId("lserr").style.display="inline"),e.json())).then(e=>{if(umCfg=e.um,getPins(e),urows="",isO(umCfg))for(const[e,n]of Object.entries(umCfg))urows+=`<hr><h3>${e}</h3>`,addField(e,"unknown",n);""===urows&&(urows="Usermods configuration not found.<br>Press <i>Save</i> to initialize defaults."),gId("um").innerHTML=urows}).catch((function(e){gId("lserr").style.display="inline",console.log(e)}))}function svS(e){e.preventDefault(),console.log(d.Sf),d.Sf.checkValidity()&&d.Sf.submit()}function GetV() {var d=document;
var owner,locip,urows,d=document,umCfg={},pins=[6,7,8,9,10,11],pinO=["rsvd","rsvd","rsvd","rsvd","rsvd","rsvd"],loc=!1,numM=0;function gId(e){return d.getElementById(e)}function isO(e){return e&&"object"==typeof e&&!Array.isArray(e)}function H(){window.open("https://github.com/Aircoookie/WLED/wiki/Settings#usermod-settings")}function B(){window.open("/settings","_self")}function S(){"file:"==window.location.protocol&&(loc=!0,(locip=localStorage.getItem("locIp"))||(locip=prompt("File Mode. Please enter WLED IP!"),localStorage.setItem("locIp",locip))),GetV(),numM>0||locip?ldS():gId("um").innerHTML="No Usermods installed."}function isF(e){return e===+e&&e!==(0|e)}function isI(e){return e===+e&&e===(0|e)}function check(e,n){var i=e.name.replace("[]","").substr(-3);if("number"==e.type&&"pin"==i.substr(0,3))for(var t=0;t<pins.length;t++)if(n!=pinO[t]){if(e.value==pins[t]||e.value<-1||e.value>39){e.style.color="red";break}e.style.color=e.value>33?"orange":"#fff"}}function getPins(e){if(isO(e))for(const[i,t]of Object.entries(e))if(isO(t))owner=i,getPins(t);else if("pin"==i.replace("[]","").substr(-3))if(Array.isArray(t))for(var n=0;n<t.length;n++)t[n]>=0&&(pins.push(t[n]),pinO.push(owner));else t>=0&&(pins.push(t),pinO.push(owner));else if(Array.isArray(t))for(n=0;n<t.length;n++)getPins(t[n])}function addField(e,n,i,t=!1){if(isO(i))for(const[t,o]of Object.entries(i))"unknown"===n||e.includes(":")?addField(e,t,o):addField(e+":"+n,t,o);else if(Array.isArray(i))for(var o=0;o<i.length;o++)addField(e,n,i[o],!0);else{var s,r=typeof i;switch(r){case"boolean":r="checkbox",s='value="true"'+(i?" checked":"");break;case"number":s=`value="${i}"`,"pin"===n.substr(-3)?(s+=' max="39" min="-1" style="width:40px;"',r="int"):s+=' step="any" style="width:100px;"';break;default:r="text",s=`value="${i}" style="width:250px;"`}e.includes(":")&&(urows+=e.substr(e.indexOf(":")+1)),urows+=` ${n}: `,"checkbox"==r?urows+=`<input type="hidden" name="${e}:${n}${t?"[]":""}" value="false">`:t||(urows+=`<input type="hidden" name="${e}:${n}${t?"[]":""}" value="${r}">`),urows+=`<input type="${"int"===r?"number":r}" name="${e}:${n}${t?"[]":""}" ${s} oninput="check(this,'${e.substr(e.indexOf(":")+1)}')"><br>`}}function ldS(){fetch((loc?"http://"+locip:"")+"/cfg.json",{method:"get"}).then(e=>(e.ok||(gId("lserr").style.display="inline"),e.json())).then(e=>{if(umCfg=e.um,getPins(e),urows="",isO(umCfg))for(const[e,n]of Object.entries(umCfg))urows+=`<hr><h3>${e}</h3>`,addField(e,"unknown",n);""===urows&&(urows="Usermods configuration not found.<br>Press <i>Save</i> to initialize defaults."),gId("um").innerHTML=urows}).catch((function(e){gId("lserr").style.display="inline",console.log(e)}))}function svS(e){e.preventDefault(),console.log(d.Sf),d.Sf.checkValidity()&&d.Sf.submit()}function GetV() {var d=document;
%CSS%%SCSS%</head><body onload="S()"><form
id="form_s" name="Sf" method="post" onsubmit="svS(event)"><div class="toprow">
<div class="helpB"><button type="button" onclick="H()">?</button></div><button

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,7 @@
*/
// version code in format yymmddb (b = daily build)
#define VERSION 2107042
#define VERSION 2107070
//uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG

View File

@ -38,8 +38,9 @@ void wsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventTyp
{
wsLiveClientId = root["lv"] ? client->id() : 0;
}
fileDoc = &jsonBuffer;
verboseResponse = deserializeState(root);
fileDoc = nullptr;
}
//update if it takes longer than 300ms until next "broadcast"
if (verboseResponse && (millis() - lastInterfaceUpdate < 1700 || !interfaceUpdateCallMode)) sendDataWs(client);