fix reconnecting issues

This commit is contained in:
MathMan05 2024-08-11 20:20:18 -05:00
parent a748e923fd
commit 2f8d55d0db
4 changed files with 6 additions and 2 deletions

View file

@ -37,6 +37,7 @@ function showAccountSwitcher() {
table.append(userinfo); table.append(userinfo);
userinfo.addEventListener("click", _ => { userinfo.addEventListener("click", _ => {
thisuser.unload(); thisuser.unload();
thisuser.swapped = true;
document.getElementById("loading").classList.remove("doneloading"); document.getElementById("loading").classList.remove("doneloading");
document.getElementById("loading").classList.add("loading"); document.getElementById("loading").classList.add("loading");
thisuser = new Localuser(specialuser); thisuser = new Localuser(specialuser);

View file

@ -111,6 +111,7 @@ class Localuser {
SnowFlake.clear(); SnowFlake.clear();
User.clear(); User.clear();
} }
swapped = false;
async initwebsocket() { async initwebsocket() {
let returny = null; let returny = null;
const promise = new Promise((res) => { returny = res; }); const promise = new Promise((res) => { returny = res; });
@ -210,7 +211,7 @@ class Localuser {
this.connectionSucceed = 0; this.connectionSucceed = 0;
document.getElementById("load-desc").innerHTML = "Unable to connect to the Spacebar server, retrying in <b>" + Math.round(0.2 + (this.errorBackoff * 2.8)) + "</b> seconds..."; document.getElementById("load-desc").innerHTML = "Unable to connect to the Spacebar server, retrying in <b>" + Math.round(0.2 + (this.errorBackoff * 2.8)) + "</b> seconds...";
setTimeout(() => { setTimeout(() => {
if (!this.initialized) if (this.swapped)
return; return;
document.getElementById("load-desc").textContent = "Retrying..."; document.getElementById("load-desc").textContent = "Retrying...";
this.initwebsocket().then(() => { this.initwebsocket().then(() => {

View file

@ -46,6 +46,7 @@ function showAccountSwitcher(){
table.append(userinfo); table.append(userinfo);
userinfo.addEventListener("click",_=>{ userinfo.addEventListener("click",_=>{
thisuser.unload(); thisuser.unload();
thisuser.swapped=true;
document.getElementById("loading").classList.remove("doneloading"); document.getElementById("loading").classList.remove("doneloading");
document.getElementById("loading").classList.add("loading"); document.getElementById("loading").classList.add("loading");
thisuser=new Localuser(specialuser); thisuser=new Localuser(specialuser);

View file

@ -117,6 +117,7 @@ class Localuser{
SnowFlake.clear(); SnowFlake.clear();
User.clear(); User.clear();
} }
swapped=false;
async initwebsocket():Promise<void>{ async initwebsocket():Promise<void>{
let returny=null let returny=null
const promise=new Promise((res)=>{returny=res}); const promise=new Promise((res)=>{returny=res});
@ -221,7 +222,7 @@ class Localuser{
document.getElementById("load-desc").innerHTML="Unable to connect to the Spacebar server, retrying in <b>" + Math.round(0.2 + (this.errorBackoff*2.8)) + "</b> seconds..."; document.getElementById("load-desc").innerHTML="Unable to connect to the Spacebar server, retrying in <b>" + Math.round(0.2 + (this.errorBackoff*2.8)) + "</b> seconds...";
setTimeout(() => { setTimeout(() => {
if(!this.initialized) return; if(this.swapped) return;
document.getElementById("load-desc").textContent="Retrying..."; document.getElementById("load-desc").textContent="Retrying...";
this.initwebsocket().then(() => { this.initwebsocket().then(() => {
this.loaduser(); this.loaduser();