feat(ui): control image auto-process

This commit is contained in:
psychedelicious
2023-06-02 21:30:21 +10:00
parent fa290aff8d
commit 72b4371804
11 changed files with 395 additions and 45 deletions

View File

@ -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 { addControlNetProcessorParamsChangedListener } from './listeners/controlNetProcessorParamsChanged';
import { addControlNetAutoProcessListener } from './listeners/controlNetProcessorParamsChanged';
export const listenerMiddleware = createListenerMiddleware();
@ -178,4 +178,4 @@ addImageCategoriesChangedListener();
// ControlNet
addControlNetImageProcessedListener();
addControlNetProcessorParamsChangedListener();
addControlNetAutoProcessListener();

View File

@ -15,7 +15,10 @@ const moduleLog = log.child({ namespace: 'controlNet' });
export const addControlNetImageProcessedListener = () => {
startAppListening({
actionCreator: controlNetImageProcessed,
effect: async (action, { dispatch, getState, take }) => {
effect: async (
action,
{ dispatch, getState, take, unsubscribe, subscribe }
) => {
const { controlNetId } = action.payload;
const controlNet = getState().controlNet.controlNets[controlNetId];

View File

@ -2,6 +2,7 @@ import { startAppListening } from '..';
import { log } from 'app/logging/useLogger';
import { controlNetImageProcessed } from 'features/controlNet/store/actions';
import {
controlNetImageChanged,
controlNetProcessorParamsChanged,
controlNetProcessorTypeChanged,
} from 'features/controlNet/store/controlNetSlice';
@ -13,10 +14,11 @@ const moduleLog = log.child({ namespace: 'controlNet' });
*
* The network request is debounced by 1 second.
*/
export const addControlNetProcessorParamsChangedListener = () => {
export const addControlNetAutoProcessListener = () => {
startAppListening({
predicate: (action) =>
controlNetProcessorParamsChanged.match(action) ||
controlNetImageChanged.match(action) ||
controlNetProcessorTypeChanged.match(action),
effect: async (
action,
@ -35,11 +37,19 @@ export const addControlNetProcessorParamsChangedListener = () => {
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();
// Delay before starting actual work
await delay(1000);
await delay(300);
dispatch(controlNetImageProcessed({ controlNetId }));
},