music: start indexing after bind/start command

This commit is contained in:
Alexander Capehart 2024-07-29 18:25:06 -06:00
parent 82a015c1e1
commit 9bc27a49eb
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
3 changed files with 10 additions and 6 deletions

View file

@ -43,24 +43,25 @@ class AuxioService : MediaLibraryService(), ForegroundListener {
} }
override fun onBind(intent: Intent?): IBinder? { override fun onBind(intent: Intent?): IBinder? {
handleIntent(intent) start(intent)
return super.onBind(intent) return super.onBind(intent)
} }
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
// TODO: Start command occurring from a foreign service basically implies a detached // TODO: Start command occurring from a foreign service basically implies a detached
// service, we might need more handling here. // service, we might need more handling here.
handleIntent(intent) start(intent)
return super.onStartCommand(intent, flags, startId) return super.onStartCommand(intent, flags, startId)
} }
private fun handleIntent(intent: Intent?) { private fun start(intent: Intent?) {
val nativeStart = intent?.getBooleanExtra(INTENT_KEY_NATIVE_START, false) ?: false val nativeStart = intent?.getBooleanExtra(INTENT_KEY_NATIVE_START, false) ?: false
if (!nativeStart) { if (!nativeStart) {
// Some foreign code started us, no guarantees about foreground stability. Figure // Some foreign code started us, no guarantees about foreground stability. Figure
// out what to do. // out what to do.
mediaSessionFragment.handleNonNativeStart() mediaSessionFragment.handleNonNativeStart()
} }
indexingFragment.start()
} }
override fun onTaskRemoved(rootIntent: Intent?) { override fun onTaskRemoved(rootIntent: Intent?) {

View file

@ -280,9 +280,6 @@ constructor(
} }
logD("Registering worker $worker") logD("Registering worker $worker")
indexingWorker = worker indexingWorker = worker
if (indexingState == null) {
worker.requestIndex(true)
}
} }
@Synchronized @Synchronized

View file

@ -79,6 +79,12 @@ constructor(
foregroundListener = null foregroundListener = null
} }
fun start() {
if (musicRepository.indexingState == null) {
requestIndex(true)
}
}
fun createNotification(post: (IndexerNotification?) -> Unit) { fun createNotification(post: (IndexerNotification?) -> Unit) {
val state = musicRepository.indexingState val state = musicRepository.indexingState
if (state is IndexingState.Indexing) { if (state is IndexingState.Indexing) {