[fenix] Make sure reconnect item is displayed in HomeMenu in case of account problems

AccountObserver listeners were being triggered correctly, however, during every time
we open HomeFragment, home menu gets re-created, which causes us to re-run the initialization
block. Before this patch, the init block would never touch the account manager.
After this patch, it will query it if account manager has already been initialized.
pull/600/head
Grisha Kruglov 4 years ago committed by Grisha Kruglov
parent 8d1befd34c
commit 12e3619a2e

@ -121,7 +121,16 @@ class HomeMenu(
onItemTapped.invoke(Item.Help)
}
// Only query account manager if it has been initialized.
// We don't want to cause its initialization just for this check.
val accountAuthItem = if (context.components.backgroundServices.accountManagerAvailableQueue.isReady()) {
if (context.components.backgroundServices.accountManager.accountNeedsReauth()) reconnectToSyncItem else null
} else {
null
}
listOfNotNull(
accountAuthItem,
whatsNewItem,
BrowserMenuDivider(),
BrowserMenuCategory(

@ -19,6 +19,13 @@ class RunWhenReadyQueue {
private val tasks = CopyOnWriteArrayList<() -> Unit>()
private val isReady = AtomicBoolean(false)
/**
* Was this queue ever marked as 'ready' via a call to [ready]?
*
* @return Boolean value indicating if this queue is 'ready'.
*/
fun isReady(): Boolean = isReady.get()
/**
* Runs the [task] if this queue is marked as ready, or queues it for later execution.
* Task will be executed on the main thread.

Loading…
Cancel
Save