feat(ui): do not autoprocess control if invocation in progress

This commit is contained in:
psychedelicious 2023-06-02 17:41:11 +10:00
parent 9cdad95f48
commit 2eb367969c
3 changed files with 28 additions and 1 deletions

View File

@ -1,4 +1,5 @@
import { initialCanvasState } from 'features/canvas/store/canvasSlice';
import { initialControlNetState } from 'features/controlNet/store/controlNetSlice';
import { initialGalleryState } from 'features/gallery/store/gallerySlice';
import { initialImagesState } from 'features/gallery/store/imagesSlice';
import { initialLightboxState } from 'features/lightbox/store/lightboxSlice';
@ -28,6 +29,7 @@ const initialStates: {
ui: initialUIState,
hotkeys: initialHotkeysState,
images: initialImagesState,
controlNet: initialControlNetState,
};
export const unserialize: UnserializeFunction = (data, key) => {

View File

@ -72,6 +72,11 @@ export const addControlNetImageProcessedListener = () => {
);
const processedControlImage = imageMetadataReceivedAction.payload;
moduleLog.debug(
{ data: { arg: action.payload, processedControlImage } },
'ControlNet image processed'
);
// Update the processed image in the store
dispatch(
controlNetProcessedImageChanged({

View File

@ -8,13 +8,33 @@ import {
const moduleLog = log.child({ namespace: 'controlNet' });
/**
* Listener that automatically processes a ControlNet image when its processor parameters are changed.
*
* The network request is debounced by 1 second.
*/
export const addControlNetProcessorParamsChangedListener = () => {
startAppListening({
predicate: (action) =>
controlNetProcessorParamsChanged.match(action) ||
controlNetProcessorTypeChanged.match(action),
effect: async (action, { dispatch, cancelActiveListeners, delay }) => {
effect: async (
action,
{ dispatch, getState, cancelActiveListeners, delay }
) => {
const state = getState();
if (!state.controlNet.shouldAutoProcess) {
// silently skip
return;
}
if (state.system.isProcessing) {
moduleLog.trace('System busy, skipping ControlNet auto-processing');
return;
}
const { controlNetId } = action.payload;
// Cancel any in-progress instances of this listener
cancelActiveListeners();