Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save daleharvey/50d972ef7b903d2bd8f27bac4b1f740d to your computer and use it in GitHub Desktop.
Save daleharvey/50d972ef7b903d2bd8f27bac4b1f740d to your computer and use it in GitHub Desktop.
if (AppConstants.platform == "android") {
let enginesFromURLs = await this._loadFromChromeURLs(engines, isReload);
enginesFromURLs.forEach(this._addEngineToStore, this);
} else {
for (let [id, locales] of engineLocales) {
await this._ensureEngine(id, locales);
}
}
async _ensureEngine(id, locales) {
SearchUtils.log("_ensureEngine " + id);
try {
let policy = WebExtensionPolicy.getByID(id);
if (!policy) {
SearchUtils.log("_loadEngines: Installing " + id);
let path = EXT_SEARCH_PREFIX + id.split("@")[0] + "/";
await AddonManager.installBuiltinAddon(path);
// The AddonManager will install the engine asynchronously
// We can manually wait on that happening here.
await ExtensionParent.apiManager.global.pendingSearchSetupTasks.get(id);
policy = WebExtensionPolicy.getByID(id)
}
await policy.readyPromise;
await this._installExtensionEngine(policy.extension, locales);
SearchUtils.log("_ensureEngine: " + id + " installed.");
} catch (err) {
Cu.reportError("Failed to install engine: " + err.message + "\n" + err.stack);
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment