forked from extern/easydiffusion
Addressing Cmdr2's comments and more
Only triggers events when there actually was a state change. Also opportunistically removed the hardcoded delay in favor of an even-driven flow, which makes the whole thing more robust and much more reactive.
This commit is contained in:
parent
89170af721
commit
f7193966fb
@ -282,6 +282,7 @@ const TASK_MAPPING = {
|
|||||||
parse: (val) => val
|
parse: (val) => val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function restoreTaskToUI(task, fieldsToSkip) {
|
function restoreTaskToUI(task, fieldsToSkip) {
|
||||||
fieldsToSkip = fieldsToSkip || []
|
fieldsToSkip = fieldsToSkip || []
|
||||||
|
|
||||||
@ -311,27 +312,28 @@ function restoreTaskToUI(task, fieldsToSkip) {
|
|||||||
if (!('use_upscale' in task.reqBody)) {
|
if (!('use_upscale' in task.reqBody)) {
|
||||||
useUpscalingField.checked = false
|
useUpscalingField.checked = false
|
||||||
}
|
}
|
||||||
if (!('mask' in task.reqBody)) {
|
if (!('mask' in task.reqBody) && maskSetting.checked) {
|
||||||
maskSetting.checked = false
|
maskSetting.checked = false
|
||||||
maskSetting.dispatchEvent(new Event("click"))
|
maskSetting.dispatchEvent(new Event("click"))
|
||||||
}
|
}
|
||||||
upscaleModelField.disabled = !useUpscalingField.checked
|
upscaleModelField.disabled = !useUpscalingField.checked
|
||||||
upscaleAmountField.disabled = !useUpscalingField.checked
|
upscaleAmountField.disabled = !useUpscalingField.checked
|
||||||
|
|
||||||
// Show the source picture if present
|
// hide/show source picture as needed
|
||||||
initImagePreview.src = (task.reqBody.init_image == undefined ? '' : task.reqBody.init_image)
|
if (IMAGE_REGEX.test(initImagePreview.src) && task.reqBody.init_image == undefined) {
|
||||||
if (IMAGE_REGEX.test(initImagePreview.src)) {
|
// hide source image
|
||||||
initImagePreview.dispatchEvent(new Event("load"))
|
|
||||||
if (Boolean(task.reqBody.mask)) {
|
|
||||||
setTimeout(() => { // add a delay to insure this happens AFTER the main image loads (which reloads the inpainter)
|
|
||||||
imageInpainter.setImg(task.reqBody.mask)
|
|
||||||
}, 250)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
initImageClearBtn.dispatchEvent(new Event("click"))
|
initImageClearBtn.dispatchEvent(new Event("click"))
|
||||||
}
|
}
|
||||||
|
else if (task.reqBody.init_image !== undefined) {
|
||||||
|
// listen for inpainter loading event, which happens AFTER the main image loads (which reloads the inpainter)
|
||||||
|
document.addEventListener('imagePainterLoad', function() {
|
||||||
|
if (Boolean(task.reqBody.mask)) {
|
||||||
|
imageInpainter.setImg(task.reqBody.mask)
|
||||||
|
}
|
||||||
|
}, { once: true })
|
||||||
|
initImagePreview.src = task.reqBody.init_image
|
||||||
|
initImagePreview.dispatchEvent(new Event("load"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
function readUI() {
|
function readUI() {
|
||||||
const reqBody = {}
|
const reqBody = {}
|
||||||
|
@ -1373,6 +1373,7 @@ function img2imgLoad() {
|
|||||||
initImageSizeBox.textContent = initImagePreview.naturalWidth + " x " + initImagePreview.naturalHeight
|
initImageSizeBox.textContent = initImagePreview.naturalWidth + " x " + initImagePreview.naturalHeight
|
||||||
imageEditor.setImage(this.src, initImagePreview.naturalWidth, initImagePreview.naturalHeight)
|
imageEditor.setImage(this.src, initImagePreview.naturalWidth, initImagePreview.naturalHeight)
|
||||||
imageInpainter.setImage(this.src, parseInt(widthField.value), parseInt(heightField.value))
|
imageInpainter.setImage(this.src, parseInt(widthField.value), parseInt(heightField.value))
|
||||||
|
document.dispatchEvent(new Event("imagePainterLoad"))
|
||||||
}
|
}
|
||||||
|
|
||||||
function img2imgUnload() {
|
function img2imgUnload() {
|
||||||
|
Loading…
Reference in New Issue
Block a user