Skip to content

Commit

Permalink
feat: refresh UI quicker when user is interacting
Browse files Browse the repository at this point in the history
The current 1sec delay can make the UI feel a bit laggy, so kick off
an refresh sooner whenever we react to user input.
  • Loading branch information
vapier committed Aug 17, 2020
1 parent 37188c5 commit 1369620
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions webui-page/webui.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ function send(command, param){
request.open("post", path);

request.send(null);
// Kick off a refresh quickly in response to user input.
refreshStatus(100);
}

function togglePlaylist() {
Expand Down Expand Up @@ -457,6 +459,17 @@ function handleStatusResponse(json) {
}
}

let nextRefresh;
function refreshStatus(timeout) {
if (nextRefresh) {
return;
}
nextRefresh = setTimeout(() => {
nextRefresh = undefined;
status();
}, timeout);
}

function status(){
var request = new XMLHttpRequest();
request.open("get", "/api/status");
Expand Down

0 comments on commit 1369620

Please sign in to comment.