Removed loadInfo().

Fixed UI when no WS available.
This commit is contained in:
Blaz Kristan 2021-11-21 14:14:39 +01:00
parent 47caa2c3a0
commit 295663f6a6
11 changed files with 3543 additions and 3526 deletions

View File

@ -512,10 +512,10 @@ class Animated_Staircase : public Usermod {
JsonArray usermodEnabled = staircase.createNestedArray(F("Staircase")); // name
String btn = F("<button class=\"btn infobtn\" onclick=\"requestJson({staircase:{enabled:");
if (enabled) {
btn += F("false}},false,false);loadInfo();\">");
btn += F("false}});\">");
btn += F("enabled");
} else {
btn += F("true}},false,false);loadInfo();\">");
btn += F("true}});\">");
btn += F("disabled");
}
btn += F("</button>");

View File

@ -279,10 +279,10 @@ public:
uiDomString += F(":{");
uiDomString += FPSTR(_enabled);
if (enabled) {
uiDomString += F(":false}});loadInfo();\">");
uiDomString += F(":false}});\">");
uiDomString += F("PIR <i class=\"icons\">&#xe325;</i>");
} else {
uiDomString += F(":true}});loadInfo();\">");
uiDomString += F(":true}});\">");
uiDomString += F("PIR <i class=\"icons\">&#xe08f;</i>");
}
uiDomString += F("</button>");

View File

@ -414,7 +414,7 @@ class MultiRelay : public Usermod {
uiDomString += i;
uiDomString += F(",on:");
uiDomString += _relay[i].state ? "false" : "true";
uiDomString += F("}});loadInfo();\">");
uiDomString += F("}});\">");
uiDomString += F("Relay ");
uiDomString += i;
uiDomString += F(" <i class=\"icons\">&#xe08f;</i></button>");

View File

@ -235,7 +235,7 @@
<div>
<!--table>
<tr>
<td class="keytd"--><button class="btn" onclick="loadInfo()">Refresh</button><!--/td>
<td class="keytd"--><button class="btn" onclick="requestJson()">Refresh</button><!--/td>
<td class="valtd"--><button class="btn" onclick="toggleInfo()">Close Info</button><!--/td>
</tr>
<tr>

View File

@ -255,7 +255,8 @@ function onLoad()
loadFX(()=>{
loadFXData();
loadPresets(()=>{
if (isObj(lastinfo) && isEmpty(lastinfo)) loadInfo(requestJson); // if not filled by WS
//if (isObj(lastinfo) && isEmpty(lastinfo)) loadInfo(requestJson); // if not filled by WS
requestJson();
});
});
});
@ -1354,23 +1355,21 @@ function requestJson(command=null)
gId('connind').style.backgroundColor = "var(--c-r)";
if (command && !reqsLegal) return; //stop post requests from chrome onchange event on page restore
if (!jsonTimeout) jsonTimeout = setTimeout(showErrorToast, 3000);
if (!command) command = {'v':true};
var req = null;
var url = (loc?`http://${locip}`:'') + '/json/state';
var url = (loc?`http://${locip}`:'') + '/json/si';
var useWs = (ws && ws.readyState === WebSocket.OPEN);
var type = command ? 'post':'get';
command.v = true; // force complete /json/si API response
command.time = Math.floor(Date.now() / 1000);
var t = gId('tt');
if (t.validity.valid && command.transition==null) {
var tn = parseInt(t.value*10);
if (tn != tr) command.transition = tn;
}
req = JSON.stringify(command);
if (req.length > 1000) useWs = false; //do not send very long requests over websocket
if (command) {
command.v = true; // force complete /json/si API response
command.time = Math.floor(Date.now() / 1000);
var t = gId('tt');
if (t.validity.valid && command.transition==null) {
var tn = parseInt(t.value*10);
if (tn != tr) command.transition = tn;
}
req = JSON.stringify(command);
if (req.length > 1000) useWs = false; //do not send very long requests over websocket
};
if (useWs) {
ws.send(req?req:'{"v":true}');
@ -1396,6 +1395,11 @@ function requestJson(command=null)
gId('connind').style.backgroundColor = "var(--c-g)";
if (!json) { showToast('Empty response', true); return; }
if (json.success) return;
if (json.info) {
lastinfo = json.info;
parseInfo();
if (isInfo) populateInfo();
}
var s = json.state ? json.state : json;
readState(s);
reqsLegal = true;
@ -1451,7 +1455,7 @@ function toggleInfo()
{
if (isNodes) toggleNodes();
isInfo = !isInfo;
if (isInfo) loadInfo();
if (isInfo) requestJson(); // loadInfo();
gId('info').style.transform = (isInfo) ? "translateY(0px)":"translateY(100%)";
gId('buttonI').className = (isInfo) ? "active":"";
}

View File

@ -175,7 +175,7 @@
</div><br>
<div id="kv">Loading...</div><br>
<div>
<button class="btn" onclick="loadInfo()">Refresh</button>
<button class="btn" onclick="requestJson()">Refresh</button>
<button class="btn" onclick="toggleInfo()">Close Info</button>
<button class="btn" onclick="toggleNodes()">Instance List</button>
<button class="btn" id="resetbtn" onclick="cnfReset()">Reboot WLED</button>

View File

@ -238,7 +238,8 @@ async function onLoad()
loadPalettesData(redrawPalPrev);
loadFX(()=>{
loadPresets(()=>{
if (isObj(lastinfo) && isEmpty(lastinfo)) loadInfo(requestJson); // if not filled by WS
//if (isObj(lastinfo) && isEmpty(lastinfo)) loadInfo(requestJson); // if not filled by WS
requestJson();
});
});
});
@ -987,17 +988,21 @@ function requestJson(command=null)
gId('connind').style.backgroundColor = "var(--c-r)";
if (command && !reqsLegal) return; //stop post requests from chrome onchange event on page restore
if (!jsonTimeout) jsonTimeout = setTimeout(showErrorToast, 3000);
if (!command) command = {'v':true};
var req = null;
var url = (loc?`http://${locip}`:'') + '/json/state';
var url = (loc?`http://${locip}`:'') + '/json/si';
var useWs = (ws && ws.readyState === WebSocket.OPEN);
var type = command ? 'post':'get';
command.v = true; // force complete /json/si API response
command.time = Math.floor(Date.now() / 1000);
command.transition = tr;
req = JSON.stringify(command);
if (req.length > 1000) useWs = false; //do not send very long requests over websocket
if (command) {
command.v = true; // force complete /json/si API response
command.time = Math.floor(Date.now() / 1000);
var t = gId('tt');
if (t.validity.valid && command.transition==null) {
var tn = parseInt(t.value*10);
if (tn != tr) command.transition = tn;
}
req = JSON.stringify(command);
if (req.length > 1000) useWs = false; //do not send very long requests over websocket
};
if (useWs) {
ws.send(req?req:'{"v":true}');
@ -1023,6 +1028,11 @@ function requestJson(command=null)
gId('connind').style.backgroundColor = "var(--c-g)";
if (!json) { showToast('Empty response', true); return; }
if (json.success) return;
if (json.info) {
lastinfo = json.info;
parseInfo();
if (isInfo) populateInfo();
}
var s = json.state ? json.state : json;
readState(s);
reqsLegal = true;
@ -1044,7 +1054,7 @@ function toggleInfo()
{
if (isNodes) toggleNodes();
isInfo = !isInfo;
if (isInfo) loadInfo();
if (isInfo) requestJson(); // loadInfo();
gId('info').style.transform = (isInfo) ? "translateY(0px)":"translateY(100%)";
}

File diff suppressed because it is too large Load Diff

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 2111201
#define VERSION 2111211
//uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG

View File

@ -124,6 +124,7 @@ void sendDataWs(AsyncWebSocketClient * client)
serializeState(state);
JsonObject info = doc.createNestedObject("info");
serializeInfo(info);
DEBUG_PRINTF("JSON buffer size: %u for WS request.\n", doc.memoryUsage());
size_t len = measureJson(doc);
buffer = ws.makeBuffer(len);
if (!buffer) {