From d8df18df824400ecab66aa7129d66e7fd2b021ce Mon Sep 17 00:00:00 2001 From: FX1922 <120828496+FX192@users.noreply.github.com> Date: Fri, 16 Oct 2026 23:14:49 +0300 Subject: [PATCH] fix: Keep game art in step with Steam's grid folder; apply review fixes (#948) --- .../com/droiddeck/launcher/MainActivity.kt | 16 +- .../launcher/frontend/AddedGameArt.kt | 29 +++- .../launcher/frontend/AddedGameEdits.kt | 15 +- .../droiddeck/launcher/frontend/AddedGames.kt | 2 +- .../droiddeck/launcher/frontend/Library.kt | 9 +- .../launcher/frontend/SteamGameArt.kt | 36 +++-- .../droiddeck/launcher/frontend/SteamGrid.kt | 119 ++++++++++++++ .../launcher/frontend/SteamGridDb.kt | 20 +++ .../droiddeck/launcher/ui/AddedGameEditor.kt | 12 +- .../launcher/frontend/SteamGameArtTest.kt | 4 +- .../launcher/frontend/SteamGridTest.kt | 153 ++++++++++++++++++ docs/development/added-games.md | 16 +- 12 files changed, 393 insertions(+), 38 deletions(-) create mode 100644 app/src/main/java/com/droiddeck/launcher/frontend/SteamGrid.kt create mode 100644 app/src/test/java/com/droiddeck/launcher/frontend/SteamGridTest.kt diff --git a/app/src/main/java/com/droiddeck/launcher/MainActivity.kt b/app/src/main/java/com/droiddeck/launcher/MainActivity.kt index f4a9c0d23..a4ea05c3e 100644 --- a/app/src/main/java/com/droiddeck/launcher/MainActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/MainActivity.kt @@ -1519,10 +1519,17 @@ class MainActivity : ComponentActivity() { }, "added-games-update").start() } + private val steamArtRefreshes = HashMap() + private fun refreshSteamGameArt(appId: Int) { + val version = (steamArtRefreshes[appId] ?: 0) + 1 + steamArtRefreshes[appId] = version Thread({ val fresh = com.droiddeck.launcher.frontend.Library.steamGames(this).firstOrNull { it.appId == appId } ?: return@Thread - ui.post { steamGames = steamGames.map { if (it.appId == appId && it.library != Library.ADDED) fresh else it } } + ui.post { + if (steamArtRefreshes[appId] != version) return@post + steamGames = steamGames.map { if (it.appId == appId && it.library != Library.ADDED) fresh else it } + } }, "steam-art-update").start() } @@ -1666,6 +1673,7 @@ class MainActivity : ComponentActivity() { else -> "Steam" } else null val scanGeneration = ++libraryScanGeneration + val artRefreshesAtStart = HashMap(steamArtRefreshes) if (shortcutPicker) shortcutLibraryScanning = true Thread({ val emus = Library.emulators(this) { id -> DesktopCatalog.installed(this, id) != null } @@ -1694,7 +1702,11 @@ class MainActivity : ComponentActivity() { } ui.post { if (scanGeneration == libraryScanGeneration) { - steamGames = all + val current = steamGames.filter { it.library != Library.ADDED }.associateBy { it.appId } + steamGames = all.map { g -> + val newer = current[g.appId] + if (newer != null && g.library != Library.ADDED && steamArtRefreshes[g.appId] != artRefreshesAtStart[g.appId]) g.withArt(newer.art, newer.hero, newer.icon) else g + } shortcutLibraryScanning = false handleGameLink(all) } diff --git a/app/src/main/java/com/droiddeck/launcher/frontend/AddedGameArt.kt b/app/src/main/java/com/droiddeck/launcher/frontend/AddedGameArt.kt index 846c7b5af..15486c2bd 100644 --- a/app/src/main/java/com/droiddeck/launcher/frontend/AddedGameArt.kt +++ b/app/src/main/java/com/droiddeck/launcher/frontend/AddedGameArt.kt @@ -40,10 +40,10 @@ object AddedGameArt { class Found(val items: List, val status: SteamGridDb.Status) - private val CHOSEN = Regex("""chosen-(\w+)\.(\w+)""") + private val CHOSEN = Regex("""chosen-(p|hero|logo|icon)(?:-\d+)?\.(\w+)""") internal fun chosen(cache: File, slot: Slot): File? = - cache.listFiles { f -> CHOSEN.matchEntire(f.name)?.groupValues?.get(1) == slot.key }?.firstOrNull() + cache.listFiles { f -> CHOSEN.matchEntire(f.name)?.groupValues?.get(1) == slot.key }?.maxWithOrNull(compareBy({ it.lastModified() }, { it.name })) private val IMAGE = listOf("png", "jpg", "jpeg") private val PORTRAIT = listOf("cover", "poster", "grid", "boxart", "capsule", "folder", "library_600x900", "portrait") @@ -147,7 +147,7 @@ object AddedGameArt { fun searchGames(context: Context, term: String): Found = sgdb(context) { SteamGridDb.search(it, term) } fun gameImages(context: Context, id: Int, slot: Slot): Found