childish attempts at trying to make extension iframe chill out with the requests
This commit is contained in:
parent
810e4a5a56
commit
158ae03ff7
1 changed files with 20 additions and 12 deletions
32
js/index.js
32
js/index.js
|
@ -366,7 +366,6 @@ async function testHostConnection() {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
document.getElementById("host").value + "/sdapi/v1/progress" // seems to be the "lightest" endpoint?
|
document.getElementById("host").value + "/sdapi/v1/progress" // seems to be the "lightest" endpoint?
|
||||||
);
|
);
|
||||||
const responseData = await response.json();
|
|
||||||
switch (response.status) {
|
switch (response.status) {
|
||||||
case 200: {
|
case 200: {
|
||||||
setConnectionStatus("online");
|
setConnectionStatus("online");
|
||||||
|
@ -445,7 +444,7 @@ async function testHostConnection() {
|
||||||
return status;
|
return status;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (focused) {
|
if (focused || firstTimeOnline) {
|
||||||
await checkConnection(!urlParams.has("noprompt"));
|
await checkConnection(!urlParams.has("noprompt"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -461,7 +460,7 @@ async function testHostConnection() {
|
||||||
|
|
||||||
// Checks every 5 seconds if offline, 60 seconds if online
|
// Checks every 5 seconds if offline, 60 seconds if online
|
||||||
const checkAgain = () => {
|
const checkAgain = () => {
|
||||||
if (focused) {
|
if (focused || firstTimeOnline) {
|
||||||
setTimeout(
|
setTimeout(
|
||||||
async () => {
|
async () => {
|
||||||
let simple = !firstTimeOnline;
|
let simple = !firstTimeOnline;
|
||||||
|
@ -470,7 +469,7 @@ async function testHostConnection() {
|
||||||
checkAgain();
|
checkAgain();
|
||||||
},
|
},
|
||||||
connectionStatus ? 60000 : 5000
|
connectionStatus ? 60000 : 5000
|
||||||
//connectionStatus ? 5000 : 5000 //TODO REMOVE DEBUG REPLACE TO 60000 : 5000
|
// connectionStatus ? 10000 : 1000 //TODO REMOVE DEBUG REPLACE TO 60000 : 5000
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
@ -478,13 +477,11 @@ async function testHostConnection() {
|
||||||
checkFocus();
|
checkFocus();
|
||||||
checkAgain();
|
checkAgain();
|
||||||
}, 60000);
|
}, 60000);
|
||||||
//}, 5000); //TODO REMOVE DEBUG REPLACE TO 60000
|
// }, 1000); //TODO REMOVE DEBUG REPLACE TO 60000
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (focused) {
|
checkAgain();
|
||||||
checkAgain();
|
|
||||||
}
|
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
checkConnection().catch(() => {});
|
checkConnection().catch(() => {});
|
||||||
|
@ -1295,11 +1292,22 @@ document.addEventListener("visibilitychange", () => {
|
||||||
checkFocus();
|
checkFocus();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
window.addEventListener("blur", () => {
|
||||||
|
checkFocus();
|
||||||
|
console.warn("openoutpaint unfocused");
|
||||||
|
});
|
||||||
|
|
||||||
|
window.addEventListener("focus", () => {
|
||||||
|
checkFocus();
|
||||||
|
console.warn("openoutpaint focused");
|
||||||
|
});
|
||||||
|
|
||||||
function checkFocus() {
|
function checkFocus() {
|
||||||
if (!document.hidden) {
|
let hasFocus = document.hasFocus();
|
||||||
focused = true;
|
if (document.hidden || !hasFocus) {
|
||||||
} else {
|
|
||||||
focused = false;
|
focused = false;
|
||||||
|
} else {
|
||||||
|
focused = true;
|
||||||
}
|
}
|
||||||
console.debug("FOCUSED: " + focused); //TODO comment out or something
|
console.debug("FOCUSED: " + focused); //TODO comment out or something //seriously it stops working without this here wtf
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue