Skip to content

Commit

Permalink
Queue stat panel commands, ideally fixing another source of the recon…
Browse files Browse the repository at this point in the history
…nect bug (tgstation#59228)
  • Loading branch information
Mothblocks authored May 22, 2021
1 parent ea1479c commit a207239
Showing 1 changed file with 47 additions and 11 deletions.
58 changes: 47 additions & 11 deletions html/statbrowser.html
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,43 @@
var storedimages = [];
var split_admin_tabs = false;

var connected = false;
var commandQueue = [];

// Any BYOND verb call must go through this, as if a verb is sent during reconnect then
// it will cause the reconnect to fail.
// This function will either call immediately, or queue until
// BYOND confirms we are connected.
function send_byond_command(command) {
var href = "byond://winset?command=" + command;

if (connected) {
window.location.href = href;
} else {
commandQueue.push(href);
}
}

// Any BYOND commands that could result in the client's focus changing go through this
// to ensure that when we relinquish our focus, we don't do it after the result of
// a command has already taken focus for itself.
function send_byond_focus_command(url) {
setTimeout(function() {
window.location.href = url;
}, 0);
function run_after_focus(callback) {
setTimeout(callback, 0);
}

function connected_to_server() {
if (connected) {
return;
}

connected = true;

for (var index = 0; index < commandQueue.length; index++) {
// This is just setting it a lot, is this not going to cancel?
window.location.href = commandQueue[index];
}

commandQueue = [];
}

function update_split_admin_tabs(status) {
Expand Down Expand Up @@ -497,7 +527,7 @@

function update_verbs() {
wipe_verbs();
window.location.href = "byond://winset?command=Update-Verbs";
send_byond_command("Update-Verbs");
}

function add_verb_list(v) {
Expand Down Expand Up @@ -544,6 +574,7 @@
// passes a 2D list of (verbcategory, verbname) creates tabs and adds verbs to respective list
// example (IC, Say)
function init_verbs(c, v) {
connected_to_server();
wipe_verbs(); // remove all verb categories so we can replace them
checkStatusTab(); // remove all status tabs
verb_tabs = JSON.parse(c);
Expand Down Expand Up @@ -576,12 +607,12 @@
}

function SendTabToByond(tab) {
window.location.href = "byond://winset?command=Send-Tabs " + tab;
send_byond_command("Send-Tabs " + tab);
}

//Byond can't have this tab anymore since we're removing it
function TakeTabFromByond(tab) {
window.location.href = "byond://winset?command=Remove-Tabs " + tab;
send_byond_command("Remove-Tabs " + tab);
}

function update(global_data, ping_entry, other_entries) {
Expand Down Expand Up @@ -697,8 +728,9 @@
}

function set_byond_tab(tab){
window.location.href = "byond://winset?command=Set-Tab " + tab;
send_byond_command("Set-Tab " + tab);
}

function draw_debug() {
statcontentdiv[textContentKey] = "";
var wipeverbstabs = document.createElement("div");
Expand Down Expand Up @@ -788,7 +820,7 @@
}
if(verb_tabs.length == 0 || !verbs)
{
window.location.href = "byond://winset?command=Fix-Stat-Panel";
send_byond_command("Fix-Stat-Panel");
}
}

Expand Down Expand Up @@ -1094,7 +1126,9 @@

function make_verb_onclick(command) {
return function() {
send_byond_focus_command("byond://winset?command=" + command);
run_after_focus(function() {
send_byond_command(command);
});
};
}

Expand Down Expand Up @@ -1182,7 +1216,9 @@
}

function restoreFocus() {
send_byond_focus_command("byond://winset?map.focus=true")
run_after_focus(function() {
window.location.href = "byond://winset?map.focus=true";
});
}

document[addEventListenerKey]("mouseup", restoreFocus);
Expand Down

0 comments on commit a207239

Please sign in to comment.