Skip to content

Native Android client for Spotify, built with Jetpack Compose

Extensions: Accept on an update card installs a code change with the same version code (it returned silently), every outcome logged; installing, enabling or removing an extension updates audio routing, the next song, download and lyrics availability at once

kota-zo062b99dab37d
diff --git a/base/app/src/main/java/com/music/spotui/data/api/LyricsApi.kt b/base/app/src/main/java/com/music/spotui/data/api/LyricsApi.kt
index 06eef16f..550d22d9 100644
--- a/base/app/src/main/java/com/music/spotui/data/api/LyricsApi.kt
+++ b/base/app/src/main/java/com/music/spotui/data/api/LyricsApi.kt
@@ -89,6 +89,20 @@ object LyricsApi {
/** A setting changed what is looked for: every song is read again when next shown. */
fun forgetAll() { cache.clear(); scope.launch { LyricsDisk.clear() } }
+ /** Bumped when the lyrics extensions changed and the cache was dropped: an open lyrics view reads its song again. */
+ val sourcesTick = kotlinx.coroutines.flow.MutableStateFlow(0L)
+
+ /**
+ * The lyrics extensions changed (one installed, turned on or off, updated, removed): the songs
+ * not found are asked again, and, but for [keepFound] (the ones on at launch just loaded), the
+ * lyrics found too, from memory and storage, so the new set of sources answers. Off the main thread.
+ */
+ fun sourcesChanged(keepFound: Boolean) {
+ if (keepFound) synchronized(cache) { cache.values.removeAll { it is Miss } }
+ else { cache.clear(); LyricsDisk.clear() }
+ sourcesTick.value++
+ }
+
suspend fun fetch(track: Track): Lyrics? {
when (val c = cache[track.key]) {
is Lyrics -> return c
diff --git a/base/app/src/main/java/com/music/spotui/di/LocalPlayer.kt b/base/app/src/main/java/com/music/spotui/di/LocalPlayer.kt
index a07af5a2..16e94859 100644
--- a/base/app/src/main/java/com/music/spotui/di/LocalPlayer.kt
+++ b/base/app/src/main/java/com/music/spotui/di/LocalPlayer.kt
@@ -195,6 +195,22 @@ object LocalPlayer {
private const val AHEAD_DELAY_MS = 10_000L
+ /**
+ * The audio-source extensions changed (see SongPlayer.audioSourcesChanged): the next song is
+ * asked again ahead, and a song the queue stopped on for want of a source is tried again.
+ */
+ fun sourcesChanged() {
+ val p = exo ?: return
+ if (CastPlayback.active) return
+ errors.played()
+ val item = p.currentMediaItem?.localConfiguration?.uri
+ if (p.playerError != null && item?.scheme == com.music.spotui.extensions.ExtensionAudio.SCHEME) {
+ log("${current()?.title}: the audio sources changed, asked again")
+ p.prepare(); p.play()
+ }
+ prefetchNext(p)
+ }
+
/** The most a song's start read ahead is kept (less when its address expires sooner). */
private const val HEAD_KEEP_MS = 10 * 60_000L
diff --git a/base/app/src/main/java/com/music/spotui/di/SongPlayer.kt b/base/app/src/main/java/com/music/spotui/di/SongPlayer.kt
index f41b083b..d196b1d4 100644
--- a/base/app/src/main/java/com/music/spotui/di/SongPlayer.kt
+++ b/base/app/src/main/java/com/music/spotui/di/SongPlayer.kt
@@ -1075,6 +1075,28 @@ object SongPlayer {
/** How long before its end the last song is played by Spotify, so its autoplay goes on at once. */
private const val END_LEAD_MS = 1_000L
+ /**
+ * The audio-source extensions changed (one installed, turned on, updated or removed, or the
+ * order of the sources): [added] gives audio now and did not, [any]: one gives audio. The songs
+ * they had nothing for this session are asked again; the answers kept for the songs to come are
+ * dropped (asked again in the new order). The local queue asks again for its next song, and the
+ * song it stopped on for want of a source; with a new source while Spotify plays, the song after
+ * the one playing goes to the extensions (as after a fallback), asked ahead. On the main thread.
+ */
+ fun audioSourcesChanged(added: List<String>, any: Boolean) {
+ spotifyPlayed.clear()
+ if (!any) return
+ val local = LocalPlayer.active.value
+ com.music.spotui.extensions.ExtensionAudio.forgetAllBut(if (local) LocalPlayer.current()?.let(LocalPlayer::spotifyIdOf) else null)
+ if (local) { LocalPlayer.sourcesChanged(); return }
+ if (added.isEmpty() || _activeDevice.value != null || routing || com.music.spotui.data.DataSaver.active) return
+ val id = trackIdOf(_nowPlaying.value.uri).ifBlank { return }
+ spotifyFallbackId = id
+ val next = _queue.value.let { it.queued + it.nextUp }.map { it.song }.firstOrNull { it.spotifyTrackId.isNotBlank() && it.spotifyTrackId != id }
+ app.myspoti.host.android.Logbook.log("audio: ${added.joinToString()} gives audio now: the song after $id goes to the extensions${next?.let { ", ${it.title} asked ahead" } ?: ""}")
+ if (next != null) scope.launch { runCatching { com.music.spotui.extensions.ExtensionAudio.warm(listOf(next)) } }
+ }
+
/** The songs the extensions had nothing for this session: a resume of one goes straight to Spotify. */
private val spotifyPlayed = java.util.Collections.synchronizedSet(HashSet<String>())
@@ -1589,6 +1611,9 @@ object SongPlayer {
// before it took the tap flipped the button back, and the two screens then disagreed; the
// value asked for holds until the page reports it (or for SHUFFLE_HOLD_MS).
@Volatile private var shuffleWanted = false
+ /** The repeat mode last tapped, held against the page's older reports like [shuffleWanted]. */
+ @Volatile private var repeatWanted = 0
+ @Volatile private var repeatWantedUntil = 0L
@Volatile private var shuffleWantedUntil = 0L
private const val SHUFFLE_HOLD_MS = 2_500L
@@ -1602,6 +1627,8 @@ object SongPlayer {
if (LocalPlayer.active.value) { _repeatMode.value = mode; LocalPlayer.setRepeatMode(mode); return }
Haptics.toggle(mode != 0)
_repeatMode.value = mode
+ repeatWanted = mode
+ repeatWantedUntil = SystemClock.elapsedRealtime() + SHUFFLE_HOLD_MS
boundState?.repeat?.value = mode != 0
lastTrackPrefs().edit().putInt("repeat", mode.coerceIn(0, 2)).apply()
command { api.player.setRepeat(Repeat.entries[mode.coerceIn(0, 2)]) }
@@ -1611,9 +1638,6 @@ object SongPlayer {
* Reported: the repeat button forgets what it was. The mode is the user's choice, kept from
* one run of the app to the next (the page always starts with repeat off): shown at once and
* set again on the first song the page reports.
- /** The repeat mode last tapped, held against the page's older reports like [shuffleWanted]. */
- @Volatile private var repeatWanted = 0
- @Volatile private var repeatWantedUntil = 0L
*/
private fun restoreRepeat(state: CurrentSongState) {
val p = lastTrackPrefs()
@@ -1627,8 +1651,6 @@ object SongPlayer {
fun cycleRepeat() = setRepeatMode((_repeatMode.value + 1) % 3)
/** Podcast playback speed (Spotify refuses it on music). */
- repeatWanted = mode
- repeatWantedUntil = SystemClock.elapsedRealtime() + SHUFFLE_HOLD_MS
fun setSpeed(speed: Double) {
_speed.value = speed
command { api.player.setSpeed(speed) }
diff --git a/base/app/src/main/java/com/music/spotui/extensions/ExtensionAudio.kt b/base/app/src/main/java/com/music/spotui/extensions/ExtensionAudio.kt
index 5e01f2e8..d17eb988 100644
--- a/base/app/src/main/java/com/music/spotui/extensions/ExtensionAudio.kt
+++ b/base/app/src/main/java/com/music/spotui/extensions/ExtensionAudio.kt
@@ -34,6 +34,12 @@ object ExtensionAudio {
/** Drops every remembered answer (an extension was removed: none of them may keep playing from it). */
fun forgetAll() = known.clear()
+ /**
+ * Drops the answers kept for every song but [playing] (the audio sources changed: the songs
+ * after it are asked again, in the new order; the one playing keeps its stream for seeks).
+ */
+ fun forgetAllBut(playing: String?) { known.keys.removeIf { it != playing } }
+
fun uri(s: SongsModel): Uri = Uri.Builder().scheme(SCHEME).authority("track").appendPath(s.spotifyTrackId)
.appendQueryParameter("title", s.title).appendQueryParameter("artist", s.singer)
.appendQueryParameter("album", s.album).appendQueryParameter("duration", s.durationMs.toString())
diff --git a/base/app/src/main/java/com/music/spotui/extensions/ExtensionUpdates.kt b/base/app/src/main/java/com/music/spotui/extensions/ExtensionUpdates.kt
index 9981d7c5..71dff959 100644
--- a/base/app/src/main/java/com/music/spotui/extensions/ExtensionUpdates.kt
+++ b/base/app/src/main/java/com/music/spotui/extensions/ExtensionUpdates.kt
@@ -252,7 +252,7 @@ object ExtensionUpdates {
Result.WAITING
}
UpdateGate.Decision.Apply -> {
- val plan = InstallPlan.of(m, e, accepted.toManifest()) as? InstallPlan.Update ?: return Result.UP_TO_DATE
+ val plan = updatePlan(m, e, accepted.toManifest()) ?: return Result.UP_TO_DATE
Extensions.install(f.zip, f.pkg, Grants.replacing(m, plan.refused), e.source, origin = f.origin, accepted = false)
val pinned = accepted.copy(scriptSha = next.scriptSha ?: accepted.scriptSha)
Extensions.update { r -> r.find(id)?.let { r.put(it.copy(accepted = pinned, pendingUpdate = null, updateBlocked = null, seenSha = null, seenAt = 0)) } ?: r }
@@ -268,6 +268,19 @@ object ExtensionUpdates {
}
}
+ /**
+ * [m] as an update of [e]: a newer version code, or (a branch can change under the same version
+ * code) the same one with other code. [InstallPlan.of] calls the latter [InstallPlan.NotNewer],
+ * which left Accept doing nothing on a same-version code update.
+ */
+ private fun updatePlan(m: Manifest, e: InstalledExtension, installed: Manifest?): InstallPlan.Update? =
+ when (val plan = InstallPlan.of(m, e, installed)) {
+ is InstallPlan.Update -> plan
+ is InstallPlan.NotNewer -> if (m.versionCode == e.versionCode)
+ (InstallPlan.of(m, e.copy(versionCode = e.versionCode - 1), installed) as? InstallPlan.Update)?.copy(from = e) else null
+ is InstallPlan.Fresh -> null
+ }
+
/** The staged update of [id], read and checked against what was staged. */
private fun staged(id: String): ExtensionPackage? {
val e = Extensions.registry.value.find(id) ?: return null
@@ -276,28 +289,52 @@ object ExtensionUpdates {
return runCatching { ExtensionPackage.read(bytes) }.getOrNull()?.takeIf { it.sha256 == p.kept.sha256 }
}
+ /** Ids whose Accept runs: a second tap meanwhile does nothing. */
+ private val accepting = java.util.concurrent.ConcurrentHashMap.newKeySet<String>()
+
/**
* The user read the card and accepted: the staged version is installed with all it lists
* granted (but the actions unticked before, still waiting on their own card), and becomes the
- * accepted snapshot.
+ * accepted snapshot. Each outcome goes to the extension's log and the Logbook.
*/
suspend fun accept(id: String) = withContext(Dispatchers.IO) {
- val e = Extensions.registry.value.find(id) ?: return@withContext
- e.updateBlocked?.let { throw ExtensionException("update refused: the repository changed owner") }
- val p = staged(id) ?: run { Extensions.update { r -> r.put(e.copy(pendingUpdate = null)) }; throw ExtensionException("the update is no longer on the phone: check again") }
- val accepted = e.accepted?.toManifest() ?: Extensions.manifest(id)
- val plan = InstallPlan.of(p.manifest, e, accepted) as? InstallPlan.Update ?: return@withContext
- val grant = Grants.replacing(p.manifest, plan.refused)
- val zip = File(Extensions.dir, "$id/staging.zip").readBytes()
- Extensions.install(zip, p, grant, e.source, clashes = Extensions.clashes(p.manifest), origin = e.pendingUpdate?.kept?.origin, accepted = true)
- Extensions.update { r -> r.find(id)?.let { r.put(it.copy(pendingUpdate = null)) } ?: r }
+ if (!accepting.add(id)) return@withContext Logbook.log("ext $id: update Accept ignored: already running")
+ try {
+ val e = Extensions.registry.value.find(id) ?: return@withContext Logbook.log("ext $id: update Accept: not installed")
+ val wanted = e.pendingUpdate?.kept?.version
+ e.updateBlocked?.let {
+ Extensions.log(id, "update to $wanted not accepted: the repository changed owner ($it)")
+ throw ExtensionException("update refused: the repository changed owner")
+ }
+ val p = staged(id) ?: run {
+ Extensions.update { r -> r.find(id)?.let { r.put(it.copy(pendingUpdate = null)) } ?: r }
+ Extensions.log(id, "update to $wanted not accepted: the staged package is missing or changed")
+ throw ExtensionException("the update is no longer on the phone: check again")
+ }
+ val accepted = e.accepted?.toManifest() ?: Extensions.manifest(id)
+ val plan = updatePlan(p.manifest, e, accepted) ?: run {
+ Extensions.update { r -> r.find(id)?.let { r.put(it.copy(pendingUpdate = null)) } ?: r }
+ File(Extensions.dir, "$id/staging.zip").delete()
+ Extensions.log(id, "update to ${p.manifest.version} (${p.manifest.versionCode}) not accepted: not newer than ${e.version} (${e.versionCode})")
+ throw ExtensionException("this version is not newer than the one installed: check again")
+ }
+ val grant = Grants.replacing(p.manifest, plan.refused)
+ val zip = File(Extensions.dir, "$id/staging.zip").readBytes()
+ runCatching {
+ Extensions.install(zip, p, grant, e.source, clashes = Extensions.clashes(p.manifest), origin = e.pendingUpdate?.kept?.origin, accepted = true)
+ }.onFailure { Extensions.log(id, "update to ${p.manifest.version} accepted but failed: ${it.message ?: it}") }.getOrThrow()
+ Extensions.update { r -> r.find(id)?.let { r.put(it.copy(pendingUpdate = null)) } ?: r }
+ Extensions.log(id, "update to ${p.manifest.version} accepted and installed")
+ } finally {
+ accepting.remove(id)
+ }
}
/** "Keep current": the staged version is dropped and not offered again (a newer one will be). */
fun keepCurrent(id: String) {
val e = Extensions.registry.value.find(id) ?: return
File(Extensions.dir, "$id/staging.zip").delete()
- Extensions.update { r -> r.put(e.copy(pendingUpdate = null, declinedVersionCode = e.pendingUpdate?.kept?.versionCode ?: e.declinedVersionCode, declinedSha = e.pendingUpdate?.kept?.sha256 ?: e.declinedSha)) }
+ Extensions.update { r -> r.find(id)?.let { r.put(it.copy(pendingUpdate = null, declinedVersionCode = e.pendingUpdate?.kept?.versionCode ?: it.declinedVersionCode, declinedSha = e.pendingUpdate?.kept?.sha256 ?: it.declinedSha)) } ?: r }
Extensions.log(id, "kept ${e.version}: ${e.pendingUpdate?.kept?.version} declined")
}
diff --git a/base/app/src/main/java/com/music/spotui/extensions/Extensions.kt b/base/app/src/main/java/com/music/spotui/extensions/Extensions.kt
index ed824153..9de17c1e 100644
--- a/base/app/src/main/java/com/music/spotui/extensions/Extensions.kt
+++ b/base/app/src/main/java/com/music/spotui/extensions/Extensions.kt
@@ -116,6 +116,23 @@ object Extensions {
/** Bumped when an extension's log gets a line, so an open log view reads it again. */
val logTick = MutableStateFlow(0L)
+ /**
+ * The running extensions giving songs' audio, download files and lyrics, in the order they are
+ * asked; [ready]: the ones on at launch have all been started. [refreshProvided] keeps it in step
+ * when one loads or stops (installed, updated, turned on or off, removed), its status changes or
+ * the user's order changes; what depends on it (the player's routing, downloads, lyrics) reacts
+ * at once, without a restart ([providersChanged]).
+ */
+ data class Provided(
+ val audio: List<String> = emptyList(), val download: List<String> = emptyList(),
+ val lyrics: List<String> = emptyList(), val ready: Boolean = false,
+ )
+ private val _provided = MutableStateFlow(Provided())
+ val provided: StateFlow<Provided> = _provided.asStateFlow()
+ /** The same, read by [hasAudioSource], [hasDownloadSource] and [hasLyrics]: a screen calling them is drawn again when it changes. */
+ private val providedState = androidx.compose.runtime.mutableStateOf(Provided())
+ private val providedLock = Any()
+
private val runtimes = ConcurrentHashMap<String, ExtensionRuntime>()
internal val packages = ConcurrentHashMap<String, ExtensionPackage>()
private val stores = ConcurrentHashMap<String, FileStore>()
@@ -144,6 +161,7 @@ object Extensions {
// One after the other, their sources asked only once all are loaded: a cold start is busy enough.
_registry.value.extensions.filter { it.enabled }.forEach { start(it, probe = false) }
started.complete(Unit)
+ refreshProvided()
probeAll()
ExtensionUpdates.daily()
}
@@ -151,6 +169,48 @@ object Extensions {
watchPlayback()
watchNetwork()
watchStatus()
+ watchProvided()
+ }
+
+ /**
+ * Reads again which extensions give audio, downloads and lyrics; when that changed, the songs
+ * none had lately are asked again, and [providersChanged] runs.
+ */
+ private fun refreshProvided() {
+ if (!isReady) return
+ synchronized(providedLock) {
+ val now = Provided(
+ providing(Hook.AUDIO_SOURCE).map { it.first }, providing(Hook.DOWNLOAD_SOURCE).map { it.first },
+ providing(Hook.LYRICS).map { it.first }, started.isCompleted,
+ )
+ if (now == _provided.value) return
+ if (now.audio != _provided.value.audio || now.download != _provided.value.download) misses.clear()
+ _provided.value = now
+ providedState.value = now
+ }
+ }
+
+ private fun watchProvided() = scope.launch {
+ var before = Provided()
+ _provided.collect { now -> if (now != before) { val was = before; before = now; providersChanged(was, now) } }
+ }
+
+ /**
+ * What depends on which extensions give what, brought in step at once: the player (the song
+ * playing and the ones after it), the lyrics cache, the downloads waiting for a source. Not at
+ * launch (the extensions on before load then, nothing was asked of them yet) but for the misses.
+ */
+ private fun providersChanged(before: Provided, now: Provided) {
+ Logbook.log("ext: sources now: audio ${now.audio.ifEmpty { "none" }}, downloads ${now.download.ifEmpty { "none" }}, lyrics ${now.lyrics.ifEmpty { "none" }}")
+ if (now.audio != before.audio && before.ready) {
+ val added = now.audio.filter { it !in before.audio }
+ main.post { runCatching { com.music.spotui.di.SongPlayer.audioSourcesChanged(added, now.audio.isNotEmpty()) }
+ .onFailure { Logbook.log("audio: sources changed, player not updated: $it") } }
+ }
+ if (now.lyrics != before.lyrics) com.music.spotui.data.api.LyricsApi.sourcesChanged(keepFound = !before.ready)
+ // Lists kept downloaded skipped their songs for want of a source: synced now.
+ if (before.ready && before.download.isEmpty() && now.download.isNotEmpty())
+ com.music.spotui.data.offline.OfflineCollections.refreshAll(ctx, force = true)
}
// ── Writes allowed for good ──
@@ -566,13 +626,13 @@ object Extensions {
/** The extensions that have a page (webview.page granted). */
fun hasPage(id: String): Boolean = runtimes[id]?.provides(Hook.PAGE) == true
- fun hasLyrics(): Boolean = isReady && providing(Hook.LYRICS).isNotEmpty()
+ fun hasLyrics(): Boolean { providedState.value; return isReady && providing(Hook.LYRICS).isNotEmpty() }
/**
* An audio-source extension is asked for songs: one runs and is not inactive, or one that is on
* is still being started at launch (the song then waits for it, see [audio]).
*/
- fun hasAudioSource(): Boolean = isReady && (providing(Hook.AUDIO_SOURCE).isNotEmpty() || startingAudioSource())
+ fun hasAudioSource(): Boolean { providedState.value; return isReady && (providing(Hook.AUDIO_SOURCE).isNotEmpty() || startingAudioSource()) }
/** The app is still starting the extensions on at launch, an audio source among them. */
private fun startingAudioSource(): Boolean =
@@ -595,7 +655,7 @@ object Extensions {
fun statusOf(id: String): app.myspoti.extensions.ExtensionStatus? = health.last(id)
/** An enabled extension gives songs' download files (without one, downloads say to install one). */
- fun hasDownloadSource(): Boolean = isReady && providing(Hook.DOWNLOAD_SOURCE).isNotEmpty()
+ fun hasDownloadSource(): Boolean { providedState.value; return isReady && providing(Hook.DOWNLOAD_SOURCE).isNotEmpty() }
/**
* The files [track] can be downloaded from in [quality] (`hi-res`, `cd`, `small`), best first,
@@ -757,6 +817,7 @@ object Extensions {
val ms = System.currentTimeMillis() - t0
val changed = health.record(id, s)
if (changed && s.live) misses.clear()
+ if (changed) refreshProvided()
if (changed) log(id, when (s.state) {
"live" -> "status: live${s.detail?.let { " ($it)" } ?: ""} in $ms ms"
"inactive" -> "status: inactive: ${s.detail ?: "no detail"} in $ms ms"
@@ -1038,6 +1099,7 @@ object Extensions {
runtimes[e.id] = rt
runningSha[e.id] = e.sha256
misses.clear()
+ refreshProvided()
log(e.id, "loaded ${p.manifest.version} (granted: ${e.granted.sorted().joinToString().ifBlank { "nothing" }})")
if (onlineMarker(e.id).exists() && isOnline()) deliverOnline(e.id)
if (probe) scope.launch { probe(e.id, rt) }
@@ -1053,6 +1115,7 @@ object Extensions {
runtimes.remove(id)?.close(); ExtensionAuth.cancel(id)
health.forget(id); _statuses.value = health.inactiveNow()
misses.clear()
+ refreshProvided()
}
/** Delivers a sign-in page's outcome to [id] ([ExtensionAuth]). */
@@ -1083,10 +1146,14 @@ object Extensions {
private fun setError(id: String, message: String) { _errors.value = _errors.value + (id to message) }
private fun clearError(id: String) { _errors.value = _errors.value - id }
- internal fun update(change: (Registry) -> Registry) = synchronized(lock) {
- val r = change(_registry.value)
- _registry.value = r
- runCatching { Registry.write(File(dir, "registry.json"), r) }.onFailure { Logbook.log("ext: registry not saved: ${it.message}") }
+ internal fun update(change: (Registry) -> Registry) {
+ synchronized(lock) {
+ val r = change(_registry.value)
+ _registry.value = r
+ runCatching { Registry.write(File(dir, "registry.json"), r) }.onFailure { Logbook.log("ext: registry not saved: ${it.message}") }
+ }
+ // Turned on or off, the order of the sources, the active one: who gives what may have changed.
+ refreshProvided()
}
fun log(id: String, message: String) {
diff --git a/base/app/src/main/java/com/music/spotui/ui/components/QualityPickers.kt b/base/app/src/main/java/com/music/spotui/ui/components/QualityPickers.kt
index d2f637b9..96c164de 100644
--- a/base/app/src/main/java/com/music/spotui/ui/components/QualityPickers.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/components/QualityPickers.kt
@@ -22,6 +22,7 @@ import androidx.compose.material3.RadioButton
import androidx.compose.material3.RadioButtonDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
@@ -153,6 +154,9 @@ object DownloadAsk {
@Composable
fun DownloadAskHost() {
+ // A download extension was installed meanwhile: the pointer to the store has done its job.
+ val hasSource = com.music.spotui.extensions.Extensions.hasDownloadSource()
+ LaunchedEffect(hasSource) { if (hasSource) DownloadAsk.needSource = false }
if (DownloadAsk.needSource) NeedSourceDialog()
val action = DownloadAsk.pending ?: return
val choices = listOf(
diff --git a/base/app/src/main/java/com/music/spotui/ui/screens/LyricsScreen.kt b/base/app/src/main/java/com/music/spotui/ui/screens/LyricsScreen.kt
index ef01d663..16c075d3 100644
--- a/base/app/src/main/java/com/music/spotui/ui/screens/LyricsScreen.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/screens/LyricsScreen.kt
@@ -216,8 +216,13 @@ private fun shareLyrics(context: Context, title: String, artist: String, line: S
internal fun rememberLyricsState(vm: LyricsViewModel, title: String, artist: String): LyricsViewModel.State {
// currentTrackId is plain data, not Compose state: the playing item's uri re-runs the load on a skip.
val playingUri = SongPlayer.nowPlaying.value.uri
- LaunchedEffect(title, artist, playingUri, SongPlayer.currentTrackId) {
- SongPlayer.currentLyricsTrack()?.let { vm.load(it) }
+ // The lyrics extensions changed (one installed, removed…): the song is read again from the new set.
+ val sources by com.music.spotui.data.api.LyricsApi.sourcesTick.collectAsState()
+ var seen by remember { mutableStateOf(sources) }
+ LaunchedEffect(title, artist, playingUri, SongPlayer.currentTrackId, sources) {
+ val again = seen != sources
+ seen = sources
+ SongPlayer.currentLyricsTrack()?.let { vm.load(it, force = again) }
}
return vm.state.collectAsState().value
}