Add separate imagegen stop button Closes #2591

41af05769bf0d8f8f553e2d9410f5f13f28dfc3f

Cohee <18619528+Cohee1207@users.noreply.github.com>

2 files changed, +15 -7Showing whitespace changes
public/scripts/extensions/stable-diffusion/button.html+5 -1
@@ -1,4 +1,8 @@
1<div id="sd_gen" class="list-group-item flex-container flexGap5">1<div id="sd_gen" class="list-group-item flex-container flexGap5">
2 <div class="fa-solid fa-paintbrush extensionsMenuExtensionButton" title="Trigger Stable Diffusion" data-i18n="[title]Trigger Stable Diffusion" /></div>2 <div class="fa-solid fa-paintbrush extensionsMenuExtensionButton" title="Trigger Stable Diffusion" data-i18n="[title]Trigger Stable Diffusion" /></div>
3 Generate Image3 <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</div>8</div>
public/scripts/extensions/stable-diffusion/index.js+10 -6
@@ -37,6 +37,7 @@ const MODULE_NAME = 'sd';
37const UPDATE_INTERVAL = 1000;37const UPDATE_INTERVAL = 1000;
38// This is a 1x1 transparent PNG38// This is a 1x1 transparent PNG
39const PNG_PIXEL = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=';39const PNG_PIXEL = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=';
40const CUSTOM_STOP_EVENT = 'sd_stop_generation';
4041
41const sources = {42const sources = {
42 extras: 'extras',43 extras: 'extras',
@@ -2290,6 +2291,7 @@ async function generatePicture(initiator, args, trigger, message, callback) {
22902291
2291 const dimensions = setTypeSpecificDimensions(generationType);2292 const dimensions = setTypeSpecificDimensions(generationType);
2292 const abortController = new AbortController();2293 const abortController = new AbortController();
2294 const stopButton = document.getElementById('sd_stop_gen');
2293 let negativePromptPrefix = args?.negative || '';2295 let negativePromptPrefix = args?.negative || '';
2294 let imagePath = '';2296 let imagePath = '';
22952297
@@ -2300,9 +2302,8 @@ async function generatePicture(initiator, args, trigger, message, callback) {
2300 const prompt = await getPrompt(generationType, message, trigger, quietPrompt, combineNegatives);2302 const prompt = await getPrompt(generationType, message, trigger, quietPrompt, combineNegatives);
2301 console.log('Processed image prompt:', prompt);2303 console.log('Processed image prompt:', prompt);
23022304
2303 eventSource.once(event_types.GENERATION_STOPPED, stopListener);2305 $(stopButton).show();
2304 context.deactivateSendButtons();2306 eventSource.once(CUSTOM_STOP_EVENT, stopListener);
2305 hideSwipeButtons();
23062307
2307 if (typeof args?._abortController?.addEventListener === 'function') {2308 if (typeof args?._abortController?.addEventListener === 'function') {
2308 args._abortController.addEventListener('abort', stopListener);2309 args._abortController.addEventListener('abort', stopListener);
@@ -2314,10 +2315,9 @@ async function generatePicture(initiator, args, trigger, message, callback) {
2314 throw new Error('SD prompt text generation failed.');2315 throw new Error('SD prompt text generation failed.');
2315 }2316 }
2316 finally {2317 finally {
2318 $(stopButton).hide();
2317 restoreOriginalDimensions(dimensions);2319 restoreOriginalDimensions(dimensions);
2318 eventSource.removeListener(event_types.GENERATION_STOPPED, stopListener);2320 eventSource.removeListener(CUSTOM_STOP_EVENT, stopListener);
2319 context.activateSendButtons();
2320 showSwipeButtons();
2321 }2321 }
23222322
2323 return imagePath;2323 return imagePath;
@@ -3425,6 +3425,10 @@ async function addSDGenButtons() {
3425 generatePicture(initiators.wand, {}, param);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}
34293433
3430function isValidState() {3434function isValidState() {