mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 22:36:00 +00:00
feat(library): add a Hidden tab synced with Steam's hidden games (#2803)
* feat(library): add a Hidden tab synced with Steam's hidden games * fix(library): mark the hidden collection as modified so Steam uploads it * fix(library): make the Steam hidden write atomic and refresh the hidden set on resume * feat(library): show an error when hiding a game can't sync with Steam * fix(library): keep the pending Steam upload list safe when it can't be read * fix(library): report a failed Steam sync when the upload marker can't be saved * fix(library): refresh the Steam hidden set from disk after a failed sync * fix(library): keep the cached hidden set when Steam's file can't be read * fix(library): handle a malformed hidden entry and a changed Steam root * fix(library): refuse to overwrite a malformed hidden entry * fix(library): validate the hidden collection, keep Steam saves separate from upload status and cover cloud and uninstalled games * fix(library): accept numeric-string ids, keep uninstalled games in the Hidden tab and hide games from the Steam home list * fix(library): keep hidden Steam games out of the home capsule wall * fix(library): refresh home art when the hidden set changes and track the Steam account * fix(library): clear the cached hidden set when the Steam account changes * fix(library): ignore a previous account's art while the home scan runs * fix(library): conceal home art for hidden added games that carry a Steam app id
This commit is contained in:
1 parent
d89c2c1c2d
commit
f1be935761
43 files changed
+459
-32
No files matched your search
@@ -0,0 +1,101 @@
|
||||
package com.droiddeck.launcher.frontend
|
||||
|
||||
import java.io.File
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33])
|
||||
class SteamHiddenTest {
|
||||
@get:Rule val tmp = TemporaryFolder()
|
||||
|
||||
private fun steamRoot(): File = tmp.newFolder("Steam").also { root ->
|
||||
File(root, "config").mkdirs()
|
||||
File(root, "config/loginusers.vdf").writeText(
|
||||
"\"users\"\n{\n\t\"76561198352563669\"\n\t{\n\t\t\"AccountName\"\t\t\"a\"\n\t\t\"MostRecent\"\t\t\"1\"\n\t}\n}\n")
|
||||
}
|
||||
|
||||
private fun store(root: File, json: String?): File {
|
||||
val dir = File(root, "userdata/392297941/config/cloudstorage").apply { mkdirs() }
|
||||
return File(dir, "cloud-storage-namespace-1.json").also { f -> json?.let { f.writeText(it) } }
|
||||
}
|
||||
|
||||
private fun hiddenEntry(file: File): JSONObject {
|
||||
val entries = JSONArray(file.readText())
|
||||
return (0 until entries.length()).map { entries.getJSONArray(it) }.first { it.getString(0) == "user-collections.hidden" }.getJSONObject(1)
|
||||
}
|
||||
|
||||
@Test fun hidingAddsTheGameAndKeepsOtherEntries() {
|
||||
val root = steamRoot()
|
||||
val file = store(root, """[["user-collections.favorite",{"key":"user-collections.favorite","value":"{}"}],["user-collections.hidden",{"key":"user-collections.hidden","timestamp":5,"version":"7","value":"{\"id\":\"hidden\",\"name\":\"Hidden\",\"added\":[10],\"removed\":[]}"}]]""")
|
||||
assertNotNull(SteamHidden.write(root, 440, true, now = 99))
|
||||
assertEquals(setOf(10L, 440L), SteamHidden.read(root))
|
||||
val entry = hiddenEntry(file)
|
||||
assertEquals(99L, entry.getLong("timestamp"))
|
||||
assertEquals("8", entry.getString("version"))
|
||||
assertEquals("Hidden", JSONObject(entry.getString("value")).getString("name"))
|
||||
assertEquals(2, JSONArray(file.readText()).length())
|
||||
}
|
||||
|
||||
@Test fun unhidingTakesTheGameOutAgain() {
|
||||
val root = steamRoot()
|
||||
store(root, """[["user-collections.hidden",{"key":"user-collections.hidden","value":"{\"id\":\"hidden\",\"added\":[10,440],\"removed\":[]}"}]]""")
|
||||
assertNotNull(SteamHidden.write(root, 440, false))
|
||||
assertEquals(setOf(10L), SteamHidden.read(root))
|
||||
}
|
||||
|
||||
@Test fun aMissingCollectionIsCreatedWhenHiding() {
|
||||
val root = steamRoot()
|
||||
val file = store(root, "[]")
|
||||
assertNotNull(SteamHidden.write(root, 2931908220L, true))
|
||||
assertEquals(setOf(2931908220L), SteamHidden.read(root))
|
||||
assertFalse(hiddenEntry(file).getBoolean("is_deleted"))
|
||||
}
|
||||
|
||||
@Test fun aDeletedCollectionIsRevivedWhenHiding() {
|
||||
val root = steamRoot()
|
||||
store(root, """[["user-collections.hidden",{"key":"user-collections.hidden","is_deleted":true}]]""")
|
||||
assertEquals(emptySet<Long>(), SteamHidden.read(root))
|
||||
assertNotNull(SteamHidden.write(root, 7, true))
|
||||
assertEquals(setOf(7L), SteamHidden.read(root))
|
||||
}
|
||||
|
||||
@Test fun withoutASteamStoreNothingIsWritten() {
|
||||
val root = steamRoot()
|
||||
assertNull(SteamHidden.write(root, 1, true))
|
||||
assertEquals(emptySet<Long>(), SteamHidden.read(root))
|
||||
}
|
||||
|
||||
@Test fun theCollectionIsMarkedAsPendingUploadOnce() {
|
||||
val root = steamRoot()
|
||||
val file = store(root, "[]")
|
||||
SteamHidden.write(root, 1, true)
|
||||
SteamHidden.write(root, 2, true)
|
||||
assertEquals("""["user-collections.hidden"]""", File(file.parentFile, "cloud-storage-namespace-1.modified.json").readText())
|
||||
}
|
||||
|
||||
@Test fun aMalformedMemberIsRejectedAndTheFileIsLeftAlone() {
|
||||
val root = steamRoot()
|
||||
val json = """[["user-collections.hidden",{"key":"user-collections.hidden","value":"{\"id\":\"hidden\",\"added\":[\"x\"],\"removed\":[]}"}]]"""
|
||||
val file = store(root, json)
|
||||
assertEquals(emptySet<Long>(), SteamHidden.readOrNull(root))
|
||||
assertNull(SteamHidden.write(root, 1, true))
|
||||
assertEquals(json, file.readText())
|
||||
}
|
||||
|
||||
@Test fun numericStringsAreReadAndBadMembersAreSkipped() {
|
||||
val root = steamRoot()
|
||||
store(root, """[["user-collections.hidden",{"key":"user-collections.hidden","value":"{\"id\":\"hidden\",\"added\":[\"440\",\"x\",4.5,730],\"removed\":[]}"}]]""")
|
||||
assertEquals(setOf(440L, 730L), SteamHidden.read(root))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import com.droiddeck.launcher.frontend.Library
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class LibraryHiddenTest {
|
||||
private fun steam(id: Int, name: String) = LibraryEntry("app:$id", Library.SOURCE_STEAM, name, Library.SteamGame(id, name, null, "Steam library"), null, true)
|
||||
|
||||
private val tf2 = steam(440, "Team Fortress 2")
|
||||
private val cs = steam(10, "Counter-Strike")
|
||||
private val hiddenSet = setOf(tf2.favoriteKey)
|
||||
private val hidden: (LibraryEntry) -> Boolean = { it.favoriteKey in hiddenSet }
|
||||
|
||||
@Test fun hiddenGamesLeaveAllAndTheirStoreTab() {
|
||||
assertFalse(inLibrarySource(LIBRARY_ALL, tf2, emptySet(), hidden))
|
||||
assertFalse(inLibrarySource(Library.SOURCE_STEAM, tf2, emptySet(), hidden))
|
||||
assertTrue(inLibrarySource(LIBRARY_ALL, cs, emptySet(), hidden))
|
||||
assertTrue(inLibrarySource(Library.SOURCE_STEAM, cs, emptySet(), hidden))
|
||||
}
|
||||
|
||||
@Test fun hiddenGamesLeaveFavorites() {
|
||||
assertFalse(inLibrarySource(LIBRARY_FAVORITES, tf2, setOf(tf2.favoriteKey), hidden))
|
||||
}
|
||||
|
||||
@Test fun theHiddenSourceHoldsOnlyHiddenGames() {
|
||||
assertTrue(inLibrarySource(LIBRARY_HIDDEN, tf2, emptySet(), hidden))
|
||||
assertFalse(inLibrarySource(LIBRARY_HIDDEN, cs, emptySet(), hidden))
|
||||
}
|
||||
|
||||
@Test fun theHiddenTabIsLastAndOnlyWhenEnabled() {
|
||||
val entries = listOf(tf2, cs)
|
||||
assertEquals(listOf(Library.SOURCE_STEAM), librarySources(entries, emptyList(), hidden = hidden))
|
||||
assertEquals(listOf(Library.SOURCE_STEAM, LIBRARY_HIDDEN), librarySources(entries, emptyList(), hidden = hidden, showHidden = true))
|
||||
}
|
||||
|
||||
@Test fun aStoreTabWithOnlyHiddenGamesDisappears() {
|
||||
assertEquals(emptyList<String>(), librarySources(listOf(tf2), emptyList(), hidden = hidden))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user