From 0340c82bc82738a63c8a374930cf39cbed5c7c8c Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 29 Mar 2020 21:10:47 +0900 Subject: Complete tab by an index and a flag --- .../completion/impl/TabRepositoryImpl.ts | 32 ++++++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'src/background/completion/impl') diff --git a/src/background/completion/impl/TabRepositoryImpl.ts b/src/background/completion/impl/TabRepositoryImpl.ts index 6692b27..adcaba7 100644 --- a/src/background/completion/impl/TabRepositoryImpl.ts +++ b/src/background/completion/impl/TabRepositoryImpl.ts @@ -15,13 +15,27 @@ export default class TabRepositoryImpl implements TabRepository { }) .filter(item => item.id && item.title && item.url) .slice(0, COMPLETION_ITEM_LIMIT) - .map(item => ({ - id: item.id!!, - url: item.url!!, - active: item.active, - title: item.title!!, - faviconUrl: item.favIconUrl, - index: item.index, - })) + .map(TabRepositoryImpl.toEntity); } -} \ No newline at end of file + + async getAllTabs(excludePinned: boolean): Promise { + if (excludePinned) { + return (await browser.tabs.query({ currentWindow: true, pinned: true })) + .map(TabRepositoryImpl.toEntity) + + } + return (await browser.tabs.query({ currentWindow: true })) + .map(TabRepositoryImpl.toEntity) + } + + private static toEntity(tab: browser.tabs.Tab,): Tab { + return { + id: tab.id!!, + url: tab.url!!, + active: tab.active, + title: tab.title!!, + faviconUrl: tab.favIconUrl, + index: tab.index, + } + } +} -- cgit v1.2.3