Check the stored sign-in only once at a time
The activity and the playback service both start the app state. When the first check of the stored sign-in was still running as the service came up, a second one started and signed in again with a new client. Requests already made with the first client had their results dropped, and since they still showed as loading they were never asked for again, so Home and Liked tracks could stay on "Loading…" after a cold start. A check now waits out one that is already running. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8461c20133
commit
75a02c61e5
1 file changed
+8
-1
@@ -47,6 +47,7 @@ import it.panov.musyx.data.SettingsStore
|
||||
import it.panov.musyx.player.Buffering
|
||||
import it.panov.musyx.player.PlaybackController
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/** Tracks in Home's "Recently played". */
|
||||
@@ -182,9 +183,15 @@ class AppState(
|
||||
if (session == Session.Restoring) restore()
|
||||
}
|
||||
|
||||
/** The stored sign-in being checked, if it is. */
|
||||
private var restoring: Job? = null
|
||||
|
||||
fun restore() {
|
||||
// The activity and the playback service both start the app; a second check would sign
|
||||
// in twice, and requests made with the first client would be dropped, never to finish.
|
||||
if (restoring?.isActive == true) return
|
||||
session = Session.Restoring
|
||||
scope.launch {
|
||||
restoring = scope.launch {
|
||||
val stored = credentialStore.load()
|
||||
if (stored == null) {
|
||||
session = signedOut()
|
||||
|
||||
Reference in new issue
Block a user