2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-19 09:25:34 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/19804: Changed var isDefaultBrowser to a function

The change to the function makes it so when the Settings.kt class is initialized, the isDefaultBrowser, which calls the
BrowserCache, won't get called right away. `isDefaultBrowser()` is known to take quite a while on start up on the G5+ (approx
30-40ms).
This commit is contained in:
Marc Leclair 2021-06-21 13:00:08 -04:00 committed by mergify[bot]
parent aac9149bb5
commit 6e811abdef
2 changed files with 14 additions and 11 deletions

View File

@ -314,14 +314,11 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
// Launch this on a background thread so as not to affect startup performance
lifecycleScope.launch(IO) {
if (
settings().isDefaultBrowser() &&
settings().wasDefaultBrowserOnLastResume != settings().isDefaultBrowser()
settings().checkDefaultBrowserAndSet()
) {
metrics.track(Event.ChangedToDefaultBrowser)
}
settings().wasDefaultBrowserOnLastResume = settings().isDefaultBrowser()
DefaultBrowserNotificationWorker.setDefaultBrowserNotificationIfNeeded(applicationContext)
}
}

View File

@ -471,15 +471,21 @@ class Settings(private val appContext: Context) : PreferencesHolder {
)
/**
* Caches the last known "is default browser" state when the app was paused.
* For an up to do date state use `isDefaultBrowser` instead.
* Declared as a function for performance purposes. When this class is first initialized, the
* isDefaultBrowser function takes approx. 30-40ms.
*/
var wasDefaultBrowserOnLastResume by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_default_browser),
default = isDefaultBrowser()
)
fun checkDefaultBrowserAndSet(): Boolean {
val prefKey = appContext.getPreferenceKey(R.string.pref_key_default_browser)
val isDefaultBrowser = isDefaultBrowser()
this.preferences.edit().putBoolean(prefKey, isDefaultBrowser).apply()
return this.preferences.getBoolean(prefKey, isDefaultBrowser) != isDefaultBrowser
}
fun isDefaultBrowser(): Boolean {
/**
* This function is "blocking" since calling this can take approx. 30-40ms (timing taken on a
* G5+).
*/
private fun isDefaultBrowserBlocking(): Boolean {
val browsers = BrowsersCache.all(appContext)
return browsers.isDefaultBrowser
}