diff --git a/core/src/main/java/it/panov/musyx/state/AppState.kt b/core/src/main/java/it/panov/musyx/state/AppState.kt index 404498e..1046cd7 100644 --- a/core/src/main/java/it/panov/musyx/state/AppState.kt +++ b/core/src/main/java/it/panov/musyx/state/AppState.kt @@ -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()