From fd0c6f124fe82ed64450f764091d27e594f57a3a Mon Sep 17 00:00:00 2001
From: The412Banner
Date: Thu, 8 Oct 2026 18:19:40 -0400
Subject: [PATCH] Stores: the pad keeps its place on the game page, and no
template keys in a description
A card opening its page took the pad's focus with it, so the next press
landed on the rail. Each move on the page now says where focus goes:
the game page's main action (or its back link), the card the page was
opened from on the way back, the first card after a tab or chip change;
the page is a focus group, so Left is the way to the rail.
GOG's account endpoints return template keys (product_description_)
for some products, and the v2 record repeats them. Store text now has
those keys dropped, tags stripped and entities decoded; the library
tries the product's lead, then the v2 overview and description, and shows
nothing when all are templates. Epic's and Amazon's text is cleaned too.
---
.../droiddeck/launcher/stores/StoreCatalog.kt | 26 ++++++++++
.../launcher/stores/epic/EpicLibrary.kt | 2 +-
.../launcher/stores/epic/EpicStoreCatalog.kt | 2 +-
.../launcher/stores/gog/GogLibrary.kt | 19 ++++---
.../com/droiddeck/launcher/ui/StoresDetail.kt | 6 ++-
.../com/droiddeck/launcher/ui/StoresPage.kt | 49 ++++++++++++++++---
docs/progress-log.md | 10 ++++
7 files changed, 94 insertions(+), 20 deletions(-)
diff --git a/app/src/main/java/com/droiddeck/launcher/stores/StoreCatalog.kt b/app/src/main/java/com/droiddeck/launcher/stores/StoreCatalog.kt
index 8df9c71177..c6e1dd5a8e 100644
--- a/app/src/main/java/com/droiddeck/launcher/stores/StoreCatalog.kt
+++ b/app/src/main/java/com/droiddeck/launcher/stores/StoreCatalog.kt
@@ -56,6 +56,32 @@ class InstalledStoreGame(val sidecar: StoreGameSidecar, val folder: java.io.File
val key: String get() = "${sidecar.store.id}:${sidecar.id}"
}
+private val TEMPLATE_KEY = Regex("product_(description|feature)_\\d+")
+private val HTML_TAG = Regex("<[^>]+>")
+private val ENTITY = Regex("&(#\\d+|#x[0-9a-fA-F]+|[a-zA-Z]+);")
+private val NAMED_ENTITIES = mapOf("amp" to "&", "lt" to "<", "gt" to ">", "quot" to "\"", "apos" to "'", "nbsp" to " ", "ndash" to "–", "mdash" to "—", "hellip" to "…", "trade" to "™", "reg" to "®", "copy" to "©")
+
+/**
+ * Store copy as plain text: GOG's account endpoints return template keys
+ * (`product_description_2015545325`) for some products instead of words, and every store's
+ * descriptions carry HTML. Those keys go, tags go, entities are decoded, whitespace is collapsed;
+ * "" when nothing readable is left, so a page shows nothing rather than a placeholder.
+ */
+fun cleanStoreText(raw: String?): String {
+ if (raw.isNullOrBlank()) return ""
+ var s = raw.replace(TEMPLATE_KEY, " ")
+ s = s.replace(Regex("(?i)
|
||"), "\n").replace(HTML_TAG, " ")
+ s = ENTITY.replace(s) { m ->
+ val e = m.groupValues[1]
+ when {
+ e.startsWith("#x") -> e.substring(2).toIntOrNull(16)?.toChar()?.toString() ?: " "
+ e.startsWith("#") -> e.substring(1).toIntOrNull()?.toChar()?.toString() ?: " "
+ else -> NAMED_ENTITIES[e.lowercase()] ?: " "
+ }
+ }
+ return s.lines().map { it.replace(Regex("[ \\t\\u00A0]+"), " ").trim() }.filter { it.isNotEmpty() }.joinToString("\n")
+}
+
/** Human sizes the way the Downloads page and the cards print them ("810.2 MB", "3.9 GB"). */
fun formatBytes(bytes: Long): String = when {
bytes >= 1_073_741_824L -> "%.1f GB".format(bytes / 1_073_741_824.0)
diff --git a/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicLibrary.kt b/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicLibrary.kt
index d5590e0c23..1ef3c28913 100644
--- a/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicLibrary.kt
+++ b/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicLibrary.kt
@@ -111,7 +111,7 @@ object EpicLibrary {
store = Store.EPIC, id = g.appName, title = g.title.ifBlank { g.appName },
imageUrl = g.artSquare.ifBlank { null } ?: g.artCover.ifBlank { null },
tallImageUrl = g.artCover.ifBlank { null } ?: g.artSquare.ifBlank { null },
- developer = g.developer, description = g.description, owned = true,
+ developer = g.developer, description = com.droiddeck.launcher.stores.cleanStoreText(g.description), owned = true,
sizeBytes = EpicPrefs.get(context).getLong("size_${g.appName}", g.installSize),
storeUrl = "https://store.epicgames.com/en-US/browse?q=${java.net.URLEncoder.encode(g.title, "UTF-8")}",
extra = mapOf("namespace" to g.namespace, "catalogItemId" to g.catalogItemId),
diff --git a/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicStoreCatalog.kt b/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicStoreCatalog.kt
index 371f50c347..12f1f2965e 100644
--- a/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicStoreCatalog.kt
+++ b/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicStoreCatalog.kt
@@ -114,7 +114,7 @@ object EpicStoreCatalog {
store = Store.EPIC, id = id, title = title, imageUrl = wide ?: thumb, tallImageUrl = tall ?: thumb, tags = tagLine,
isFree = isFree, hasPrice = hasPrice, finalPrice = finalPrice, originalPrice = if (discountPct > 0) fmtOriginal else "", discountPercent = discountPct,
storeUrl = storeUrl, developer = e.optJSONObject("seller")?.optString("name", "").orEmpty(),
- releaseDate = e.optString("releaseDate", e.optString("effectiveDate", "")), description = e.optString("description", ""),
+ releaseDate = e.optString("releaseDate", e.optString("effectiveDate", "")), description = com.droiddeck.launcher.stores.cleanStoreText(e.optString("description", "")),
extra = buildMap { put("namespace", ns); if (itemIds.isNotEmpty()) put("items", itemIds.joinToString(",")); if (slug.isNotBlank()) put("slug", slug) },
)
}
diff --git a/app/src/main/java/com/droiddeck/launcher/stores/gog/GogLibrary.kt b/app/src/main/java/com/droiddeck/launcher/stores/gog/GogLibrary.kt
index 04066a7fa6..eceb6c38c3 100644
--- a/app/src/main/java/com/droiddeck/launcher/stores/gog/GogLibrary.kt
+++ b/app/src/main/java/com/droiddeck/launcher/stores/gog/GogLibrary.kt
@@ -6,6 +6,7 @@ import android.util.Log
import com.droiddeck.launcher.stores.CatalogItem
import com.droiddeck.launcher.stores.Store
import com.droiddeck.launcher.stores.StoreNet
+import com.droiddeck.launcher.stores.cleanStoreText
import org.json.JSONArray
import org.json.JSONObject
import java.util.concurrent.Callable
@@ -40,7 +41,7 @@ object GogLibrary {
val arr = JSONArray(json)
(0 until arr.length()).mapNotNull { i ->
val o = arr.optJSONObject(i) ?: return@mapNotNull null
- GogGame(o.optString("gameId", ""), o.optString("title", ""), o.optString("imageUrl", ""), o.optString("description", ""),
+ GogGame(o.optString("gameId", ""), o.optString("title", ""), o.optString("imageUrl", ""), cleanStoreText(o.optString("description", "")),
o.optString("developer", ""), o.optString("category", ""), o.optInt("generation", 1), o.optString("verticalCover", "").ifEmpty { null })
}.filter { it.gameId.isNotEmpty() }.sortedBy { it.title.lowercase() }
}.getOrDefault(emptyList())
@@ -124,16 +125,18 @@ object GogLibrary {
val images = prod.optJSONObject("images")
var imageUrl = ""
var boxArt = ""
- runCatching {
- val links = StoreNet.get("https://api.gog.com/v2/games/$id?locale=en-US")?.let { JSONObject(it).optJSONObject("_links") }
- if (links != null) {
- imageUrl = links.optJSONObject("galaxyBackgroundImage")?.optString("href", "").orEmpty()
- boxArt = links.optJSONObject("boxArtImage")?.optString("href", "").orEmpty()
- }
+ val v2 = runCatching { StoreNet.get("https://api.gog.com/v2/games/$id?locale=en-US")?.let { JSONObject(it) } }.getOrNull()
+ v2?.optJSONObject("_links")?.let { links ->
+ imageUrl = links.optJSONObject("galaxyBackgroundImage")?.optString("href", "").orEmpty()
+ boxArt = links.optJSONObject("boxArtImage")?.optString("href", "").orEmpty()
}
if (imageUrl.isEmpty()) imageUrl = images?.optString("logo2x", "") ?: ""
if (imageUrl.isEmpty()) imageUrl = images?.optString("icon", "") ?: ""
- val desc = prod.optJSONObject("description")?.optString("lead", "") ?: ""
+ // The account endpoint hands back template keys for some products; the v2 record's text
+ // is tried next, and when that is a template too the game simply has no description.
+ val desc = cleanStoreText(prod.optJSONObject("description")?.optString("lead", ""))
+ .ifEmpty { cleanStoreText(v2?.optString("overview", "")) }
+ .ifEmpty { cleanStoreText(v2?.optString("description", "")) }
val developer = prod.optJSONObject("developers")?.optString("name", "") ?: prod.optString("developer", "")
val genres = prod.optJSONArray("genres")
val category = if (genres != null && genres.length() > 0) genres.optJSONObject(0)?.optString("name", "") ?: "" else ""
diff --git a/app/src/main/java/com/droiddeck/launcher/ui/StoresDetail.kt b/app/src/main/java/com/droiddeck/launcher/ui/StoresDetail.kt
index c72a3bdcdc..ae1cee04d5 100644
--- a/app/src/main/java/com/droiddeck/launcher/ui/StoresDetail.kt
+++ b/app/src/main/java/com/droiddeck/launcher/ui/StoresDetail.kt
@@ -114,8 +114,10 @@ internal fun StoreGameDetail(store: Store, key: String, s: FrontEndState, a: Fro
}
}
}
- if (item != null && item.description.isNotBlank()) Rise(2) {
- Text(item.description, fontSize = 13.sp, lineHeight = 19.sp, color = colors.onSurfaceVariant, maxLines = 6, overflow = TextOverflow.Ellipsis, modifier = Modifier.padding(top = 12.dp))
+ // Plain text only, and nothing at all when the store sent a template key instead of words.
+ val description = item?.let { com.droiddeck.launcher.stores.cleanStoreText(it.description) }.orEmpty()
+ if (description.isNotBlank()) Rise(2) {
+ Text(description, fontSize = 13.sp, lineHeight = 19.sp, color = colors.onSurfaceVariant, maxLines = 6, overflow = TextOverflow.Ellipsis, modifier = Modifier.padding(top = 12.dp))
}
Rise(3) {
BoxWithConstraints(Modifier.fillMaxWidth().padding(top = 16.dp)) {
diff --git a/app/src/main/java/com/droiddeck/launcher/ui/StoresPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/StoresPage.kt
index 907ca0539b..c2d94b2c6f 100644
--- a/app/src/main/java/com/droiddeck/launcher/ui/StoresPage.kt
+++ b/app/src/main/java/com/droiddeck/launcher/ui/StoresPage.kt
@@ -7,6 +7,7 @@ import androidx.compose.foundation.LocalIndication
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
+import androidx.compose.foundation.focusGroup
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.hoverable
import androidx.compose.foundation.interaction.MutableInteractionSource
@@ -96,20 +97,44 @@ internal fun StoresPage(s: FrontEndState, a: FrontEndActions, modifier: Modifier
LaunchedEffect(Unit) { StoresState.refresh(ctx) }
// A store the account is signed into fills itself when its chip is on screen.
LaunchedEffect(chip, StoresState.accounts[store]) { if (store != null && StoresState.isSignedIn(store)) StoresState.open(ctx, store) }
+ // A pad's focus sits on something the page is about to replace - the card that opens a game,
+ // a tab's contents - and would be lost with it, leaving the next press to land on the rail.
+ // Each move says where focus goes next: into the game page's main action, back to the card
+ // it was opened from, or onto the first card of a tab or store just picked.
+ val ff = LocalFrontFocus.current
+ val inputMode = androidx.compose.ui.platform.LocalInputModeManager.current
+ var focusMove by remember { mutableStateOf?>(null) }
+ var lastOpened by remember { mutableStateOf(null) }
+ fun move(kind: String) { focusMove = kind to (focusMove?.second ?: 0) + 1 }
+ fun open(key: String) { lastOpened = key; openGame = key; move("detail") }
+ fun closeGame() { openGame = null; move("card") }
+ fun switchTab(to: String) { tab = to; move("first") }
// Picking a chip opens the tab Setup says (Library or Store); a tab the user switches to
// afterwards stays until another chip is picked.
val pickChip: (String) -> Unit = { id ->
chip = id; openGame = null; query = ""
if (id != DOWNLOADS) tab = if (s.storesOpenTab == SessionPrefs.STORES_OPEN_STORE) "store" else "library"
+ move("first")
}
- BackHandler(enabled = openGame != null) { openGame = null }
+ BackHandler(enabled = openGame != null) { closeGame() }
val scroll = rememberScrollState()
LaunchedEffect(chip, tab, openGame) { scroll.scrollTo(0) }
+ LaunchedEffect(focusMove, openGame) {
+ if (inputMode.inputMode != androidx.compose.ui.input.InputMode.Keyboard || ff == null) return@LaunchedEffect
+ val target = when {
+ openGame != null -> if (ff.primaryAttached > 0) ff.primary else ff.items["back:${store?.label}"]
+ focusMove?.first == "card" -> lastOpened?.let { ff.items["card:$it"] } ?: ff.firstTile.takeIf { ff.firstTileAttached > 0 }
+ focusMove?.first == "first" -> ff.firstTile.takeIf { ff.firstTileAttached > 0 }
+ else -> null
+ } ?: return@LaunchedEffect
+ var landed = false
+ focusWithinFrames({ landed }) { target.also { landed = runCatching { it.requestFocus() }.isSuccess } }
+ }
Column(
modifier = modifier.padding(horizontal = padH, vertical = if (narrow) 10.dp else 14.dp)
.bumpers(
- onPrevious = { if (openGame == null && chip != DOWNLOADS) tab = TABS[(TABS.indexOf(tab) + TABS.size - 1) % TABS.size] },
- onNext = { if (openGame == null && chip != DOWNLOADS) tab = TABS[(TABS.indexOf(tab) + 1) % TABS.size] },
+ onPrevious = { if (openGame == null && chip != DOWNLOADS) switchTab(TABS[(TABS.indexOf(tab) + TABS.size - 1) % TABS.size]) },
+ onNext = { if (openGame == null && chip != DOWNLOADS) switchTab(TABS[(TABS.indexOf(tab) + 1) % TABS.size]) },
),
) {
Rise(0) { StoreChips(chip, s.storeDownloadsActive, onPick = pickChip, onSettings = { settings = true }) }
@@ -118,8 +143,10 @@ internal fun StoresPage(s: FrontEndState, a: FrontEndActions, modifier: Modifier
chip == DOWNLOADS -> StoresDownloadsPane(s, a)
store == null -> {}
!StoresState.isSignedIn(store) -> Rise(1) { SignInCard(store) }
- openGame != null -> StoreGameDetail(store, openGame!!, s, a, onBack = { openGame = null })
- else -> Storefront(store, tab, query, s, a, onTab = { tab = it }, onQuery = { query = it }, onOpen = { openGame = it })
+ // One focus group, so the pad walks the page's own controls - back, the hero's
+ // actions, the cards - and reaches the rail only with Left from them.
+ openGame != null -> Column(Modifier.fillMaxWidth().focusGroup()) { StoreGameDetail(store, openGame!!, s, a, onBack = { closeGame() }) }
+ else -> Storefront(store, tab, query, s, a, onTab = { switchTab(it) }, onQuery = { query = it }, onOpen = { open(it) })
}
}
}
@@ -289,7 +316,13 @@ private fun Storefront(
}
StoresState.status[store]?.let { Rise(3) { Text(it, fontSize = 12.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(bottom = 6.dp)) } }
StoresState.problems[store]?.let { Rise(3) { Box(Modifier.padding(bottom = 8.dp)) { Note(it) } } }
- val card: @Composable (CatalogItem) -> Unit = { item -> GameCard(item, store, s, a, installedKeys, onOpen) }
+ // The first card drawn on the tab is where a pad lands after a tab or chip change.
+ var firstPlaced = false
+ val card: @Composable (CatalogItem) -> Unit = { item ->
+ val first = !firstPlaced
+ firstPlaced = true
+ GameCard(item, store, s, a, installedKeys, onOpen, first)
+ }
when (tab) {
"installed" -> Grid(installedItems.filter(::matches), stringResource(R.string.stores_installed_empty, store.label), card)
"library" -> Grid(library.filter(::matches), if (library.isEmpty() && StoresState.status[store] != null) stringResource(R.string.stores_library_loading) else stringResource(R.string.stores_nothing_matches), card)
@@ -401,7 +434,7 @@ private val CardWidth = 150.dp
* on the store. Tapping the card itself opens the game's page.
*/
@Composable
-private fun GameCard(item: CatalogItem, store: Store, s: FrontEndState, a: FrontEndActions, installedKeys: Set, onOpen: (String) -> Unit) {
+private fun GameCard(item: CatalogItem, store: Store, s: FrontEndState, a: FrontEndActions, installedKeys: Set, onOpen: (String) -> Unit, first: Boolean = false) {
val ctx = LocalContext.current
val colors = MaterialTheme.colorScheme
val pal = LocalPalette.current
@@ -413,7 +446,7 @@ private fun GameCard(item: CatalogItem, store: Store, s: FrontEndState, a: Front
val download = StoresState.downloads.firstOrNull { it.store == store && it.id == item.id && it.isActive }
val open = { onOpen(item.key) }
Column(
- modifier = Modifier.fillMaxWidth().paneItem("card:${item.key}").graphicsLayer { scaleX = scale; scaleY = scale }
+ modifier = Modifier.fillMaxWidth().paneItem("card:${item.key}").then(if (first) Modifier.firstTile() else Modifier).graphicsLayer { scaleX = scale; scaleY = scale }
.clip(RoundedCornerShape(10.dp)).background(colors.surface).glideBorder(hot, RoundedCornerShape(10.dp), pal.signal, pal.line)
.hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, onClick = open).controllerConfirm(onClick = open),
) {
diff --git a/docs/progress-log.md b/docs/progress-log.md
index fa08e3e248..9e4935b825 100644
--- a/docs/progress-log.md
+++ b/docs/progress-log.md
@@ -80,6 +80,16 @@ without it and Setup says "Stores engine not built").
places `cover.jpg`, `hero.jpg` and `header.jpg` in the game folder, re-encoded as opaque JPEGs
over a dark ground, under the names `AddedGameArt` looks for - so the Games tab and the client's
grid (through the listing) get real art for store games.
+- **Device feedback on `9f5a2f3` (GOG › DOOM I Enhanced page):** (1) the pad lost focus when a
+ card opened its page (the card left composition; the next press landed on the rail). The page
+ now follows the Flathub store's pattern: a focus move is recorded on each change and
+ `focusWithinFrames` lands it - the game page's main action (or its back link), the card the page
+ was opened from on the way back, the first card after a tab or chip change (`firstTile`); the
+ page is a `focusGroup`, so Left is the way to the rail. (2) GOG's account endpoints return
+ template keys (`product_description_2015545325
product_feature_…`) for some products; the
+ v2 record has the same keys for them. `cleanStoreText` drops those keys, strips tags, decodes
+ entities; the library tries the product's lead, then v2 `overview`, then v2 `description`, and
+ shows nothing when all are templates. Epic's and Amazon's text goes through the same cleaner.
- Status: compiles on CI with the JVM and python tests green; nothing device-tested yet - the
sign-in pages, a real install, the shortcut landing in the client and the .bat launch under Proton
are the first things to prove on hardware.