1
0
Fork 0

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.
master
Grisha Kruglov 2020-03-31 15:21:25 -07:00 committed by Grisha Kruglov
parent 60943df6d9
commit 54b7fd8834
2 changed files with 16 additions and 0 deletions

View File

@ -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(

View File

@ -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.