From 548eefe7693226504a754dce377519c70c8c6f98 Mon Sep 17 00:00:00 2001 From: tim h Date: Sat, 7 Jan 2023 14:06:37 -0600 Subject: [PATCH 1/9] checks tab focus before doing XHR background stuff, replaces connectivity check endpoint for a lighter response --- js/index.js | 161 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 111 insertions(+), 50 deletions(-) diff --git a/js/index.js b/js/index.js index 7f341d4..6333aca 100644 --- a/js/index.js +++ b/js/index.js @@ -143,6 +143,7 @@ var stableDiffusionData = { var host = ""; var url = "/sdapi/v1/"; const basePixelCount = 64; //64 px - ALWAYS 64 PX +var focused = true; function startup() { testHostConfiguration(); @@ -168,6 +169,7 @@ function startup() { changeHiResSquare(); changeRestoreFaces(); changeSyncCursorSize(); + checkFocus(); } function setFixedHost(h, changePromptMessage) { @@ -335,7 +337,23 @@ async function testHostConnection() { 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) throw new CheckInProgressError( "Check is currently in progress, please try again" @@ -344,50 +362,64 @@ async function testHostConnection() { var url = document.getElementById("host").value + "/startup-events"; // Attempt normal request try { - // Check if API is available - const response = await fetch( - 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); - // 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; - } - 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; + if (simpleProgressStatus) { + const response = await fetch( + document.getElementById("host").value + "/sdapi/v1/progress" // seems to be the "lightest" endpoint? + ); + const responseData = await response.json(); + switch (response.status) { + case 200: { + setConnectionStatus("online"); + break; + } + case 404: { + apiIssueResult(); + break; + } + default: { + offlineResult(); } - break; } - case 404: { - 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); + } else { + // Check if API is available + const response = await fetch( + 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); - 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: { - setConnectionStatus("offline"); - const message = `The connection with the host returned an error: ${response.status} - ${response.statusText}`; - console.error(message); - if (notify) alert(message); + 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: { + apiIssueResult(); + break; + } + default: { + offlineResult(); + } } } } catch (e) { @@ -413,7 +445,9 @@ async function testHostConnection() { return status; }; - await checkConnection(!urlParams.has("noprompt")); + if (focused) { + await checkConnection(!urlParams.has("noprompt")); + } // On click, attempt to refresh connectionIndicator.onclick = async () => { @@ -425,18 +459,32 @@ 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 = () => { - setTimeout( - async () => { - await checkConnection(); + if (focused) { + setTimeout( + async () => { + let simple = !firstTimeOnline; + await checkConnection(false, simple); + checkFocus(); + checkAgain(); + }, + connectionStatus ? 60000 : 5000 + //connectionStatus ? 5000 : 5000 //TODO REMOVE DEBUG REPLACE TO 60000 : 5000 + ); + } else { + setTimeout(() => { + console.debug("unfocused, zzz"); + checkFocus(); checkAgain(); - }, - connectionStatus ? 30000 : 5000 - ); + }, 60000); + //}, 5000); //TODO REMOVE DEBUG REPLACE TO 60000 + } }; - checkAgain(); + if (focused) { + checkAgain(); + } return () => { checkConnection().catch(() => {}); @@ -1242,3 +1290,16 @@ function resetToDefaults() { localStorage.clear(); } } + +document.addEventListener("visibilitychange", () => { + checkFocus(); +}); + +function checkFocus() { + if (!document.hidden) { + focused = true; + } else { + focused = false; + } + console.debug("FOCUSED: " + focused); //TODO comment out or something +} From 810e4a5a568a447afb2ed0fe9ad864414f1d2b1a Mon Sep 17 00:00:00 2001 From: zero01101 Date: Sat, 7 Jan 2023 20:07:04 +0000 Subject: [PATCH 2/9] Fixed resource hashes --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index dcbf766..32decf1 100644 --- a/index.html +++ b/index.html @@ -357,7 +357,7 @@ - + - + - + - + @@ -368,10 +368,10 @@ - + diff --git a/js/ui/tool/dream.js b/js/ui/tool/dream.js index 7760de4..daa0670 100644 --- a/js/ui/tool/dream.js +++ b/js/ui/tool/dream.js @@ -177,6 +177,7 @@ const _dream = async (endpoint, request) => { * @returns {Promise} */ const _generate = async (endpoint, request, bb, options = {}) => { + var alertCount = 0; defaultOpt(options, { drawEvery: 0.2 / request.n_iter, keepUnmask: null, @@ -532,9 +533,14 @@ const _generate = async (endpoint, request, bb, options = {}) => { seeds.push(...dreamData.seeds); imageindextxt.textContent = `${at}/${images.length - 1}`; } catch (e) { - alert( - `Error generating images. Please try again or see console for more details` - ); + if (alertCount < 2) { + alert( + `Error generating images. Please try again or see console for more details` + ); + } else { + eagerGenerateCount = 0; + } + alertCount++; console.warn(`[dream] Error generating images:`); console.warn(e); } finally { From b166efc5e2ffde4b94bff583cb18fa397b88297a Mon Sep 17 00:00:00 2001 From: zero01101 Date: Sun, 8 Jan 2023 22:45:15 +0000 Subject: [PATCH 8/9] Fixed resource hashes --- index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 797c48d..2494d65 100644 --- a/index.html +++ b/index.html @@ -339,7 +339,7 @@ - + @@ -368,7 +368,7 @@ From 857cb29c121eb7a556ed2f58f783e02856a00c07 Mon Sep 17 00:00:00 2001 From: Victor Seiji Hariki Date: Tue, 10 Jan 2023 01:02:19 -0300 Subject: [PATCH 9/9] migrates vp to DOMMatrix implementation breaks select, but it was broken anyway. Signed-off-by: Victor Seiji Hariki --- css/layers.css | 1 + index.html | 17 +++--- js/initalize/layers.populate.js | 105 ++++++++++++++++++-------------- js/lib/util.js | 10 +++ js/ui/tool/colorbrush.js | 4 +- js/ui/tool/dream.js | 9 ++- js/ui/tool/generic.js | 9 ++- pages/configuration.html | 2 +- 8 files changed, 89 insertions(+), 68 deletions(-) diff --git a/css/layers.css b/css/layers.css index a4f2ee7..6b616f9 100644 --- a/css/layers.css +++ b/css/layers.css @@ -25,6 +25,7 @@ .layer-render-target .collection { position: absolute; + transform-origin: 0px 0px; } .layer-render-target .collection > .collection-input-overlay { diff --git a/index.html b/index.html index 2494d65..929997e 100644 --- a/index.html +++ b/index.html @@ -8,7 +8,7 @@ - + @@ -49,6 +49,7 @@ +
@@ -331,15 +332,15 @@
+ src="pages/configuration.html?v=7fca00b">
- + - + @@ -349,7 +350,7 @@ @@ -368,15 +369,15 @@ - +