Merge pull request #161 from zero01101/testing
relax with the background checks especially if the tab isn't focused
This commit is contained in:
commit
db3875ad09
2 changed files with 112 additions and 50 deletions
|
@ -357,7 +357,7 @@
|
||||||
|
|
||||||
<!-- Content -->
|
<!-- Content -->
|
||||||
<script src="js/prompt.js?v=7a1c68c" type="text/javascript"></script>
|
<script src="js/prompt.js?v=7a1c68c" type="text/javascript"></script>
|
||||||
<script src="js/index.js?v=c6539e5" type="text/javascript"></script>
|
<script src="js/index.js?v=b446b93" type="text/javascript"></script>
|
||||||
|
|
||||||
<script
|
<script
|
||||||
src="js/ui/floating/history.js?v=fc92d14"
|
src="js/ui/floating/history.js?v=fc92d14"
|
||||||
|
|
160
js/index.js
160
js/index.js
|
@ -143,6 +143,7 @@ var stableDiffusionData = {
|
||||||
var host = "";
|
var host = "";
|
||||||
var url = "/sdapi/v1/";
|
var url = "/sdapi/v1/";
|
||||||
const basePixelCount = 64; //64 px - ALWAYS 64 PX
|
const basePixelCount = 64; //64 px - ALWAYS 64 PX
|
||||||
|
var focused = true;
|
||||||
|
|
||||||
function startup() {
|
function startup() {
|
||||||
testHostConfiguration();
|
testHostConfiguration();
|
||||||
|
@ -168,6 +169,7 @@ function startup() {
|
||||||
changeHiResSquare();
|
changeHiResSquare();
|
||||||
changeRestoreFaces();
|
changeRestoreFaces();
|
||||||
changeSyncCursorSize();
|
changeSyncCursorSize();
|
||||||
|
checkFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
function setFixedHost(h, changePromptMessage) {
|
function setFixedHost(h, changePromptMessage) {
|
||||||
|
@ -335,7 +337,23 @@ async function testHostConnection() {
|
||||||
|
|
||||||
let checkInProgress = false;
|
let checkInProgress = false;
|
||||||
|
|
||||||
const checkConnection = async (notify = false) => {
|
const checkConnection = async (
|
||||||
|
notify = false,
|
||||||
|
simpleProgressStatus = false
|
||||||
|
) => {
|
||||||
|
const apiIssueResult = () => {
|
||||||
|
setConnectionStatus("apiissue");
|
||||||
|
const message = `The host is online, but the API seems to be disabled.\nHave you run the webui with the flag '--api', or is the flag '--gradio-debug' currently active?`;
|
||||||
|
console.error(message);
|
||||||
|
if (notify) alert(message);
|
||||||
|
};
|
||||||
|
|
||||||
|
const offlineResult = () => {
|
||||||
|
setConnectionStatus("offline");
|
||||||
|
const message = `The connection with the host returned an error: ${response.status} - ${response.statusText}`;
|
||||||
|
console.error(message);
|
||||||
|
if (notify) alert(message);
|
||||||
|
};
|
||||||
if (checkInProgress)
|
if (checkInProgress)
|
||||||
throw new CheckInProgressError(
|
throw new CheckInProgressError(
|
||||||
"Check is currently in progress, please try again"
|
"Check is currently in progress, please try again"
|
||||||
|
@ -344,50 +362,63 @@ async function testHostConnection() {
|
||||||
var url = document.getElementById("host").value + "/startup-events";
|
var url = document.getElementById("host").value + "/startup-events";
|
||||||
// Attempt normal request
|
// Attempt normal request
|
||||||
try {
|
try {
|
||||||
// Check if API is available
|
if (simpleProgressStatus) {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
document.getElementById("host").value + "/sdapi/v1/options"
|
document.getElementById("host").value + "/sdapi/v1/progress" // seems to be the "lightest" endpoint?
|
||||||
);
|
);
|
||||||
const optionsdata = await response.json();
|
switch (response.status) {
|
||||||
if (optionsdata["use_scale_latent_for_hires_fix"]) {
|
case 200: {
|
||||||
const message = `You are using an outdated version of A1111 webUI.\nThe HRfix options will not work until you update to at least commit ef27a18 or newer.\n(https://github.com/AUTOMATIC1111/stable-diffusion-webui/commit/ef27a18b6b7cb1a8eebdc9b2e88d25baf2c2414d)\nHRfix will fallback to half-resolution only.`;
|
setConnectionStatus("online");
|
||||||
console.warn(message);
|
break;
|
||||||
if (notify) alert(message);
|
}
|
||||||
// Hide all new hrfix options
|
case 404: {
|
||||||
document
|
apiIssueResult();
|
||||||
.querySelectorAll(".hrfix")
|
break;
|
||||||
.forEach((el) => (el.style.display = "none"));
|
}
|
||||||
|
default: {
|
||||||
// We are using old HRFix
|
offlineResult();
|
||||||
global.isOldHRFix = true;
|
|
||||||
stableDiffusionData.enable_hr = false;
|
|
||||||
}
|
|
||||||
switch (response.status) {
|
|
||||||
case 200: {
|
|
||||||
setConnectionStatus("online");
|
|
||||||
// Load data as soon as connection is first stablished
|
|
||||||
if (firstTimeOnline) {
|
|
||||||
getConfig();
|
|
||||||
getStyles();
|
|
||||||
getSamplers();
|
|
||||||
getUpscalers();
|
|
||||||
getModels();
|
|
||||||
firstTimeOnline = false;
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case 404: {
|
} else {
|
||||||
setConnectionStatus("apiissue");
|
// Check if API is available
|
||||||
const message = `The host is online, but the API seems to be disabled.\nHave you run the webui with the flag '--api', or is the flag '--gradio-debug' currently active?`;
|
const response = await fetch(
|
||||||
console.error(message);
|
document.getElementById("host").value + "/sdapi/v1/options"
|
||||||
|
);
|
||||||
|
const optionsdata = await response.json();
|
||||||
|
if (optionsdata["use_scale_latent_for_hires_fix"]) {
|
||||||
|
const message = `You are using an outdated version of A1111 webUI.\nThe HRfix options will not work until you update to at least commit ef27a18 or newer.\n(https://github.com/AUTOMATIC1111/stable-diffusion-webui/commit/ef27a18b6b7cb1a8eebdc9b2e88d25baf2c2414d)\nHRfix will fallback to half-resolution only.`;
|
||||||
|
console.warn(message);
|
||||||
if (notify) alert(message);
|
if (notify) alert(message);
|
||||||
break;
|
// Hide all new hrfix options
|
||||||
|
document
|
||||||
|
.querySelectorAll(".hrfix")
|
||||||
|
.forEach((el) => (el.style.display = "none"));
|
||||||
|
|
||||||
|
// We are using old HRFix
|
||||||
|
global.isOldHRFix = true;
|
||||||
|
stableDiffusionData.enable_hr = false;
|
||||||
}
|
}
|
||||||
default: {
|
switch (response.status) {
|
||||||
setConnectionStatus("offline");
|
case 200: {
|
||||||
const message = `The connection with the host returned an error: ${response.status} - ${response.statusText}`;
|
setConnectionStatus("online");
|
||||||
console.error(message);
|
// Load data as soon as connection is first stablished
|
||||||
if (notify) alert(message);
|
if (firstTimeOnline) {
|
||||||
|
getConfig();
|
||||||
|
getStyles();
|
||||||
|
getSamplers();
|
||||||
|
getUpscalers();
|
||||||
|
getModels();
|
||||||
|
firstTimeOnline = false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 404: {
|
||||||
|
apiIssueResult();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
offlineResult();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -413,7 +444,9 @@ async function testHostConnection() {
|
||||||
return status;
|
return status;
|
||||||
};
|
};
|
||||||
|
|
||||||
await checkConnection(!urlParams.has("noprompt"));
|
if (focused || firstTimeOnline) {
|
||||||
|
await checkConnection(!urlParams.has("noprompt"));
|
||||||
|
}
|
||||||
|
|
||||||
// On click, attempt to refresh
|
// On click, attempt to refresh
|
||||||
connectionIndicator.onclick = async () => {
|
connectionIndicator.onclick = async () => {
|
||||||
|
@ -425,15 +458,23 @@ async function testHostConnection() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Checks every 5 seconds if offline, 30 seconds if online
|
// Checks every 5 seconds if offline, 60 seconds if online
|
||||||
const checkAgain = () => {
|
const checkAgain = () => {
|
||||||
setTimeout(
|
checkFocus();
|
||||||
async () => {
|
if (focused || firstTimeOnline) {
|
||||||
await checkConnection();
|
setTimeout(
|
||||||
|
async () => {
|
||||||
|
let simple = !firstTimeOnline;
|
||||||
|
await checkConnection(false, simple);
|
||||||
|
checkAgain();
|
||||||
|
},
|
||||||
|
connectionStatus ? 60000 : 5000
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
setTimeout(() => {
|
||||||
checkAgain();
|
checkAgain();
|
||||||
},
|
}, 60000);
|
||||||
connectionStatus ? 30000 : 5000
|
}
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
checkAgain();
|
checkAgain();
|
||||||
|
@ -1242,3 +1283,24 @@ function resetToDefaults() {
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
document.addEventListener("visibilitychange", () => {
|
||||||
|
checkFocus();
|
||||||
|
});
|
||||||
|
|
||||||
|
window.addEventListener("blur", () => {
|
||||||
|
checkFocus();
|
||||||
|
});
|
||||||
|
|
||||||
|
window.addEventListener("focus", () => {
|
||||||
|
checkFocus();
|
||||||
|
});
|
||||||
|
|
||||||
|
function checkFocus() {
|
||||||
|
let hasFocus = document.hasFocus();
|
||||||
|
if (document.hidden || !hasFocus) {
|
||||||
|
focused = false;
|
||||||
|
} else {
|
||||||
|
focused = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue