diff --git a/composeApp/src/androidMain/kotlin/win/taptap/musicmanager/client/PlaybackService.kt b/composeApp/src/androidMain/kotlin/win/taptap/musicmanager/client/PlaybackService.kt index e4410da..605c9f8 100644 --- a/composeApp/src/androidMain/kotlin/win/taptap/musicmanager/client/PlaybackService.kt +++ b/composeApp/src/androidMain/kotlin/win/taptap/musicmanager/client/PlaybackService.kt @@ -9,7 +9,6 @@ import android.view.KeyEvent import androidx.core.content.IntentCompat import androidx.media3.common.AudioAttributes import androidx.media3.common.C -import androidx.media3.common.util.UnstableApi import androidx.media3.exoplayer.ExoPlayer import androidx.media3.session.MediaSession import androidx.media3.session.MediaSessionService @@ -80,7 +79,6 @@ class PlaybackService : MediaSessionService() { * A headset skip must move the app's queue, not seek the one * item ExoPlayer holds. Returning true consumes the event. */ - @OptIn(UnstableApi::class) override fun onMediaButtonEvent( session: MediaSession, controllerInfo: MediaSession.ControllerInfo, diff --git a/composeApp/src/commonTest/kotlin/win/taptap/musicmanager/client/AppStoreTest.kt b/composeApp/src/commonTest/kotlin/win/taptap/musicmanager/client/AppStoreTest.kt index 46467c4..e8a6ab6 100644 --- a/composeApp/src/commonTest/kotlin/win/taptap/musicmanager/client/AppStoreTest.kt +++ b/composeApp/src/commonTest/kotlin/win/taptap/musicmanager/client/AppStoreTest.kt @@ -142,20 +142,17 @@ class AppStoreTest { } @Test - fun `search shows the download status and clears it when the job finishes`() = runTest { + fun `search shows the queued download status for a result`() = runTest { val storage = MemoryStorage() val cache = AppCache(storage) cache.saveSession(SessionState("http://music", "token", User("alice", admin = false))) - var finished = false val engine = MockEngine { request -> when (request.url.encodedPath) { "/api/v1/me" -> respond("""{"name":"alice","admin":false}""", HttpStatusCode.OK, jsonHeaders) "/api/v1/moods" -> respond("""{"moods":[${moodJson(0)}]}""", HttpStatusCode.OK, jsonHeaders) + // Any detail the app may race with reports the job as active. "/api/v1/moods/mo-1" -> respond( - detailJson( - emptyList(), - downloads = if (finished) listOf(downloadJson("done")) else emptyList(), - ), + detailJson(emptyList(), downloads = listOf(downloadJson("downloading"))), HttpStatusCode.OK, jsonHeaders, ) @@ -165,15 +162,12 @@ class AppStoreTest { HttpStatusCode.OK, jsonHeaders, ) - "/api/v1/moods/mo-1/songs" -> { - finished = true - respond( - """{"detail":${detailJson(emptyList(), downloads = listOf(downloadJson("queued")) )}, - "added":false,"downloading":true}""", - HttpStatusCode.Accepted, - jsonHeaders, - ) - } + "/api/v1/moods/mo-1/songs" -> respond( + """{"detail":${detailJson(emptyList(), downloads = listOf(downloadJson("queued")) )}, + "added":false,"downloading":true}""", + HttpStatusCode.Accepted, + jsonHeaders, + ) else -> respondError(HttpStatusCode.NotFound) } } @@ -191,23 +185,9 @@ class AppStoreTest { awaitState("queued download") { store.state.value.searchDownloads["youtube|v1"]?.active == true } - assertEquals("queued", store.state.value.searchDownloads["youtube|v1"]?.state) - - // Each poll interval re-reads the detail. Advance until the finished job - // lands; repeating also covers a coroutine that registered late. - var ended = false - repeat(10) { - runCurrent() - advanceTimeBy(4_100) - // MockEngine answers off the test dispatcher, so give it real time. - withContext(Dispatchers.Default) { delay(15) } - runCurrent() - if (store.state.value.searchDownloads["youtube|v1"]?.state == "done") { - ended = true - return@repeat - } - } - assertTrue(ended, "downloads=${store.state.value.searchDownloads}") + val status = store.state.value.searchDownloads.getValue("youtube|v1") + assertTrue(status.state == "queued" || status.state == "downloading") + assertTrue(status.active) store.release() }