From 9ab0991f4d450083889aecce5d14d14c5dd7fa72 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Wed, 4 Jan 2023 13:33:27 -0500 Subject: [PATCH 1/2] fix leave-page alert --- js/ui/tool/dream.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/js/ui/tool/dream.js b/js/ui/tool/dream.js index 9792b3e..4649404 100644 --- a/js/ui/tool/dream.js +++ b/js/ui/tool/dream.js @@ -1,7 +1,6 @@ let blockNewImages = false; let generationQueue = []; let generationAreas = new Set(); -let generating = false; /** * Starts progress monitoring bar @@ -76,6 +75,17 @@ const _monitorProgress = (bb, oncheck = null) => { }; }; +let busy = false +const generating = (val) => { + console.log('GENERATING', val) + busy = val + if (busy) { + window.onbeforeunload = async () => { await sendInterrupt(); }; + } else { + window.onbeforeunload = null + } +} + /** * Starts a dream * @@ -129,7 +139,7 @@ const _dream = async (endpoint, request) => { /** @type {StableDiffusionResponse} */ let data = null; try { - generating = true; + generating(true); if ( endpoint == "txt2img" && request.enable_hr && @@ -176,7 +186,7 @@ const _dream = async (endpoint, request) => { data = await response.json(); } finally { - generating = false; + generating(false); } var responseSubdata = JSON.parse(data.info); var returnData = { @@ -724,9 +734,7 @@ const _generate = async (endpoint, request, bb, options = {}) => { mouse.listen.world.btn.middle.onclick.clear(onmorehandler); mouse.listen.world.onwheel.clear(onwheelhandler); isDreamComplete = true; - if (generating) { - sendInterrupt(); - } + generating(false) }; redraw(); @@ -2206,11 +2214,6 @@ const img2imgTool = () => } ); -window.onbeforeunload = async () => { - // Stop current generation on page close - if (generating) await sendInterrupt(); -}; - const sendSeed = (seed) => { stableDiffusionData.seed = document.getElementById("seed").value = seed; }; From 31dc797583b067e796fadae22936dda0d1a73dda Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Wed, 4 Jan 2023 16:07:16 -0500 Subject: [PATCH 2/2] remove debug console message --- js/ui/tool/dream.js | 1 - 1 file changed, 1 deletion(-) diff --git a/js/ui/tool/dream.js b/js/ui/tool/dream.js index 4649404..b3453c6 100644 --- a/js/ui/tool/dream.js +++ b/js/ui/tool/dream.js @@ -77,7 +77,6 @@ const _monitorProgress = (bb, oncheck = null) => { let busy = false const generating = (val) => { - console.log('GENERATING', val) busy = val if (busy) { window.onbeforeunload = async () => { await sendInterrupt(); };