mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(ui): add mini/advanced controlnet ui
This commit is contained in:
@ -71,7 +71,7 @@ import { addStagingAreaImageSavedListener } from './listeners/stagingAreaImageSa
|
||||
import { addCommitStagingAreaImageListener } from './listeners/addCommitStagingAreaImageListener';
|
||||
import { addImageCategoriesChangedListener } from './listeners/imageCategoriesChanged';
|
||||
import { addControlNetImageProcessedListener } from './listeners/controlNetImageProcessed';
|
||||
import { addControlNetAutoProcessListener } from './listeners/controlNetProcessorParamsChanged';
|
||||
import { addControlNetAutoProcessListener } from './listeners/controlNetAutoProcess';
|
||||
|
||||
export const listenerMiddleware = createListenerMiddleware();
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { AnyAction } from '@reduxjs/toolkit';
|
||||
import { startAppListening } from '..';
|
||||
import { log } from 'app/logging/useLogger';
|
||||
import { controlNetImageProcessed } from 'features/controlNet/store/actions';
|
||||
@ -5,10 +6,37 @@ import {
|
||||
controlNetImageChanged,
|
||||
controlNetProcessorParamsChanged,
|
||||
controlNetProcessorTypeChanged,
|
||||
isControlNetImagePreprocessedToggled,
|
||||
} from 'features/controlNet/store/controlNetSlice';
|
||||
import { RootState } from 'app/store/store';
|
||||
|
||||
const moduleLog = log.child({ namespace: 'controlNet' });
|
||||
|
||||
const predicate = (action: AnyAction, state: RootState) => {
|
||||
const isActionMatched =
|
||||
controlNetProcessorParamsChanged.match(action) ||
|
||||
controlNetImageChanged.match(action) ||
|
||||
controlNetProcessorTypeChanged.match(action) ||
|
||||
isControlNetImagePreprocessedToggled.match(action);
|
||||
|
||||
if (!isActionMatched) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const { controlNetId } = action.payload;
|
||||
|
||||
const shouldAutoProcess =
|
||||
!state.controlNet.controlNets[controlNetId].isPreprocessed;
|
||||
|
||||
const isBusy = state.system.isProcessing;
|
||||
|
||||
const hasControlImage = Boolean(
|
||||
state.controlNet.controlNets[controlNetId].controlImage
|
||||
);
|
||||
|
||||
return shouldAutoProcess && !isBusy && hasControlImage;
|
||||
};
|
||||
|
||||
/**
|
||||
* Listener that automatically processes a ControlNet image when its processor parameters are changed.
|
||||
*
|
||||
@ -16,35 +44,13 @@ const moduleLog = log.child({ namespace: 'controlNet' });
|
||||
*/
|
||||
export const addControlNetAutoProcessListener = () => {
|
||||
startAppListening({
|
||||
predicate: (action) =>
|
||||
controlNetProcessorParamsChanged.match(action) ||
|
||||
controlNetImageChanged.match(action) ||
|
||||
controlNetProcessorTypeChanged.match(action),
|
||||
predicate,
|
||||
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;
|
||||
|
||||
if (!state.controlNet.controlNets[controlNetId].controlImage) {
|
||||
moduleLog.trace(
|
||||
{ data: { controlNetId } },
|
||||
'No ControlNet image to auto-process'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Cancel any in-progress instances of this listener
|
||||
cancelActiveListeners();
|
||||
|
Reference in New Issue
Block a user