Native Android client for Spotify, built with Jetpack Compose
Kotlin ad-freeadblockandroidjetpack-composekotlinlyricsmusic-playermusic-videomyspotispotifyspotify-adblockerspotify-clientspotify-connectspotui
A newly installed extension is asked first in every order it stands in (its areas on the Installed tab and the audio and download source orders, above Spotify too), the others keeping their order behind it, while an update, a revert or turning one back on leaves the user's order as it was
kota-zoec19e89e07d8
diff --git a/base/app/src/main/java/com/music/spotui/extensions/ExtensionRegistry.kt b/base/app/src/main/java/com/music/spotui/extensions/ExtensionRegistry.ktindex 7e1cc63a..43399d1b 100644--- a/base/app/src/main/java/com/music/spotui/extensions/ExtensionRegistry.kt+++ b/base/app/src/main/java/com/music/spotui/extensions/ExtensionRegistry.kt@@ -8,9 +8,11 @@ import app.myspoti.extensions.Clashimport app.myspoti.extensions.Hookimport app.myspoti.extensions.Levelimport app.myspoti.extensions.Manifest+import app.myspoti.extensions.Modeimport app.myspoti.extensions.Originimport app.myspoti.extensions.Snapshotimport app.myspoti.extensions.Storage+import app.myspoti.extensions.modeimport kotlinx.serialization.Serializableimport kotlinx.serialization.builtins.MapSerializerimport kotlinx.serialization.builtins.serializer@@ -89,8 +91,9 @@ data class Registry(/*** Per [Area] key, the ids in the order the user set on the Installed tab: asked first, first* answer wins (lyrics: the best answer, ties to the higher one; blocks: shown first; playback- * commands: the higher wins a contradiction). An extension not listed (installed since) comes- * after, in installation order. Before areas, keys were hook keys: [migrated] maps them.+ * commands: the higher wins a contradiction). A new install goes first ([firstOnInstall]); an+ * extension not listed (an area it gained with an update) comes after, in installation order.+ * Before areas, keys were hook keys: [migrated] maps them.*/val priority: Map<String, List<String>> = emptyMap(),/** Per exclusive action key (audio.source, download.source), the extension the user made active. */@@ -131,6 +134,17 @@ data class Registry(return copy(priority = priority + (area to now))}+ /**+ * [id], installed just now as [m], first in every order it stands in: its areas ([Areas.of])+ * and the sources it gives (audio, downloads, Spotify included), so it is asked before the+ * others. They keep their order behind it (never moved: installation order). Not for an+ * update or a turn back on: the order the user left stays as it is.+ */+ fun firstOnInstall(id: String, m: Manifest): Registry {+ val keys = Areas.of(m).map { it.key } + m.actionSet().filter { it.mode == Mode.ORDERED }.map { it.key }+ return copy(priority = priority + keys.associateWith { k -> listOf(id) + (priority[k].orEmpty() - id) })+ }+/*** A registry written before actions, as one now: granted hook and permission keys become* action keys ([Action.migrateGranted]), priorities per hook become priorities per area.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.ktindex 633b8924..33d5ee71 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@@ -354,7 +354,8 @@ object Extensions {rawGrants = (before?.rawGrants.orEmpty() +if (app.myspoti.extensions.Action.SPOTIFY_RAW.key in granted) p.manifest.declaredWrites() else emptyList()).distinct(),)- update { it.put(e) }+ // A fresh install is asked first wherever it acts; an update keeps the user's order.+ update { r -> r.put(e).let { if (before == null) it.firstOnInstall(id, p.manifest) else it } }e to before}failures.reset(id)diff --git a/base/app/src/test/java/com/music/spotui/extensions/ExtensionRegistryTest.kt b/base/app/src/test/java/com/music/spotui/extensions/ExtensionRegistryTest.ktindex f7ba8193..b360e9b7 100644--- a/base/app/src/test/java/com/music/spotui/extensions/ExtensionRegistryTest.kt+++ b/base/app/src/test/java/com/music/spotui/extensions/ExtensionRegistryTest.kt@@ -235,7 +235,7 @@ class ExtensionRegistryTest {assertEquals(listOf("a", "c", "b"), r.byPriority("lyrics", ids) { it })r = r.move("lyrics", ids, "c", -5)assertEquals(listOf("c", "a", "b"), r.byPriority("lyrics", ids) { it })- // Another area keeps installation order; a newly installed one comes last.+ // Another area keeps installation order; one not listed (not a fresh install) comes last.assertEquals(ids, r.byPriority("audio", ids) { it })assertEquals(listOf("c", "a", "b", "d"), r.byPriority("lyrics", ids + "d") { it })// Moving past the end, or an unknown id, changes nothing.@@ -253,7 +253,7 @@ class ExtensionRegistryTest {r = r.move("audio.source", r.bySourceOrder("audio.source", "audio", ids) { it }, "qobuz", -2)assertEquals(listOf("qobuz", "deezer", "tidal"), r.bySourceOrder("audio.source", "audio", ids) { it })assertEquals(ids, r.bySourceOrder("download.source", "audio", ids) { it })- // A source installed later is asked last.+ // A source not listed (it became one with an update) is asked last.assertEquals(listOf("qobuz", "deezer", "tidal", "new"), r.bySourceOrder("audio.source", "audio", ids + "new") { it })// Spotify is last until moved; moved first, it stays first and a new source goes after it.val line = ids + SPOTIFY_SOURCE@@ -264,6 +264,33 @@ class ExtensionRegistryTest {assertEquals(listOf(SPOTIFY_SOURCE) + ids + "new", r.bySourceOrder("audio.source", "audio", ids + "new" + SPOTIFY_SOURCE) { it })}+ @Test fun aFreshInstallIsAskedFirstWhereverItActs() {+ fun m(id: String, vararg actions: String) = Manifest(id, id, "1", author = "me", actions = actions.map { ActionRequest(it, "Because") })+ val ids = listOf("tidal", "qobuz", "deezer")+ // No order set yet: the new one first, the others behind it in installation order.+ var r = Registry().firstOnInstall("new", m("new", "lyrics.provide", "audio.source", "network"))+ assertEquals(listOf("new") + ids, r.byPriority("lyrics", ids + "new") { it })+ assertEquals(listOf("new") + ids + SPOTIFY_SOURCE, r.bySourceOrder("audio.source", "audio", ids + "new" + SPOTIFY_SOURCE) { it })+ // What it does not give keeps its order: downloads, home.+ assertEquals(ids, r.bySourceOrder("download.source", "audio", ids) { it })+ assertNull(r.priority["download.source"])+ assertNull(r.priority["home"])+ // The user's order: the new one above it all, Spotify moved first and the one active before included.+ r = Registry(active = mapOf("download.source" to "deezer"))+ .move("audio.source", ids + SPOTIFY_SOURCE, SPOTIFY_SOURCE, -3)+ .move("lyrics", ids, "deezer", -2)+ .firstOnInstall("dl", m("dl", "audio.source", "download.source", "lyrics.provide"))+ assertEquals(listOf("dl", SPOTIFY_SOURCE) + ids, r.bySourceOrder("audio.source", "audio", ids + "dl" + SPOTIFY_SOURCE) { it })+ assertEquals(listOf("dl", "deezer", "tidal", "qobuz"), r.bySourceOrder("download.source", "audio", ids + "dl") { it })+ assertEquals(listOf("dl", "deezer", "tidal", "qobuz"), r.byPriority("lyrics", ids + "dl") { it })+ // Moved down by the user, it stays there: only a fresh install puts it first, never twice listed.+ r = r.move("lyrics", ids + "dl", "dl", 3)+ assertEquals(listOf("deezer", "tidal", "qobuz", "dl"), r.byPriority("lyrics", ids + "dl") { it })+ assertEquals(listOf("dl", "deezer", "tidal", "qobuz"), r.firstOnInstall("dl", m("dl", "lyrics.provide")).priority["lyrics"])+ // Support actions alone: first of Other.+ assertEquals(mapOf("other" to listOf("x.net")), Registry().firstOnInstall("x.net", m("x.net", "network", "storage")).priority)+ }+@Test fun priorityIsKeptOnDiskAndForgetsAnUninstalledExtension() {val m = manifest()val a = installed(m, base).copy(id = "a.b.a")diff --git a/docs/extensions/API.md b/docs/extensions/API.mdindex aec9ffcb..f8e9e66f 100644--- a/docs/extensions/API.md+++ b/docs/extensions/API.md@@ -94,7 +94,8 @@ action it lists, or is not installed. The official repository is suggested, nevesearch, Menus & player, Library & Spotify, Pages & more. Each area opens with a **Built-in** row (adropdown of what Myspoti does there by itself, e.g. Lyrics: Spotify, LRCLIB, NetEase, KuGou,Lyrics+, Genius; built-in sources are not extensions), then the extensions acting there with their-switch and action icons, in the user's order (arrows; installation order until moved). That order+switch and action icons, in the user's order (arrows). A newly installed extension is placed first in each area and in+the audio and download source orders it gives; an update keeps the user's order. That orderis the one the area asks them in (section 3) and the one the playback arbiter uses. The Built-in row says inone plain sentence what the app already does there; an area no extension acts in says "Noextension — the app already does: …". Nothing is ever installed without the install prompt, and