1
0
Fork 0

No issue: sync and refresh device state on foreground

master
Grisha Kruglov 2019-05-28 15:26:36 -07:00 committed by Grisha Kruglov
parent 039990f608
commit fda0f1de97
1 changed files with 16 additions and 0 deletions

View File

@ -14,6 +14,9 @@ import androidx.appcompat.widget.Toolbar
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.NavigationUI
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import mozilla.components.browser.search.SearchEngine
import mozilla.components.browser.session.Session
import mozilla.components.browser.session.SessionManager
@ -102,6 +105,19 @@ open class HomeActivity : AppCompatActivity() {
handleOpenedFromExternalSourceIfNecessary(intent)
}
override fun onResume() {
super.onResume()
CoroutineScope(Dispatchers.Main).launch {
// Make sure accountManager is initialized.
components.backgroundServices.accountManager.initAsync().await()
// If we're authenticated, kick-off a sync and a device state refresh.
components.backgroundServices.accountManager.authenticatedAccount()?.let {
components.backgroundServices.syncManager.syncNow(startup = true)
it.deviceConstellation().refreshDeviceStateAsync().await()
}
}
}
override fun onCreateView(
parent: View?,
name: String,