music: do not auto-index unless indeterminate

Make IndexerService only auto-index music when there is no library AND
no loading has occured.

This resolves an issue where if IndexerService dies after a failed
index, IndexerService would try to index music regardless, as there was
no library present.
This commit is contained in:
OxygenCobalt 2022-06-05 11:43:01 -06:00
parent f3a7813f5e
commit dd00c70488
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
2 changed files with 9 additions and 3 deletions

View file

@ -61,6 +61,13 @@ class Indexer {
private var currentGeneration = 0L
private val callbacks = mutableListOf<Callback>()
/**
* Whether this instance is in an indeterminate state or not, where nothing has been previously
* loaded, yet no loading is going on.
*/
val isIndeterminate: Boolean
get() = lastResponse == null && loadingState == null
fun addCallback(callback: Callback) {
val currentState =
loadingState?.let { State.Loading(it) } ?: lastResponse?.let { State.Complete(it) }

View file

@ -62,10 +62,9 @@ class IndexerService : Service(), Indexer.Callback {
notification = IndexerNotification(this)
// FIXME: Do not re-index if Indexer has already completed
indexer.addCallback(this)
if (musicStore.library == null) {
logD("No library present, loading music now")
if (musicStore.library == null && indexer.isIndeterminate) {
logD("No library present and no previous response, loading music now")
onRequestReindex()
}