diff options
author | Shin'ya UEOKA <ueokande@i-beam.org> | 2021-05-09 02:37:54 +0000 |
---|---|---|
committer | Shin'ya UEOKA <ueokande@i-beam.org> | 2021-05-09 02:37:54 +0000 |
commit | a7ade501f7c85632208c74e3553305c815159d01 (patch) | |
tree | 27a43ae9ba44cb295c4825d81fe52bc7cb9ef004 /src/background | |
parent | 48bee8f5d2b4a5c5996870b46afeadefed86106e (diff) |
Support reader-mode
Diffstat (limited to 'src/background')
-rw-r--r-- | src/background/operators/impls/TabOperatorFactoryChain.ts | 3 | ||||
-rw-r--r-- | src/background/operators/impls/ToggleReaderOperator.ts | 11 | ||||
-rw-r--r-- | src/background/presenters/TabPresenter.ts | 6 |
3 files changed, 20 insertions, 0 deletions
diff --git a/src/background/operators/impls/TabOperatorFactoryChain.ts b/src/background/operators/impls/TabOperatorFactoryChain.ts index edd3eaf..d526f86 100644 --- a/src/background/operators/impls/TabOperatorFactoryChain.ts +++ b/src/background/operators/impls/TabOperatorFactoryChain.ts @@ -16,6 +16,7 @@ import PinTabOperator from "./PinTabOperator"; import UnpinTabOperator from "./UnpinTabOperator"; import TogglePinnedTabOperator from "./TogglePinnedTabOperator"; import DuplicateTabOperator from "./DuplicateTabOperator"; +import ToggleReaderOperator from "./ToggleReaderOperator"; @injectable() export default class TabOperatorFactoryChain implements OperatorFactoryChain { @@ -58,6 +59,8 @@ export default class TabOperatorFactoryChain implements OperatorFactoryChain { return new TogglePinnedTabOperator(this.tabPresenter); case operations.TAB_DUPLICATE: return new DuplicateTabOperator(this.tabPresenter); + case operations.TAB_TOGGLE_READER: + return new ToggleReaderOperator(this.tabPresenter); } return null; } diff --git a/src/background/operators/impls/ToggleReaderOperator.ts b/src/background/operators/impls/ToggleReaderOperator.ts new file mode 100644 index 0000000..681e4c3 --- /dev/null +++ b/src/background/operators/impls/ToggleReaderOperator.ts @@ -0,0 +1,11 @@ +import Operator from "../Operator"; +import TabPresenter from "../../presenters/TabPresenter"; + +export default class ToggleReaderOperator implements Operator { + constructor(private readonly tabPresenter: TabPresenter) {} + + async run(): Promise<void> { + const tab = await this.tabPresenter.getCurrent(); + return this.tabPresenter.toggleReaderMode(tab.id as number); + } +} diff --git a/src/background/presenters/TabPresenter.ts b/src/background/presenters/TabPresenter.ts index 2f8f5d9..ef4b343 100644 --- a/src/background/presenters/TabPresenter.ts +++ b/src/background/presenters/TabPresenter.ts @@ -47,6 +47,8 @@ export default interface TabPresenter { onSelected( listener: (arg: { tabId: number; windowId: number }) => void ): void; + + toggleReaderMode(tabId: number): Promise<void>; } export class TabPresenterImpl implements TabPresenter { @@ -152,6 +154,10 @@ export class TabPresenterImpl implements TabPresenter { ): void { browser.tabs.onActivated.addListener(listener); } + + toggleReaderMode(tabId: number): Promise<void> { + return browser.tabs.toggleReaderMode(tabId); + } } const tabPresenter = new TabPresenterImpl(); |