diff --git a/core b/core index e0a846d..163263b 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit e0a846d1850894378e36f684cad1692fc244a32e +Subproject commit 163263b11daa4c2ecb455d19d9a1659d9ca338c0 diff --git a/extension/lib.js b/extension/lib.js index d4d7f0e..2bb07ab 100644 --- a/extension/lib.js +++ b/extension/lib.js @@ -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 ${query} on ${isOfflineMode ? "offline mode" : stdSearcher.getRootPath()}`, + description: `Search Rust docs ${query} 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)}: ${crate.id} v${crate.version} - ${Compat.escape(Compat.eliminateTags(crate.description))}`, }; }, - 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) => { diff --git a/extension/main.js b/extension/main.js index 30534b8..4016383 100644 --- a/extension/main.js +++ b/extension/main.js @@ -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);