|
|
@ -1,22 +1,47 @@ |
|
|
|
import * as tabs from './tabs'; |
|
|
|
import * as tabs from './tabs'; |
|
|
|
import * as histories from './histories'; |
|
|
|
import * as histories from './histories'; |
|
|
|
|
|
|
|
import * as bookmarks from './bookmarks'; |
|
|
|
|
|
|
|
|
|
|
|
const getOpenCompletions = (command, keywords, searchConfig) => { |
|
|
|
const getSearchCompletions = (command, keywords, searchConfig) => { |
|
|
|
|
|
|
|
let engineNames = Object.keys(searchConfig.engines); |
|
|
|
|
|
|
|
let engineItems = engineNames.filter(name => name.startsWith(keywords)) |
|
|
|
|
|
|
|
.map(name => ({ |
|
|
|
|
|
|
|
caption: name, |
|
|
|
|
|
|
|
content: command + ' ' + name |
|
|
|
|
|
|
|
})); |
|
|
|
|
|
|
|
return Promise.resolve(engineItems); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const getHistoryCompletions = (command, keywords) => { |
|
|
|
return histories.getCompletions(keywords).then((pages) => { |
|
|
|
return histories.getCompletions(keywords).then((pages) => { |
|
|
|
let historyItems = pages.map((page) => { |
|
|
|
return pages.map((page) => { |
|
|
|
return { |
|
|
|
return { |
|
|
|
caption: page.title, |
|
|
|
caption: page.title, |
|
|
|
content: command + ' ' + page.url, |
|
|
|
content: command + ' ' + page.url, |
|
|
|
url: page.url |
|
|
|
url: page.url |
|
|
|
}; |
|
|
|
}; |
|
|
|
}); |
|
|
|
}); |
|
|
|
let engineNames = Object.keys(searchConfig.engines); |
|
|
|
}); |
|
|
|
let engineItems = engineNames.filter(name => name.startsWith(keywords)) |
|
|
|
}; |
|
|
|
.map(name => ({ |
|
|
|
|
|
|
|
caption: name, |
|
|
|
|
|
|
|
content: command + ' ' + name |
|
|
|
|
|
|
|
})); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const getBookmarksCompletions = (command, keywords) => { |
|
|
|
|
|
|
|
return bookmarks.getCompletions(keywords).then((items) => { |
|
|
|
|
|
|
|
return items.map((item) => { |
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
caption: item.title, |
|
|
|
|
|
|
|
content: command + ' ' + item.url, |
|
|
|
|
|
|
|
url: item.url, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const getOpenCompletions = (command, keywords, searchConfig) => { |
|
|
|
|
|
|
|
return Promise.all([ |
|
|
|
|
|
|
|
getSearchCompletions(command, keywords, searchConfig), |
|
|
|
|
|
|
|
getHistoryCompletions(command, keywords), |
|
|
|
|
|
|
|
getBookmarksCompletions(command, keywords), |
|
|
|
|
|
|
|
]).then(([engineItems, historyItems, bookmarkItems]) => { |
|
|
|
let completions = []; |
|
|
|
let completions = []; |
|
|
|
if (engineItems.length > 0) { |
|
|
|
if (engineItems.length > 0) { |
|
|
|
completions.push({ |
|
|
|
completions.push({ |
|
|
@ -30,6 +55,12 @@ const getOpenCompletions = (command, keywords, searchConfig) => { |
|
|
|
items: historyItems |
|
|
|
items: historyItems |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (bookmarkItems.length > 0) { |
|
|
|
|
|
|
|
completions.push({ |
|
|
|
|
|
|
|
name: 'Bookmarks', |
|
|
|
|
|
|
|
items: bookmarkItems |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
return completions; |
|
|
|
return completions; |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|
}; |
|
|
|