feat(settings): one home per setting, Storage/Syncthing/Downloads tabs, scoped frame limit, clearer menus (#2791)

This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-11-17 20:26:37 -05:00
1 parent 868207baf8
commit 0ce168b913
41 files changed
+1283 -187

No files matched your search

@@ -85,4 +85,23 @@ class SessionScalingPrefsTest {
SessionPrefs.setUpscaler(context, 1)
assertEquals(0, prefs.getInt("upscaler", -1))
}
private fun fpsContext(): Context = RuntimeEnvironment.getApplication().also {
it.getSharedPreferences("session", Context.MODE_PRIVATE).edit().clear().commit()
}
@Test fun aFrameLimitStaysWithTheGameOrDesktopItWasSetIn() {
val ctx = fpsContext()
val game = SessionPrefs.fpsLimitKey(SessionService.MODE_RUN, "123")
val desktop = SessionPrefs.fpsLimitKey(SessionService.MODE_DESKTOP, null)
SessionPrefs.saveFpsLimit(ctx, game, 45)
SessionPrefs.saveFpsLimit(ctx, desktop, 30)
assertEquals(45, SessionPrefs.savedFpsLimit(ctx, game))
assertEquals(30, SessionPrefs.savedFpsLimit(ctx, desktop))
assertEquals(0, SessionPrefs.savedFpsLimit(ctx, SessionPrefs.fpsLimitKey(SessionService.MODE_RUN, "456")))
assertEquals(null, SessionPrefs.fpsLimitKey(SessionService.MODE_STEAM, "123"))
assertEquals(null, SessionPrefs.fpsLimitKey(SessionService.MODE_RUN, "not-a-game"))
SessionPrefs.saveFpsLimit(ctx, game, 0)
assertEquals(0, SessionPrefs.savedFpsLimit(ctx, game))
}
}
@@ -42,4 +42,20 @@ class StoreCacheTest {
val fresh = listOf(a)
assertSame(fresh, mergeItems(null, fresh))
}
@Test fun aSavedStoreLibraryRoundTripsWithItsStoreAndExtras() {
val games = listOf(
CatalogItem(
Store.UBISOFT, "4553", "Far Cry 3 Blood Dragon", "https://img/wide.jpg", tallImageUrl = "https://img/tall.jpg",
logoUrl = "https://img/logo.png", owned = true, sizeBytes = 2_000_000L, extra = mapOf("productId" to "205", "spaceId" to "abc"),
subscription = true, includedWith = "Ubisoft+",
),
CatalogItem(Store.UBISOFT, "1", "No art", null),
)
assertEquals(games, StoreLibraryCache.decode(Store.UBISOFT, StoreLibraryCache.encode(games)))
}
@Test fun aSavedEmptyStoreLibraryStaysEmptyRatherThanUnknown() {
assertEquals(emptyList<CatalogItem>(), StoreLibraryCache.decode(Store.ROCKSTAR, StoreLibraryCache.encode(emptyList())))
}
}
@@ -41,23 +41,23 @@ class NavTabsTest {
}
@Test fun musicStartsInMore() {
assertEquals(listOf("steam", "games", "stores", "desktop", "components", "setup", "updates", NavTabs.MORE), navigationKeys(state()))
assertEquals(listOf("soundtracks"), NavTabs.more(state()))
assertEquals(setOf("soundtracks", "agent"), NavTabs.shelved)
assertEquals(listOf("steam", "games", "stores", "downloads", "desktop", "components", "setup", "updates", NavTabs.MORE), navigationKeys(state()))
assertEquals(listOf("soundtracks", "storage", "sync"), NavTabs.more(state()))
assertEquals(setOf("soundtracks", "agent", "storage", "sync"), NavTabs.shelved)
assertFalse(com.droiddeck.launcher.agent.AgentTab.shown)
}
@Test fun showingMusicOnceKeepsItShownAfterReload() {
place("soundtracks", TabPlace.BAR)
NavTabs.load(ctx)
assertEquals(listOf("steam", "games", "soundtracks", "stores", "desktop", "components", "setup", "updates"), navigationKeys(state()))
assertEquals(listOf("steam", "games", "soundtracks", "stores", "downloads", "desktop", "components", "setup", "updates", NavTabs.MORE), navigationKeys(state()))
}
@Test fun shelvedTabsLeaveTheBarAndAddMoreAtTheEnd() {
place("stores", TabPlace.MORE)
place("components", TabPlace.MORE)
val s = state()
assertEquals(listOf("components", "soundtracks", "stores"), NavTabs.more(s))
assertEquals(listOf("components", "soundtracks", "stores", "storage", "sync"), NavTabs.more(s))
assertEquals(NavTabs.MORE, navigationKeys(s).last())
assertFalse("stores" in navigationKeys(s))
}
@@ -73,6 +73,7 @@ class NavTabsTest {
@Test fun disabledStoresFeatureReadsAsHidden() {
assertEquals(TabPlace.HIDDEN, NavTabs.place(state(storesOn = false), "stores"))
assertEquals(TabPlace.HIDDEN, NavTabs.place(state(storesOn = false), "downloads"))
}
@Test fun movingSwapsWithTheNextVisibleTabAndPersists() {
@@ -84,25 +85,37 @@ class NavTabsTest {
}
@Test fun tabsMissingFromASavedOrderSlotInAfterTheirDefaultNeighbour() {
assertEquals(listOf("updates", "steam", "games", "soundtracks", "stores", "desktop", "agent", "components", "android-apps", "setup"),
assertEquals(listOf("updates", "steam", "games", "soundtracks", "stores", "downloads", "desktop", "agent", "components", "android-apps", "storage", "sync", "setup"),
NavTabs.arrange(listOf("updates", "steam")))
assertEquals(listOf("games", "soundtracks", "steam", "setup", "stores", "desktop", "agent", "components", "android-apps", "updates"),
assertEquals(listOf("games", "soundtracks", "steam", "setup", "stores", "downloads", "desktop", "agent", "components", "android-apps", "storage", "sync", "updates"),
NavTabs.arrange(listOf("games", "steam", "setup", "stores", "desktop", "components", "android-apps", "updates", "bogus")))
}
@Test fun storageAndSyncJoinMoreForUsersWithASavedLayout() {
ctx.getSharedPreferences("session", Context.MODE_PRIVATE).edit()
.putString("navTabOrder", "steam,games,soundtracks,stores,desktop,agent,components,android-apps,setup,updates")
.putString("navTabShelved", "soundtracks").commit()
NavTabs.load(ctx)
assertEquals(listOf("soundtracks", "storage", "sync"), NavTabs.more(state()))
place("sync", TabPlace.BAR)
NavTabs.load(ctx)
assertTrue("sync" in navigationKeys(state()))
}
@Test fun moreCarriesTheDownloadCountAndBadgesOfShelvedTabs() {
place("stores", TabPlace.MORE)
place("downloads", TabPlace.MORE)
place("setup", TabPlace.MORE)
val s = state(downloads = 3, setupReady = false)
assertEquals(3, railCount(s, NavTabs.MORE))
assertTrue(railBadge(s, NavTabs.MORE))
place("stores", TabPlace.BAR)
place("downloads", TabPlace.BAR)
assertEquals(0, railCount(s, NavTabs.MORE))
assertEquals(3, railCount(s, "stores"))
assertEquals(3, railCount(s, "downloads"))
assertEquals(0, railCount(s, "stores"))
}
@Test fun sideRailShowsTheDownloadCountOnMoreWhenStoresIsShelved() {
place("stores", TabPlace.MORE)
@Test fun sideRailShowsTheDownloadCountOnMoreWhenDownloadsIsShelved() {
place("downloads", TabPlace.MORE)
val s = state(downloads = 2)
compose.setContent {
DroidDeckTheme {
@@ -111,13 +124,13 @@ class NavTabsTest {
}
}
}
compose.onNodeWithTag("rail-stores").assertDoesNotExist()
compose.onNodeWithTag("rail-downloads").assertDoesNotExist()
compose.onNode(hasTestTag("rail-more")).assertIsDisplayed()
compose.onNode(hasText("2") and hasParentTag("rail-more"), useUnmergedTree = true).assertIsDisplayed()
}
@Test fun morePageListsShelvedTabsWithTheirCount() {
place("stores", TabPlace.MORE)
place("downloads", TabPlace.MORE)
place("components", TabPlace.MORE)
val s = state(downloads = 4)
compose.setContent {
@@ -127,9 +140,9 @@ class NavTabsTest {
}
}
}
compose.onNodeWithTag("more-stores").assertIsDisplayed()
compose.onNodeWithTag("more-downloads").assertIsDisplayed()
compose.onNodeWithTag("more-components").assertIsDisplayed()
compose.onNode(hasText("4") and hasParentTag("more-stores"), useUnmergedTree = true).assertIsDisplayed()
compose.onNode(hasText("4") and hasParentTag("more-downloads"), useUnmergedTree = true).assertIsDisplayed()
}
@Test fun backFromAShelvedTabReturnsToMore() {
@@ -0,0 +1,69 @@
package com.droiddeck.launcher.ui
import com.droiddeck.launcher.R
import java.io.File
import javax.xml.parsers.DocumentBuilderFactory
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
class SettingsMapTest {
private val strings: Map<String, String> by lazy {
File("src/main/res/values").listFiles { f -> f.extension == "xml" }.orEmpty().flatMap { file ->
val doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(file)
val nodes = doc.getElementsByTagName("string")
(0 until nodes.length).map { i ->
val n = nodes.item(i)
n.attributes.getNamedItem("name").nodeValue to n.textContent.replace("\\'", "'").replace("\\\"", "\"")
}
}.toMap()
}
private val names: Map<Int, String> by lazy {
R.string::class.java.fields.associate { it.getInt(null) to it.name }
}
private fun text(id: Int): String = strings.getValue(names.getValue(id))
private fun render(): String = buildString {
appendLine("# Where settings live")
appendLine()
appendLine("Generated from `SettingsIndex.kt` by `SettingsMapTest`. Run `UPDATE_SETTINGS_MAP=1 ./gradlew :app:testDebugUnitTest --tests '*SettingsMapTest*'` after changing the index.")
appendLine()
appendLine("Links of the form `droiddeck://settings/<section>` open a Settings section directly.")
appendLine()
SettingsIndex.entries.groupBy { it.place }.forEach { (place, entries) ->
appendLine("## ${text(place.title)}")
appendLine()
appendLine("| Setting | Where | Also matches |")
appendLine("| --- | --- | --- |")
entries.forEach { e ->
val where = listOfNotNull(text(place.title), e.within?.let(::text)).joinToString(" › ") +
(e.section?.let { " (`droiddeck://settings/${it.key}`)" } ?: "")
appendLine("| ${text(e.title)} | $where | ${e.words.joinToString(", ")} |")
}
appendLine()
}
}
@Test
fun everyIndexedStringExists() {
SettingsIndex.entries.forEach { e ->
listOfNotNull(e.title, e.within).forEach { id -> assertTrue("missing string $id", names[id] in strings) }
}
SettingsSection.entries.forEach { assertTrue(names[it.title] in strings) }
}
@Test
fun docsMatchIndex() {
val doc = File("../docs/settings-map.md")
val now = render()
if (System.getenv("UPDATE_SETTINGS_MAP") == "1") doc.writeText(now)
assertEquals("docs/settings-map.md is stale; regenerate it", now, doc.readText().replace("\r\n", "\n"))
}
@Test
fun sectionKeysRoundTrip() {
SettingsSection.entries.forEach { assertEquals(it, SettingsSection.of(it.key)) }
}
}