aboutsummaryrefslogtreecommitdiff
path: root/src/background/repositories/CompletionsRepository.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/background/repositories/CompletionsRepository.ts')
-rw-r--r--src/background/repositories/CompletionsRepository.ts14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/background/repositories/CompletionsRepository.ts b/src/background/repositories/CompletionsRepository.ts
index 1318d36..18af587 100644
--- a/src/background/repositories/CompletionsRepository.ts
+++ b/src/background/repositories/CompletionsRepository.ts
@@ -1,7 +1,13 @@
+type Tab = browser.tabs.Tab;
+type BookmarkTreeNode = browser.bookmarks.BookmarkTreeNode;
+
export default class CompletionsRepository {
- async queryBookmarks(keywords) {
+ async queryBookmarks(keywords: string): Promise<BookmarkTreeNode[]> {
let items = await browser.bookmarks.search({ query: keywords });
return items.filter((item) => {
+ if (!item.url) {
+ return false;
+ }
let url = undefined;
try {
url = new URL(item.url);
@@ -12,17 +18,17 @@ export default class CompletionsRepository {
});
}
- queryHistories(keywords) {
+ queryHistories(keywords: string): Promise<browser.history.HistoryItem[]> {
return browser.history.search({
text: keywords,
startTime: 0,
});
}
- async queryTabs(keywords, excludePinned) {
+ async queryTabs(keywords: string, excludePinned: boolean): Promise<Tab[]> {
let tabs = await browser.tabs.query({ currentWindow: true });
return tabs.filter((t) => {
- return t.url.toLowerCase().includes(keywords.toLowerCase()) ||
+ return t.url && t.url.toLowerCase().includes(keywords.toLowerCase()) ||
t.title && t.title.toLowerCase().includes(keywords.toLowerCase());
}).filter((t) => {
return !(excludePinned && t.pinned);