diff --git a/invokeai/frontend/web/src/app/store/enhancers/reduxRemember/unserialize.ts b/invokeai/frontend/web/src/app/store/enhancers/reduxRemember/unserialize.ts index c6ae4946f2..c6af5f3612 100644 --- a/invokeai/frontend/web/src/app/store/enhancers/reduxRemember/unserialize.ts +++ b/invokeai/frontend/web/src/app/store/enhancers/reduxRemember/unserialize.ts @@ -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) => { diff --git a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/controlNetImageProcessed.ts b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/controlNetImageProcessed.ts index 00cc2d2474..7d3def3a8f 100644 --- a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/controlNetImageProcessed.ts +++ b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/controlNetImageProcessed.ts @@ -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({ diff --git a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/controlNetProcessorParamsChanged.ts b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/controlNetProcessorParamsChanged.ts index 315b793e53..5f71c1ed56 100644 --- a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/controlNetProcessorParamsChanged.ts +++ b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/controlNetProcessorParamsChanged.ts @@ -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();