mirror of
https://github.com/huhu/rust-search-extension
synced 2024-11-13 23:27:13 +00:00
Get settings from async function
This commit is contained in:
parent
7fe32096a5
commit
fb4cb133e7
3 changed files with 13 additions and 23 deletions
2
core
2
core
|
@ -1 +1 @@
|
|||
Subproject commit e0a846d1850894378e36f684cad1692fc244a32e
|
||||
Subproject commit 163263b11daa4c2ecb455d19d9a1659d9ca338c0
|
|
@ -24,8 +24,6 @@ export default class RustSearchOmnibox {
|
|||
// All dynamic setting items. Those items will been updated
|
||||
// in chrome.storage.onchange listener callback.
|
||||
let isOfflineMode = await settings.isOfflineMode;
|
||||
let defaultSearch = await settings.defaultSearch;
|
||||
let crateRegistry = await settings.crateRegistry;
|
||||
|
||||
function formatDoc(index, doc) {
|
||||
let content = doc.href;
|
||||
|
@ -58,10 +56,10 @@ export default class RustSearchOmnibox {
|
|||
return stdSearcher.search(query);
|
||||
},
|
||||
onFormat: formatDoc,
|
||||
onAppend: (query) => {
|
||||
onAppend: async (query) => {
|
||||
return [{
|
||||
content: stdSearcher.getSearchUrl(query),
|
||||
description: `Search Rust docs <match>${query}</match> on ${isOfflineMode ? "offline mode" : stdSearcher.getRootPath()}`,
|
||||
description: `Search Rust docs <match>${query}</match> on ${await settings.isOfflineMode ? "offline mode" : stdSearcher.getRootPath()}`,
|
||||
}];
|
||||
},
|
||||
};
|
||||
|
@ -124,8 +122,8 @@ export default class RustSearchOmnibox {
|
|||
|
||||
omnibox.addPrefixQueryEvent("~", {
|
||||
name: "External docs",
|
||||
isDefaultSearch: () => {
|
||||
return defaultSearch.thirdPartyDocs;
|
||||
isDefaultSearch: async () => {
|
||||
return (await settings.defaultSearch).thirdPartyDocs;
|
||||
},
|
||||
searchPriority: 1,
|
||||
onSearch: async (query) => {
|
||||
|
@ -165,8 +163,8 @@ export default class RustSearchOmnibox {
|
|||
|
||||
omnibox.addPrefixQueryEvent("!", {
|
||||
name: "docs.rs",
|
||||
isDefaultSearch: () => {
|
||||
return defaultSearch.docsRs;
|
||||
isDefaultSearch: async () => {
|
||||
return (await settings.defaultSearch).docsRs;
|
||||
},
|
||||
searchPriority: 2,
|
||||
onSearch: (query) => {
|
||||
|
@ -192,13 +190,15 @@ export default class RustSearchOmnibox {
|
|||
onSearch: (query) => {
|
||||
return crateSearcher.search(query);
|
||||
},
|
||||
onFormat: (index, crate) => {
|
||||
onFormat: async (index, crate) => {
|
||||
let crateRegistry = await settings.crateRegistry;
|
||||
return {
|
||||
content: `https://${crateRegistry}/crates/${crate.id}`,
|
||||
description: `${Compat.capitalize(crateRegistry)}: <match>${crate.id}</match> v${crate.version} - <dim>${Compat.escape(Compat.eliminateTags(crate.description))}</dim>`,
|
||||
};
|
||||
},
|
||||
onAppend: (query) => {
|
||||
onAppend: async (query) => {
|
||||
let crateRegistry = await settings.crateRegistry;
|
||||
let keyword = query.replace(/[!\s]/g, "");
|
||||
return wrapCrateSearchAppendix({
|
||||
content: `https://${crateRegistry}/search?q=` + encodeURIComponent(keyword),
|
||||
|
@ -229,8 +229,8 @@ export default class RustSearchOmnibox {
|
|||
|
||||
omnibox.addPrefixQueryEvent("#", {
|
||||
name: "Attributes",
|
||||
isDefaultSearch: () => {
|
||||
return defaultSearch.attributes;
|
||||
isDefaultSearch: async () => {
|
||||
return (await settings.defaultSearch).attributes;
|
||||
},
|
||||
searchPriority: 3,
|
||||
onSearch: (query) => {
|
||||
|
|
|
@ -30,8 +30,6 @@ async function start(omnibox) {
|
|||
// in chrome.storage.onchange listener callback.
|
||||
let isOfflineMode = await settings.isOfflineMode;
|
||||
let offlineDocPath = await settings.offlineDocPath;
|
||||
let defaultSearch = await settings.defaultSearch;
|
||||
let crateRegistry = await settings.crateRegistry;
|
||||
|
||||
const crateSearcher = new CrateSearch(await IndexManager.getCrateMapping(), await IndexManager.getCrateIndex());
|
||||
let caniuseSearcher = new CaniuseSearch(await IndexManager.getCaniuseIndex());
|
||||
|
@ -119,14 +117,6 @@ async function start(omnibox) {
|
|||
offlineDocPath = newValue;
|
||||
break;
|
||||
}
|
||||
case "default-search": {
|
||||
defaultSearch = newValue;
|
||||
break;
|
||||
}
|
||||
case "crate-registry": {
|
||||
crateRegistry = newValue;
|
||||
break;
|
||||
}
|
||||
case "index-std-stable": {
|
||||
// Update search index after docs updated
|
||||
stdSearcher.setSearchIndex(newValue);
|
||||
|
|
Loading…
Reference in a new issue