fix leave-page alert

This commit is contained in:
Vladimir Mandic 2023-01-04 13:33:27 -05:00 committed by GitHub
parent 488e16ede1
commit 9ab0991f4d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,7 +1,6 @@
let blockNewImages = false; let blockNewImages = false;
let generationQueue = []; let generationQueue = [];
let generationAreas = new Set(); let generationAreas = new Set();
let generating = false;
/** /**
* Starts progress monitoring bar * 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 * Starts a dream
* *
@ -129,7 +139,7 @@ const _dream = async (endpoint, request) => {
/** @type {StableDiffusionResponse} */ /** @type {StableDiffusionResponse} */
let data = null; let data = null;
try { try {
generating = true; generating(true);
if ( if (
endpoint == "txt2img" && endpoint == "txt2img" &&
request.enable_hr && request.enable_hr &&
@ -176,7 +186,7 @@ const _dream = async (endpoint, request) => {
data = await response.json(); data = await response.json();
} finally { } finally {
generating = false; generating(false);
} }
var responseSubdata = JSON.parse(data.info); var responseSubdata = JSON.parse(data.info);
var returnData = { var returnData = {
@ -724,9 +734,7 @@ const _generate = async (endpoint, request, bb, options = {}) => {
mouse.listen.world.btn.middle.onclick.clear(onmorehandler); mouse.listen.world.btn.middle.onclick.clear(onmorehandler);
mouse.listen.world.onwheel.clear(onwheelhandler); mouse.listen.world.onwheel.clear(onwheelhandler);
isDreamComplete = true; isDreamComplete = true;
if (generating) { generating(false)
sendInterrupt();
}
}; };
redraw(); redraw();
@ -2206,11 +2214,6 @@ const img2imgTool = () =>
} }
); );
window.onbeforeunload = async () => {
// Stop current generation on page close
if (generating) await sendInterrupt();
};
const sendSeed = (seed) => { const sendSeed = (seed) => {
stableDiffusionData.seed = document.getElementById("seed").value = seed; stableDiffusionData.seed = document.getElementById("seed").value = seed;
}; };