mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-11 05:57:05 +03:00
Wi fi manager (#22)
* resampling defaults * UI cleanup * turn of JSON timers when wifi is connected * enable/disable timers depending on connection status * trigger reboot if autoexec1 has changed * code cleanup/reorder, enable reboot buttons
This commit is contained in:
committed by
Sébastien
parent
618b82b497
commit
ff1df34355
@@ -4,172 +4,12 @@
|
||||
<meta charset="utf-8"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||
<script src="/jquery.js"></script>
|
||||
<link rel="stylesheet" href="/style.css">
|
||||
<script src="/jquery.js"></script>
|
||||
<script src="/code.js"></script>
|
||||
<title>esp32-wifi-manager</title>
|
||||
</head>
|
||||
|
||||
<script>
|
||||
var ws, sel, host, old, once = 0, jso, m;
|
||||
var to = 0, set_int = 0;
|
||||
|
||||
|
||||
|
||||
function get_radio(name)
|
||||
{
|
||||
var s = document.getElementsByName(name), sel;
|
||||
for ( var i = 0; i < s.length; i++)
|
||||
if (s[i].checked) {
|
||||
sel = s[i].value;
|
||||
break;
|
||||
}
|
||||
|
||||
return sel;
|
||||
}
|
||||
|
||||
function get_radio_index(name)
|
||||
{
|
||||
var s = document.getElementsByName(name), i;
|
||||
|
||||
for (i = 0; i < s.length; i++)
|
||||
if (s[i].checked)
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
function do_reset()
|
||||
{
|
||||
var s = "{\"reset\":\"1\"}";
|
||||
try {
|
||||
ws.send(s);
|
||||
} catch(exception) {
|
||||
alert('Sorry, there was a problem' + exception);
|
||||
}
|
||||
|
||||
ws.close();
|
||||
alert("Rebooting...");
|
||||
}
|
||||
|
||||
function file_change()
|
||||
{
|
||||
document.getElementById('update').disabled = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function do_upload(f)
|
||||
{
|
||||
var xhr = new XMLHttpRequest();
|
||||
|
||||
document.getElementById('update').disabled = 1;
|
||||
//ws.close();
|
||||
document.getElementById("progr").class = "progr-ok";
|
||||
|
||||
xhr.upload.addEventListener("progress", function(e) {
|
||||
document.getElementById("progr").value = parseInt(e.loaded / e.total * 100);
|
||||
|
||||
if (e.loaded == e.total) {
|
||||
// document.getElementById("realpage").style.display = "none";
|
||||
// document.getElementById("waiting").style.display = "block";
|
||||
}
|
||||
|
||||
}, false);
|
||||
|
||||
xhr.onreadystatechange = function(e) {
|
||||
console.log("rs" + xhr.readyState + " status " + xhr.status);
|
||||
if (xhr.readyState == 4) {
|
||||
/* it completed, for good or for ill */
|
||||
// document.getElementById("realpage").style.display = "none";
|
||||
// document.getElementById("waiting").style.display = "block";
|
||||
document.getElementById("progr").class = "progr-ok";
|
||||
console.log("upload reached state 4: xhr status " + xhr.status);
|
||||
setTimeout(function() { window.location.href = location.origin + "/"; }, 9000 );
|
||||
}
|
||||
};
|
||||
|
||||
/* kill the heart timer */
|
||||
clearInterval(set_int);
|
||||
|
||||
xhr.open("POST", f.action, true);
|
||||
xhr.send(new FormData(f));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function do_settings(f)
|
||||
{
|
||||
var xhr = new XMLHttpRequest();
|
||||
|
||||
xhr.onreadystatechange = function(e) {
|
||||
console.log("do_settings" + xhr.readyState + " status " + xhr.status);
|
||||
if (xhr.readyState == 4) {
|
||||
document.getElementById("updsettings").style.opacity = "1.0";
|
||||
document.getElementById("updsettings").disabled = 0;
|
||||
}
|
||||
};
|
||||
|
||||
xhr.open("POST", f.action, true);
|
||||
document.getElementById("updsettings").style.opacity = "0.3";
|
||||
document.getElementById("updsettings").disabled = 1;
|
||||
xhr.send(new FormData(f));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function get_latest(n)
|
||||
{
|
||||
if (n == 0)
|
||||
ws.send("update-ota");
|
||||
else
|
||||
ws.send("update-factory");
|
||||
}
|
||||
|
||||
|
||||
function heart_timer() {
|
||||
var s;
|
||||
|
||||
s = Math.round((95 * to) / (40 * 10)) / 100;
|
||||
|
||||
if (s < 0) {
|
||||
clearInterval(set_int);
|
||||
set_int = 0;
|
||||
|
||||
ws.close();
|
||||
|
||||
document.getElementById("realpage").style.opacity = "0.3";
|
||||
}
|
||||
|
||||
|
||||
to--;
|
||||
document.getElementById("heart").style.opacity = s;
|
||||
}
|
||||
|
||||
|
||||
function heartbeat()
|
||||
{
|
||||
to = 40 * 10;
|
||||
if (!set_int) {
|
||||
set_int = setInterval(heart_timer, 100);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function handleClick(cb) {
|
||||
console.log(cb);
|
||||
if (cb.id == 'autoexec-cb') {
|
||||
if (cb.checked) {
|
||||
$("#autoexec-command").show(200);
|
||||
} else {
|
||||
$("#autoexec-command").hide(200);
|
||||
}
|
||||
} else if (cb.id == 'autoexec-cb') {
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<body>
|
||||
<div id="app">
|
||||
<div id="app-wrap">
|
||||
|
||||
Reference in New Issue
Block a user