Add separate imagegen stop button Closes #2591
| @@ -1,4 +1,8 @@ | ||
| 1 | 1 | <div id="sd_gen" class="list-group-item flex-container flexGap5"> |
| 2 | 2 | <div class="fa-solid fa-paintbrush extensionsMenuExtensionButton" title="Trigger Stable Diffusion" data-i18n="[title]Trigger Stable Diffusion" /></div> |
| 3 | 3 | <span>Generate Image</span> |
| 4 | +</div> | |
| 5 | +<div id="sd_stop_gen" class="list-group-item flex-container flexGap5"> | |
| 6 | + <div class="fa-solid fa-circle-stop extensionsMenuExtensionButton" title="Abort current image generation task" data-i18n="[title]Abort current image generation task"></div> | |
| 7 | + <span>Stop Image Generation</span> | |
| 4 | 8 | </div> |
| @@ -37,6 +37,7 @@ const MODULE_NAME = 'sd'; | ||
| 37 | 37 | const UPDATE_INTERVAL = 1000; |
| 38 | 38 | // This is a 1x1 transparent PNG |
| 39 | 39 | const PNG_PIXEL = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII='; |
| 40 | +const CUSTOM_STOP_EVENT = 'sd_stop_generation'; | |
| 40 | 41 | |
| 41 | 42 | const sources = { |
| 42 | 43 | extras: 'extras', |
| @@ -2290,6 +2291,7 @@ async function generatePicture(initiator, args, trigger, message, callback) { | ||
| 2290 | 2291 | |
| 2291 | 2292 | const dimensions = setTypeSpecificDimensions(generationType); |
| 2292 | 2293 | const abortController = new AbortController(); |
| 2294 | + const stopButton = document.getElementById('sd_stop_gen'); | |
| 2293 | 2295 | let negativePromptPrefix = args?.negative || ''; |
| 2294 | 2296 | let imagePath = ''; |
| 2295 | 2297 | |
| @@ -2300,9 +2302,8 @@ async function generatePicture(initiator, args, trigger, message, callback) { | ||
| 2300 | 2302 | const prompt = await getPrompt(generationType, message, trigger, quietPrompt, combineNegatives); |
| 2301 | 2303 | console.log('Processed image prompt:', prompt); |
| 2302 | 2304 | |
| 2303 | - eventSource.once(event_types.GENERATION_STOPPED, stopListener); | |
| 2305 | + $(stopButton).show(); | |
| 2304 | 2306 | contexteventSource.deactivateSendButtonsonce(CUSTOM_STOP_EVENT, stopListener); |
| 2305 | - hideSwipeButtons(); | |
| 2306 | 2307 | |
| 2307 | 2308 | if (typeof args?._abortController?.addEventListener === 'function') { |
| 2308 | 2309 | args._abortController.addEventListener('abort', stopListener); |
| @@ -2314,10 +2315,9 @@ async function generatePicture(initiator, args, trigger, message, callback) { | ||
| 2314 | 2315 | throw new Error('SD prompt text generation failed.'); |
| 2315 | 2316 | } |
| 2316 | 2317 | finally { |
| 2318 | + $(stopButton).hide(); | |
| 2317 | 2319 | restoreOriginalDimensions(dimensions); |
| 2318 | 2320 | eventSource.removeListener(event_types.GENERATION_STOPPEDCUSTOM_STOP_EVENT, stopListener); |
| 2319 | - context.activateSendButtons(); | |
| 2320 | - showSwipeButtons(); | |
| 2321 | 2321 | } |
| 2322 | 2322 | |
| 2323 | 2323 | return imagePath; |
| @@ -3425,6 +3425,10 @@ async function addSDGenButtons() { | ||
| 3425 | 3425 | generatePicture(initiators.wand, {}, param); |
| 3426 | 3426 | } |
| 3427 | 3427 | }); |
| 3428 | + | |
| 3429 | + const stopGenButton = $('#sd_stop_gen'); | |
| 3430 | + stopGenButton.hide(); | |
| 3431 | + stopGenButton.on('click', () => eventSource.emit(CUSTOM_STOP_EVENT)); | |
| 3428 | 3432 | } |
| 3429 | 3433 | |
| 3430 | 3434 | function isValidState() { |