fix(library): added and Battle.net games sort by when they were played and installed (#2256)

* fix(library): added and Battle.net games sort by when they were played and installed

Recently played and Recently installed put every added game, Battle.net
games included, at the bottom: nothing recorded a launch or an install time
for them, and the Steam play-time lookup was never reached once an entry had
a game. Launching an added game now records its play time, added games carry
their folder's install time (kept in the library cache), Battle.net installs
report theirs, and a zero time falls through to the next source.

* fix(library): an added game's play time is recorded only after it launches and kept when it is rebuilt

* fix(library): an added game's play time is recorded only when its launch is accepted

* fix(library): an added game's play time is recorded when its session actually starts

* fix(library): an added game's play time is recorded when its session service starts
This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-11-07 23:17:43 -05:00
1 parent 914b3588e1
commit 77ef10d601
9 files changed
+84 -15

No files matched your search

@@ -45,6 +45,30 @@ class LibraryShortcutsLastPlayedTest {
assertEquals(mapOf(3388195926L to 1792931476L, 1234L to 1700000000L), Library.shortcutsLastPlayed(root))
}
@Test fun aLaunchedAddedGameRemembersItsPlayTime() {
val context = org.robolectric.RuntimeEnvironment.getApplication()
val added = Library.SteamGame(-1, "World of Warcraft", null, Library.ADDED, gameId = 0xC0FFEE0002000000uL.toLong())
val steam = Library.SteamGame(570, "Dota 2", null, "/steam")
assertEquals(0L, Library.recordedPlay(context, added.gameId))
val before = System.currentTimeMillis() / 1000
Library.recordPlayed(context, added)
Library.recordPlayed(context, steam)
assert(Library.recordedPlay(context, added.gameId) >= before)
assertEquals(0L, Library.recordedPlay(context, steam.gameId))
}
@Test fun anAddedGameBuiltAgainKeepsItsRecordedPlayTime() {
val context = org.robolectric.RuntimeEnvironment.getApplication()
val dir = tmp.newFolder("Celeste")
val exe = File(dir, "Celeste.exe").apply { writeText("x") }
val g = AddedGames.Game(dir, "Celeste", exe, "/g/Celeste.exe", "/g", 0x82000003L, 0x82000003L, emptyList())
val shown = Library.addedGame(context, g, emptyList())
assertEquals(0L, shown.lastPlayed)
Library.recordPlayed(context, shown)
assertEquals(Library.recordedPlay(context, g.gameId), Library.addedGame(context, g, emptyList()).lastPlayed)
assertEquals(1900000000L, Library.addedGame(context, g, emptyList(), lastPlayed = 1900000000L).lastPlayed)
}
@Test fun missingOrBrokenShortcutsGiveNothing() {
val root = steamRoot()
assertEquals(emptyMap<Long, Long>(), Library.shortcutsLastPlayed(root))
@@ -20,6 +20,14 @@ class SortCatalogItemsTest {
assertEquals(listOf("Zelda", "Beta", "alpha"), sortCatalogItems(items, "titleDesc").map { it.title })
}
@Test fun anEntryTimeFallsBackWhenTheFirstSourceHasNone() {
assertEquals(30L, entryTime(30L, 20L))
assertEquals(20L, entryTime(0L, 20L))
assertEquals(20L, entryTime(null, 20L))
assertEquals(0L, entryTime(0L, null))
assertEquals(0L, entryTime(null, 0L))
}
@Test fun playedAndInstalledComeFirstWithTitlesBreakingTies() {
val items = listOf(item("1", "Zelda"), item("2", "alpha"), item("3", "Beta"))
val played = mapOf("gog:3" to 900L, "gog:1" to 900L)