diff --git a/lama_cleaner/app/src/components/Editor/Editor.tsx b/lama_cleaner/app/src/components/Editor/Editor.tsx index 6112632..234d76a 100644 --- a/lama_cleaner/app/src/components/Editor/Editor.tsx +++ b/lama_cleaner/app/src/components/Editor/Editor.tsx @@ -63,6 +63,7 @@ import emitter, { EVENT_PROMPT, EVENT_CUSTOM_MASK, EVENT_PAINT_BY_EXAMPLE, + RERUN_LAST_MASK, } from '../../event' import FileSelect from '../FileSelect/FileSelect' import InteractiveSeg from '../InteractiveSeg/InteractiveSeg' @@ -515,6 +516,28 @@ export default function Editor() { } }, [runInpainting]) + useEffect(() => { + emitter.on(RERUN_LAST_MASK, () => { + if (lastLineGroup.length !== 0) { + // 使用上一次手绘的 mask 生成 + runInpainting(true, undefined, prevInteractiveSegMask) + } else if (prevInteractiveSegMask) { + // 使用上一次 IS 的 mask 生成 + runInpainting(false, undefined, prevInteractiveSegMask) + } else { + setToastState({ + open: true, + desc: 'No mask to reuse', + state: 'error', + duration: 1500, + }) + } + }) + return () => { + emitter.off(RERUN_LAST_MASK) + } + }, [runInpainting]) + const hadRunInpainting = () => { return renders.length !== 0 } diff --git a/lama_cleaner/app/src/components/Header/Header.tsx b/lama_cleaner/app/src/components/Header/Header.tsx index d0d8293..844b5a5 100644 --- a/lama_cleaner/app/src/components/Header/Header.tsx +++ b/lama_cleaner/app/src/components/Header/Header.tsx @@ -1,6 +1,6 @@ import { FolderIcon, PhotoIcon } from '@heroicons/react/24/outline' -import { PlayIcon } from '@radix-ui/react-icons' -import React, { useState } from 'react' +import { PlayIcon, ReloadIcon } from '@radix-ui/react-icons' +import React, { useCallback, useState } from 'react' import { useRecoilState, useRecoilValue } from 'recoil' import * as PopoverPrimitive from '@radix-ui/react-popover' import { @@ -19,7 +19,7 @@ import { ThemeChanger } from './ThemeChanger' import SettingIcon from '../Settings/SettingIcon' import PromptInput from './PromptInput' import CoffeeIcon from '../CoffeeIcon/CoffeeIcon' -import emitter, { EVENT_CUSTOM_MASK } from '../../event' +import emitter, { EVENT_CUSTOM_MASK, RERUN_LAST_MASK } from '../../event' import { useImage } from '../../utils' import useHotKey from '../../hooks/useHotkey' @@ -49,6 +49,21 @@ const Header = () => { [showFileManager, enableFileManager, isInpainting] ) + const handleRerunLastMask = useCallback(() => { + emitter.emit(RERUN_LAST_MASK) + }, []) + + useHotKey( + 'r', + () => { + if (!isInpainting) { + handleRerunLastMask() + } + }, + {}, + [isInpainting, handleRerunLastMask] + ) + const renderHeader = () => { return (
@@ -57,7 +72,7 @@ const Header = () => { display: 'flex', justifyContent: 'center', alignItems: 'center', - gap: 8, + gap: 4, }} > {enableFileManager ? ( @@ -136,41 +151,53 @@ const Header = () => { - - setOpenMaskPopover(true)} - onMouseLeave={() => setOpenMaskPopover(false)} - style={{ - visibility: mask ? 'visible' : 'hidden', - outline: 'none', - }} - onClick={() => { - if (mask) { - emitter.emit(EVENT_CUSTOM_MASK, { mask }) - } - }} - > - - - - + setOpenMaskPopover(true)} + onMouseLeave={() => setOpenMaskPopover(false)} style={{ + visibility: mask ? 'visible' : 'hidden', outline: 'none', }} + onClick={() => { + if (mask) { + emitter.emit(EVENT_CUSTOM_MASK, { mask }) + } + }} > - {maskImageLoaded ? ( - mask - ) : ( - <> - )} - - - + + + + + {maskImageLoaded ? ( + mask + ) : ( + <> + )} + + + + ) : ( + <> + )} + +