2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-17 15:26:23 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/12081 - Properly installs searchengines when MLS completes

This commit is contained in:
Jeff Boek 2020-06-30 12:01:20 -07:00
parent 574af55820
commit 39b6463f5b

View File

@ -19,7 +19,6 @@ import mozilla.components.browser.search.provider.SearchEngineList
import mozilla.components.browser.search.provider.SearchEngineProvider
import mozilla.components.browser.search.provider.filter.SearchEngineFilter
import mozilla.components.browser.search.provider.localization.LocaleSearchLocalizationProvider
import mozilla.components.browser.search.provider.localization.SearchLocalization
import mozilla.components.browser.search.provider.localization.SearchLocalizationProvider
import mozilla.components.service.location.LocationService
import mozilla.components.service.location.MozillaLocationService
@ -98,14 +97,6 @@ open class FenixSearchEngineProvider(
fallbackEngines
}
private val region: Deferred<SearchLocalization>
get() =
if (loadedRegion.isCompleted) {
loadedRegion
} else {
fallbackRegion
}
fun getDefaultEngine(context: Context): SearchEngine {
val engines = installedSearchEngines(context)
val selectedName = context.settings().defaultSearchEngineName
@ -207,12 +198,6 @@ open class FenixSearchEngineProvider(
val prefs = prefs(context)
val installedEnginesKey = localeAwareInstalledEnginesKey()
if (installedEnginesKey != prefs.getString(CURRENT_LOCALE_KEY, "")) {
updateBaseSearchEngines()
reload()
prefs.edit().putString(CURRENT_LOCALE_KEY, installedEnginesKey).apply()
}
if (!prefs.contains(installedEnginesKey)) {
val searchEngines =
if (baseSearchEngines.isCompleted) baseSearchEngines
@ -234,12 +219,20 @@ open class FenixSearchEngineProvider(
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
suspend fun localeAwareInstalledEnginesKey(): String {
val tag = region.await().let {
val region = it.region?.let { region ->
if (region.isEmpty()) "" else "-$region"
val tag = if (loadedRegion.isCompleted) {
val localization = loadedRegion.await()
val region = localization.region?.let {
if (it.isEmpty()) "" else "-$it"
}
"${it.languageTag}$region"
"${localization.languageTag}$region"
} else {
val localization = fallbackRegion.await()
val region = localization.region?.let {
if (it.isEmpty()) "" else "-$it"
}
"${localization.languageTag}$region-fallback"
}
return "$INSTALLED_ENGINES_KEY-$tag"