From 75a02c61e54226028ec3e9ed35c0b12a6eedaf97 Mon Sep 17 00:00:00 2001 From: Yuriy Panov Date: Fri, 23 Oct 2026 15:34:26 +0600 Subject: [PATCH] Check the stored sign-in only once at a time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- core/src/main/java/it/panov/musyx/state/AppState.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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()