diff options
Diffstat (limited to 'src/background/usecases/StartFindUseCase.ts')
-rw-r--r-- | src/background/usecases/StartFindUseCase.ts | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/background/usecases/StartFindUseCase.ts b/src/background/usecases/StartFindUseCase.ts index 066d930..6aad962 100644 --- a/src/background/usecases/StartFindUseCase.ts +++ b/src/background/usecases/StartFindUseCase.ts @@ -2,7 +2,7 @@ import { inject, injectable } from "tsyringe"; import ConsoleClient from "../infrastructures/ConsoleClient"; import FindRepositoryImpl from "../repositories/FindRepository"; import FindClient from "../clients/FindClient"; -import FramePresenter from "../presenters/FramePresenter"; +import ReadyFrameRepository from "../repositories/ReadyFrameRepository"; @injectable() export default class StartFindUseCase { @@ -13,8 +13,8 @@ export default class StartFindUseCase { private readonly findRepository: FindRepositoryImpl, @inject("ConsoleClient") private readonly consoleClient: ConsoleClient, - @inject("FramePresenter") - private readonly framePresenter: FramePresenter + @inject("ReadyFrameRepository") + private readonly frameRepository: ReadyFrameRepository ) {} async startFind(tabId: number, keyword?: string): Promise<void> { @@ -31,21 +31,20 @@ export default class StartFindUseCase { this.findRepository.setGlobalKeyword(keyword); - const frameIds = await this.framePresenter.getAllFrameIds(tabId); + const frameIds = await this.frameRepository.getFrameIds(tabId); + if (typeof frameIds === "undefined") { + // No frames are ready + return; + } for (const frameId of frameIds) { await this.findClient.clearSelection(tabId, frameId); } - for (let framePos = 0; framePos < frameIds.length; ++framePos) { - const found = await this.findClient.findNext( - tabId, - frameIds[framePos], - keyword - ); + for (const frameId of frameIds) { + const found = await this.findClient.findNext(tabId, frameId, keyword); if (found) { await this.findRepository.setLocalState(tabId, { - frameIds, - framePos, + frameId, keyword, }); await this.consoleClient.showInfo(tabId, "Pattern found: " + keyword); |