aboutsummaryrefslogtreecommitdiff
path: root/src/background/completion/TabCompletionUseCase.ts
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2020-03-28 21:35:06 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2020-03-28 21:43:40 +0900
commitea63c5f78b4c985e9d6dd106afe4f97bfeedbcd0 (patch)
treef0accb862f9f3b75c8c86f78361e2acab46f11ef /src/background/completion/TabCompletionUseCase.ts
parenta8d78f1286fb3fe456a786b2c0e534d212835560 (diff)
Complete tabs by the completion packages
Diffstat (limited to 'src/background/completion/TabCompletionUseCase.ts')
-rw-r--r--src/background/completion/TabCompletionUseCase.ts34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/background/completion/TabCompletionUseCase.ts b/src/background/completion/TabCompletionUseCase.ts
new file mode 100644
index 0000000..7e6dce3
--- /dev/null
+++ b/src/background/completion/TabCompletionUseCase.ts
@@ -0,0 +1,34 @@
+import { inject, injectable } from "tsyringe";
+import TabItem from "./TabItem";
+import TabRepository from "./TabRepository";
+import TabPresenter from "../presenters/TabPresenter";
+import TabFlag from "../../shared/TabFlag";
+
+@injectable()
+export default class TabCompletionUseCase {
+ constructor(
+ @inject('TabRepository') private tabRepository: TabRepository,
+ @inject('TabPresenter') private tabPresenter: TabPresenter,
+ ) {
+ }
+
+ async queryTabs(query: string, excludePinned: boolean): Promise<TabItem[]> {
+ const lastTabId = await this.tabPresenter.getLastSelectedId();
+ const tabs = await this.tabRepository.queryTabs(query, excludePinned);
+ return tabs.map(tab => {
+ let flag = TabFlag.None;
+ if (tab.active) {
+ flag = TabFlag.CurrentTab
+ } else if (tab.id == lastTabId) {
+ flag = TabFlag.LastTab
+ }
+ return {
+ index: tab.index + 1,
+ flag: flag,
+ title: tab.title,
+ url: tab.url,
+ faviconUrl : tab.faviconUrl
+ }
+ });
+ }
+}