From 6317cf8ef9a8afeaf36cd8c6b45453a0cda8458e Mon Sep 17 00:00:00 2001 From: chainchompa Date: Tue, 23 Jul 2024 13:13:09 -0400 Subject: [PATCH] move handleSimpleUpscaleModels logic into handleSpandrelImageToImageModels listener --- .../listeners/modelsLoaded.ts | 39 +++++-------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/modelsLoaded.ts b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/modelsLoaded.ts index 5d7213bb57..000154542e 100644 --- a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/modelsLoaded.ts +++ b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/modelsLoaded.ts @@ -43,7 +43,6 @@ export const addModelsLoadedListener = (startAppListening: AppStartListening) => handleLoRAModels(models, state, dispatch, log); handleControlAdapterModels(models, state, dispatch, log); handleSpandrelImageToImageModels(models, state, dispatch, log); - handleSimpleUpscaleModels(models, state, dispatch, log); }, }); }; @@ -187,41 +186,23 @@ const handleControlAdapterModels: ModelHandler = (models, state, dispatch, _log) }; const handleSpandrelImageToImageModels: ModelHandler = (models, state, dispatch, _log) => { - const currentUpscaleModel = state.upscale.upscaleModel; + const { upscaleModel: currentUpscaleModel, simpleUpscaleModel: currentSimpleUpscaleModel } = state.upscale; const upscaleModels = models.filter(isSpandrelImageToImageModelConfig); + const firstModel = upscaleModels[0] || null; - if (currentUpscaleModel) { - const isCurrentUpscaleModelAvailable = upscaleModels.some((m) => m.key === currentUpscaleModel.key); - if (isCurrentUpscaleModelAvailable) { - return; - } - } + const isCurrentUpscaleModelAvailable = currentUpscaleModel + ? upscaleModels.some((m) => m.key === currentUpscaleModel.key) + : false; - const firstModel = upscaleModels[0]; - if (firstModel) { + if (!isCurrentUpscaleModelAvailable) { dispatch(upscaleModelChanged(firstModel)); - return; } - dispatch(upscaleModelChanged(null)); -}; + const isCurrentSimpleUpscaleModelAvailable = currentSimpleUpscaleModel + ? upscaleModels.some((m) => m.key === currentSimpleUpscaleModel.key) + : false; -const handleSimpleUpscaleModels: ModelHandler = (models, state, dispatch, _log) => { - const currentSimpleUpscaleModel = state.upscale.simpleUpscaleModel; - const upscaleModels = models.filter(isSpandrelImageToImageModelConfig); - - if (currentSimpleUpscaleModel) { - const isCurrentSimpleUpscaleModelAvailable = upscaleModels.some((m) => m.key === currentSimpleUpscaleModel.key); - if (isCurrentSimpleUpscaleModelAvailable) { - return; - } - } - - const firstModel = upscaleModels[0]; - if (firstModel) { + if (!isCurrentSimpleUpscaleModelAvailable) { dispatch(simpleUpscaleModelChanged(firstModel)); - return; } - - dispatch(simpleUpscaleModelChanged(null)); };