For #12081 - Properly installs searchengines when MLS completes
parent
7b3fe9bab4
commit
fb4822498f
|
@ -19,7 +19,6 @@ import mozilla.components.browser.search.provider.SearchEngineList
|
||||||
import mozilla.components.browser.search.provider.SearchEngineProvider
|
import mozilla.components.browser.search.provider.SearchEngineProvider
|
||||||
import mozilla.components.browser.search.provider.filter.SearchEngineFilter
|
import mozilla.components.browser.search.provider.filter.SearchEngineFilter
|
||||||
import mozilla.components.browser.search.provider.localization.LocaleSearchLocalizationProvider
|
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.browser.search.provider.localization.SearchLocalizationProvider
|
||||||
import mozilla.components.service.location.LocationService
|
import mozilla.components.service.location.LocationService
|
||||||
import mozilla.components.service.location.MozillaLocationService
|
import mozilla.components.service.location.MozillaLocationService
|
||||||
|
@ -98,14 +97,6 @@ open class FenixSearchEngineProvider(
|
||||||
fallbackEngines
|
fallbackEngines
|
||||||
}
|
}
|
||||||
|
|
||||||
private val region: Deferred<SearchLocalization>
|
|
||||||
get() =
|
|
||||||
if (loadedRegion.isCompleted) {
|
|
||||||
loadedRegion
|
|
||||||
} else {
|
|
||||||
fallbackRegion
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getDefaultEngine(context: Context): SearchEngine {
|
fun getDefaultEngine(context: Context): SearchEngine {
|
||||||
val engines = installedSearchEngines(context)
|
val engines = installedSearchEngines(context)
|
||||||
val selectedName = context.settings().defaultSearchEngineName
|
val selectedName = context.settings().defaultSearchEngineName
|
||||||
|
@ -207,12 +198,6 @@ open class FenixSearchEngineProvider(
|
||||||
val prefs = prefs(context)
|
val prefs = prefs(context)
|
||||||
val installedEnginesKey = localeAwareInstalledEnginesKey()
|
val installedEnginesKey = localeAwareInstalledEnginesKey()
|
||||||
|
|
||||||
if (installedEnginesKey != prefs.getString(CURRENT_LOCALE_KEY, "")) {
|
|
||||||
updateBaseSearchEngines()
|
|
||||||
reload()
|
|
||||||
prefs.edit().putString(CURRENT_LOCALE_KEY, installedEnginesKey).apply()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!prefs.contains(installedEnginesKey)) {
|
if (!prefs.contains(installedEnginesKey)) {
|
||||||
val searchEngines =
|
val searchEngines =
|
||||||
if (baseSearchEngines.isCompleted) baseSearchEngines
|
if (baseSearchEngines.isCompleted) baseSearchEngines
|
||||||
|
@ -234,12 +219,20 @@ open class FenixSearchEngineProvider(
|
||||||
|
|
||||||
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
||||||
suspend fun localeAwareInstalledEnginesKey(): String {
|
suspend fun localeAwareInstalledEnginesKey(): String {
|
||||||
val tag = region.await().let {
|
val tag = if (loadedRegion.isCompleted) {
|
||||||
val region = it.region?.let { region ->
|
val localization = loadedRegion.await()
|
||||||
if (region.isEmpty()) "" else "-$region"
|
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"
|
return "$INSTALLED_ENGINES_KEY-$tag"
|
||||||
|
|
Loading…
Reference in New Issue