From cac9d329e1f89a2539b4cce0f63430dabd599e47 Mon Sep 17 00:00:00 2001 From: Christian Herzog Date: Wed, 15 Apr 2020 21:40:00 +0200 Subject: [PATCH 1/2] fix message race condition --- components/wifi-manager/code.js | 23 ++++++++++++----------- components/wifi-manager/style.css | 1 + 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/components/wifi-manager/code.js b/components/wifi-manager/code.js index 054ac0ef..3b4bffd9 100644 --- a/components/wifi-manager/code.js +++ b/components/wifi-manager/code.js @@ -667,8 +667,8 @@ function refreshAPHTML(data){ } function getMessages() { - $.getJSON("/messages.json?1", function(data) { - data.forEach(function(msg) { + $.getJSON("/messages.json?1", async function(data) { + for (const msg of data) { var msg_age = msg["current_time"] - msg["sent_time"]; var msg_time = new Date(); msg_time.setTime( msg_time.getTime() - msg_age ); @@ -701,7 +701,7 @@ function getMessages() { }); break; case "MESSAGING_CLASS_SYSTEM": - showMessage(msg["message"], msg["type"],msg_age); + var r = await showMessage(msg["message"], msg["type"],msg_age); $("#syslogTable").append( ""+ @@ -713,8 +713,7 @@ function getMessages() { default: break; } - }); - + } }) .fail(function(xhr, ajaxOptions, thrownError) { console.log(xhr.status); @@ -961,16 +960,18 @@ function showMessage(message, severity, age=0) { } $('#message').html(message); - $("#content").fadeTo("slow", 0.3, function() { - $("#message").show(500).delay(5000).hide(500, function() { - $("#content").fadeTo("slow", 1.0); + return new Promise(function(resolve, reject) { + $("#content").fadeTo("slow", 0.3, function() { + $("#message").show(500).delay(5000).hide(500, function() { + $("#content").fadeTo("slow", 1.0, function() { + resolve(true); + }); + }); }); }); + } function inRange(x, min, max) { return ((x-min)*(x-max) <= 0); } - - - diff --git a/components/wifi-manager/style.css b/components/wifi-manager/style.css index bd2a170a..b6b6686d 100644 --- a/components/wifi-manager/style.css +++ b/components/wifi-manager/style.css @@ -386,6 +386,7 @@ div#message { margin-top: -2em; /*set to a negative number 1/2 of your height*/ border-radius: 8px; box-shadow: 0px 5px 2px -5px rgba(255, 255, 255, 0.5) inset, 0px 10px 20px -5px rgba(255, 255, 255, 0.1) inset, 0 0px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 3px 1px rgba(0, 0, 0, 0.12), 0 1px 10px 0 rgba(0, 0, 0, 0.3); + z-index: 20; } tr.hide { From bb44b3f718f7d50d0b483e55f3d050c493a5244d Mon Sep 17 00:00:00 2001 From: Christian Herzog Date: Thu, 16 Apr 2020 20:39:54 +0200 Subject: [PATCH 2/2] fix AP scan --- components/wifi-manager/code.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/components/wifi-manager/code.js b/components/wifi-manager/code.js index 3b4bffd9..6b54a4f4 100644 --- a/components/wifi-manager/code.js +++ b/components/wifi-manager/code.js @@ -643,16 +643,19 @@ function rssiToIcon(rssi){ function refreshAP(force){ if (!enableAPTimer && !force) return; - $.getJSON( "/ap.json", function( data ) { - if(data.length > 0){ - //sort by signal strength - data.sort(function (a, b) { - var x = a["rssi"]; var y = b["rssi"]; - return ((x < y) ? 1 : ((x > y) ? -1 : 0)); - }); - apList = data; - refreshAPHTML(apList); - } + $.getJSON( "/scan.json", async function( data ) { + await sleep(2000); + $.getJSON( "/ap.json", function( data ) { + if(data.length > 0){ + //sort by signal strength + data.sort(function (a, b) { + var x = a["rssi"]; var y = b["rssi"]; + return ((x < y) ? 1 : ((x > y) ? -1 : 0)); + }); + apList = data; + refreshAPHTML(apList); + } + }); }); } @@ -975,3 +978,7 @@ function showMessage(message, severity, age=0) { function inRange(x, min, max) { return ((x-min)*(x-max) <= 0); } + +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); +}