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:
FX1922 authored and GitHub committed 2026-11-18 07:38:34 -05:00
1 parent d89c2c1c2d
commit f1be935761
43 files changed
+459 -32

No files matched your search

@@ -222,16 +222,7 @@ object Library {
internal fun concealedSteamApps(root: File): Set<Long> {
val config = AddedGames.accountConfig(root) ?: return emptySet()
val hidden = runCatching {
val entries = org.json.JSONArray(File(config, "cloudstorage/cloud-storage-namespace-1.json").readText())
val entry = (0 until entries.length()).map { entries.getJSONArray(it) }
.firstOrNull { it.optString(0) == "user-collections.hidden" }?.optJSONObject(1)
if (entry == null || entry.optBoolean("is_deleted")) emptySet() else {
val collection = org.json.JSONObject(entry.optString("value"))
fun ids(key: String) = collection.optJSONArray(key)?.let { a -> (0 until a.length()).map { a.optLong(it) } }.orEmpty()
ids("added").toSet() - ids("removed").toSet()
}
}.getOrDefault(emptySet())
val hidden = SteamHidden.read(root)
val private = runCatching {
PRIVATE_APPS.find(File(config, "localconfig.vdf").readText())?.groupValues?.get(1)
?.split(',')?.mapNotNull { it.trim().toLongOrNull() }?.toSet()
@@ -0,0 +1,78 @@
package com.droiddeck.launcher.frontend
import org.json.JSONArray
import org.json.JSONObject
import java.io.File
internal object SteamHidden {
private const val KEY = "user-collections.hidden"
private fun file(root: File): File? = AddedGames.accountConfig(root)?.let { File(it, "cloudstorage/cloud-storage-namespace-1.json") }
class Saved(val hidden: Set<Long>, val queued: Boolean)
private fun id(member: Any?): Long? = when (member) {
is Int -> member.toLong()
is Long -> member
is String -> member.toLongOrNull()
else -> null
}
private fun ids(collection: JSONObject, key: String, strict: Boolean): List<Long> {
if (!collection.has(key)) return emptyList()
val array = collection.optJSONArray(key) ?: throw IllegalStateException(key)
return (0 until array.length()).mapNotNull { index ->
id(array.get(index)) ?: if (strict) throw IllegalStateException(key) else null
}
}
fun read(root: File): Set<Long> = readOrNull(root).orEmpty()
fun readOrNull(root: File): Set<Long>? = runCatching {
val entries = JSONArray(file(root)?.readText() ?: return null)
val slot = (0 until entries.length()).map { entries.getJSONArray(it) }.firstOrNull { it.optString(0) == KEY }
val entry = slot?.optJSONObject(1)
if (slot != null && entry == null) return null
if (entry == null || entry.optBoolean("is_deleted")) emptySet() else {
val collection = JSONObject(entry.optString("value"))
ids(collection, "added", false).toSet() - ids(collection, "removed", false).toSet()
}
}.getOrNull()
fun write(root: File, appId: Long, hidden: Boolean, now: Long = System.currentTimeMillis() / 1000): Saved? = runCatching {
val target = file(root) ?: return null
val entries = JSONArray(target.readText())
val slot = (0 until entries.length()).firstOrNull { entries.getJSONArray(it).optString(0) == KEY }
val entry = if (slot == null) JSONObject().put("key", KEY) else entries.getJSONArray(slot).optJSONObject(1) ?: return null
val live = !entry.optBoolean("is_deleted")
val collection = if (live && entry.has("value")) JSONObject(entry.optString("value")) else JSONObject().put("id", "hidden")
val added = ids(collection, "added", true).filter { it != appId }
val removed = ids(collection, "removed", true).filter { it != appId }
collection.put("added", JSONArray(if (hidden) added + appId else added))
collection.put("removed", JSONArray(if (hidden) removed else removed + appId))
entry.put("value", collection.toString())
entry.put("timestamp", now)
entry.put("is_deleted", false)
entry.opt("version")?.toString()?.toLongOrNull()?.let { entry.put("version", (it + 1).toString()) }
if (slot == null) entries.put(JSONArray().put(KEY).put(entry))
val temp = File(target.parentFile, target.name + ".tmp")
temp.writeText(entries.toString())
if (!temp.renameTo(target)) {
temp.delete()
return null
}
Saved(ids(collection, "added", true).toSet() - ids(collection, "removed", true).toSet(), markModified(File(target.parentFile, "cloud-storage-namespace-1.modified.json")))
}.getOrNull()
private fun markModified(file: File): Boolean {
val pending = if (file.exists()) runCatching { JSONArray(file.readText()) }.getOrNull() ?: return false else JSONArray()
if ((0 until pending.length()).any { pending.optString(it) == KEY }) return true
val temp = File(file.parentFile, file.name + ".tmp")
val saved = runCatching {
temp.writeText(pending.put(KEY).toString())
temp.renameTo(file)
}.getOrDefault(false)
if (!saved) temp.delete()
return saved
}
}
@@ -255,6 +255,18 @@ object SessionPrefs {
prefs(context).edit().putBoolean("libraryShowSize", show).apply()
}
fun libraryShowHidden(context: Context): Boolean = prefs(context).getBoolean("libraryShowHidden", false)
fun setLibraryShowHidden(context: Context, show: Boolean) {
prefs(context).edit().putBoolean("libraryShowHidden", show).apply()
}
fun libraryHidden(context: Context): Set<String> = prefs(context).getStringSet("libraryHidden", null)?.toSet().orEmpty()
fun setLibraryHidden(context: Context, keys: Set<String>) {
prefs(context).edit().putStringSet("libraryHidden", keys.toSet()).apply()
}
fun railLabels(context: Context): Boolean = prefs(context).getBoolean("railLabels", false)
fun setRailLabels(context: Context, show: Boolean) {
@@ -1,5 +1,6 @@
package com.droiddeck.launcher.ui
import android.widget.Toast
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.LocalIndication
import androidx.compose.ui.semantics.Role
@@ -466,7 +467,10 @@ internal fun GameActions(
}
SecondaryButton(stringResource(R.string.bnet_open)) { a.onBattleNet() }
}
if (game != null && !compactMenu) EditArtButton(game)
if (game != null && !compactMenu) {
HideButton(hideKey(game), game)
EditArtButton(game)
}
}
download != null -> {
ActionChip(downloadLabel(download), ok = false)
@@ -526,6 +530,8 @@ internal fun GameActions(
}
item != null -> PrimaryButton(buyLabel(item), main = true, modifier = leadOn) { openStoreUrl(ctx, item) }
}
val entryKey = game?.let(::hideKey) ?: storeKey
if (!s.shortcutPicker && entryKey != null && (game == null || cloud)) HideButton(entryKey, game)
if (cloud && (download != null || failed != null)) {
XboxStreamButton(game.storeId.orEmpty(), game.name)
XboxLibraryButton(game.storeId.orEmpty(), item)
@@ -618,6 +624,17 @@ internal fun rememberEditArt(g: Library.SteamGame): (() -> Unit)? {
}
}
internal fun hideKey(g: Library.SteamGame): String = g.storeId?.let { "${g.source}:$it" } ?: GameRef.key(g)
@Composable
internal fun HideButton(key: String, g: Library.SteamGame?) {
val ctx = LocalContext.current
rememberHiddenSync()
val hidden = LibraryHidden.isHidden(key, g)
val failed = stringResource(R.string.game_hide_failed)
SecondaryButton(stringResource(if (hidden) R.string.game_unhide else R.string.common_hide), compact = true) { if (!LibraryHidden.set(ctx, key, g, !hidden)) Toast.makeText(ctx, failed, Toast.LENGTH_LONG).show() }
}
@Composable
internal fun EditArtButton(g: Library.SteamGame) {
val open = rememberEditArt(g) ?: return
@@ -628,6 +645,10 @@ internal fun EditArtButton(g: Library.SteamGame) {
private fun GameMoreMenu(g: Library.SteamGame, a: FrontEndActions) {
var open by remember(g.gameId) { mutableStateOf(false) }
val edit = rememberEditArt(g)
val ctx = LocalContext.current
rememberHiddenSync()
val hidden = LibraryHidden.isHidden(hideKey(g), g)
val failed = stringResource(R.string.game_hide_failed)
Box {
SecondaryButton(stringResource(R.string.game_more)) { open = !open }
AnchoredMenu(open, onDismiss = { open = false }, title = stringResource(R.string.game_more), compact = true) { first ->
@@ -638,6 +659,8 @@ private fun GameMoreMenu(g: Library.SteamGame, a: FrontEndActions) {
MenuItem(stringResource(R.string.game_shortcut_add), checked = false, focusRequester = take()) { open = false; a.onGameShortcut(g) }
MenuItem(stringResource(R.string.game_file_export), checked = false) { open = false; a.onExportGameFile(g) }
MenuItem(stringResource(R.string.game_link_copy), checked = false) { open = false; a.onCopyGameLink(g) }
val hideKey = hideKey(g)
MenuItem(stringResource(if (hidden) R.string.game_unhide else R.string.common_hide), checked = false) { open = false; if (!LibraryHidden.set(ctx, hideKey, g, !hidden)) Toast.makeText(ctx, failed, Toast.LENGTH_LONG).show() }
edit?.let { run -> MenuItem(stringResource(R.string.game_edit_art), checked = false) { open = false; run() } }
}
}
@@ -28,8 +28,12 @@ internal object LibraryFavorites {
internal fun toggled(keys: Set<String>, key: String): Set<String> = if (key in keys) keys - key else keys + key
internal fun inLibrarySource(source: String, entry: LibraryEntry, favorites: Set<String>): Boolean = when (source) {
LIBRARY_ALL -> true
LIBRARY_FAVORITES -> entry.favoriteKey in favorites
else -> entry.source == source
internal fun inLibrarySource(source: String, entry: LibraryEntry, favorites: Set<String>, hidden: (LibraryEntry) -> Boolean = { false }): Boolean {
val concealed = hidden(entry)
return when (source) {
LIBRARY_HIDDEN -> concealed
LIBRARY_ALL -> !concealed
LIBRARY_FAVORITES -> !concealed && entry.favoriteKey in favorites
else -> !concealed && entry.source == source
}
}
@@ -0,0 +1,78 @@
package com.droiddeck.launcher.ui
import android.content.Context
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import com.droiddeck.launcher.frontend.AddedGames
import com.droiddeck.launcher.frontend.Library
import com.droiddeck.launcher.frontend.SteamHidden
import com.droiddeck.launcher.session.SessionPrefs
internal const val LIBRARY_HIDDEN = "hidden"
internal object LibraryHidden {
var keys by mutableStateOf<Set<String>>(emptySet())
private set
var account by mutableStateOf<java.io.File?>(null)
private set
var steam by mutableStateOf<Set<Long>>(emptySet())
private set
fun load(context: Context) {
keys = SessionPrefs.libraryHidden(context)
refreshSteam(context)
}
fun refreshSteam(context: Context) {
val root = SessionPrefs.activeSteamRoot(context)
adopt(root)
SteamHidden.readOrNull(root)?.let { steam = it }
}
private fun adopt(root: java.io.File) {
val resolved = AddedGames.accountConfig(root)
if (resolved != account) {
account = resolved
steam = emptySet()
}
}
fun steamId(game: Library.SteamGame?): Long? = game?.takeIf { Library.fromSteamClient(it) }?.appId?.toLong()
fun isHidden(key: String, game: Library.SteamGame?): Boolean = key in keys || steamId(game)?.let { it in steam } == true
fun isHidden(entry: LibraryEntry): Boolean = isHidden(entry.favoriteKey, entry.game)
fun set(context: Context, key: String, game: Library.SteamGame?, hidden: Boolean): Boolean {
val id = steamId(game)
val root = SessionPrefs.activeSteamRoot(context)
val written = id?.let { SteamHidden.write(root, it, hidden) }
if (id != null) {
adopt(root)
steam = written?.hidden ?: SteamHidden.readOrNull(root) ?: steam
}
keys = if (hidden && (id == null || written == null)) keys + key else keys - key
SessionPrefs.setLibraryHidden(context, keys)
return id == null || written?.queued == true
}
}
@Composable
internal fun rememberHiddenSync() {
val ctx = LocalContext.current
remember { LibraryHidden.load(ctx) }
val lifecycle = LocalLifecycleOwner.current.lifecycle
DisposableEffect(lifecycle) {
val observer = LifecycleEventObserver { _, event -> if (event == Lifecycle.Event.ON_RESUME) LibraryHidden.refreshSteam(ctx) }
lifecycle.addObserver(observer)
onDispose { lifecycle.removeObserver(observer) }
}
}
@@ -163,11 +163,17 @@ internal fun collectionEntries(all: List<LibraryEntry>, items: List<CatalogItem>
internal fun installedFirst(entries: List<LibraryEntry>): List<LibraryEntry> = entries.partition { it.installed }.let { (on, off) -> on + off }
internal const val LIBRARY_ALL = "all"
internal fun librarySources(entries: List<LibraryEntry>, order: List<String>, always: Set<String> = emptySet(), favorites: Set<String> = emptySet()): List<String> =
(listOf(LIBRARY_FAVORITES, Library.SOURCE_STEAM) + arrangeStoreTabs(order, emptySet()).map { it.store.id } + Library.ADDED + Library.SOURCE_COLLECTION)
internal fun librarySources(
entries: List<LibraryEntry>, order: List<String>, always: Set<String> = emptySet(), favorites: Set<String> = emptySet(),
hidden: (LibraryEntry) -> Boolean = { false }, showHidden: Boolean = false,
): List<String> =
(listOf(LIBRARY_FAVORITES, Library.SOURCE_STEAM) + arrangeStoreTabs(order, emptySet()).map { it.store.id } + Library.ADDED + Library.SOURCE_COLLECTION + LIBRARY_HIDDEN)
.filter { source ->
if (source == LIBRARY_FAVORITES) entries.any { it.favoriteKey in favorites }
else source in always || entries.any { it.source == source }
when (source) {
LIBRARY_HIDDEN -> showHidden
LIBRARY_FAVORITES -> entries.any { it.favoriteKey in favorites && !hidden(it) }
else -> source in always || entries.any { it.source == source && !hidden(it) }
}
}
internal object LibraryDisplay {
@@ -178,11 +184,14 @@ internal object LibraryDisplay {
private set
var size by mutableStateOf(true)
private set
var hidden by mutableStateOf(false)
private set
fun load(context: android.content.Context) {
level = SessionPrefs.libraryCardLevel(context).coerceIn(0, scales.lastIndex)
title = SessionPrefs.libraryShowTitle(context)
size = SessionPrefs.libraryShowSize(context)
hidden = SessionPrefs.libraryShowHidden(context)
}
fun step(context: android.content.Context, by: Int) {
@@ -199,6 +208,11 @@ internal object LibraryDisplay {
size = !size
SessionPrefs.setLibraryShowSize(context, size)
}
fun toggleHidden(context: android.content.Context) {
hidden = !hidden
SessionPrefs.setLibraryShowHidden(context, hidden)
}
}
internal object LibraryView {
@@ -228,8 +242,10 @@ internal fun LibraryPage(s: FrontEndState, a: FrontEndActions, selected: String,
remember { LibraryDisplay.load(ctx) }
remember { FolderSizes.load(ctx) }
remember { LibraryFavorites.load(ctx) }
rememberHiddenSync()
val soundMode = selected == "soundtracks" || selected.startsWith("sound:")
val favorites = if (soundMode) emptySet() else LibraryFavorites.keys
val concealed: (LibraryEntry) -> Boolean = { !soundMode && LibraryHidden.isHidden(it) }
val stores = !s.shortcutPicker && !soundMode
val signedIn = Store.entries.filter { StoresState.isSignedIn(it) }
LaunchedEffect(stores, signedIn) { if (stores) signedIn.forEach { StoresState.loadLibrary(ctx, it) } }
@@ -267,7 +283,7 @@ internal fun LibraryPage(s: FrontEndState, a: FrontEndActions, selected: String,
val sources = librarySources(
all, SessionPrefs.storesTabOrder(ctx),
listOfNotNull(Store.ITCH.id.takeIf { itchSignedIn && !soundMode }, Store.GAMEJOLT.id.takeIf { gameJoltSignedIn && !soundMode }, Library.SOURCE_COLLECTION.takeIf { soundMode }).toSet(),
favorites,
favorites, concealed, LibraryDisplay.hidden && !soundMode,
)
val source = LibraryView.source.takeIf { it == LIBRARY_ALL || it in sources } ?: LIBRARY_ALL
val q = LibraryView.query.trim().lowercase()
@@ -290,7 +306,7 @@ internal fun LibraryPage(s: FrontEndState, a: FrontEndActions, selected: String,
val collectionItems = collectionId?.let { if (source == Store.GAMEJOLT.id) GameJoltCollections.gamesOf(it) else ItchCollections.gamesOf(it) }
val pool = if (collectionId == null) all else collectionEntries(all, collectionItems.orEmpty(), Store.byId(source) ?: Store.ITCH)
val matching = pool.filter {
inLibrarySource(source, it, favorites) && (q.isEmpty() || it.title.lowercase().contains(q)) && keepsXbox(xboxFilter, it)
inLibrarySource(source, it, favorites, concealed) && (q.isEmpty() || it.title.lowercase().contains(q)) && keepsXbox(xboxFilter, it)
}
val listUninstalled = if (collectionId == null) showUninstalled else collectionShows?.takeIf { it.first == collectionId }?.second ?: true
val trackHits by produceState<List<SoundtrackIndex.Hit>>(emptyList(), soundMode, q, source, s.soundtracks) {
@@ -317,8 +333,8 @@ internal fun LibraryPage(s: FrontEndState, a: FrontEndActions, selected: String,
}
}
var savedDialog by remember { mutableStateOf(false) }
val candidates = if (listUninstalled) matching else matching.filter { it.installed }
val hiddenUninstalled = if (listUninstalled) 0 else matching.count { !it.installed }
val candidates = if (listUninstalled || source == LIBRARY_HIDDEN) matching else matching.filter { it.installed }
val hiddenUninstalled = if (listUninstalled || source == LIBRARY_HIDDEN) 0 else matching.count { !it.installed }
val sort = s.storesSort
val sizeSort = sort == "sizeAsc" || sort == "sizeDesc"
val installedAt = StoresState.installed.associate { it.key to it.sidecar.installedAt }
@@ -539,7 +555,7 @@ private fun LibraryGrid(
}
val picker = s.shortcutPicker && e.game != null
val choose = if (picker) ({ a.onSteamGame(e.game!!) }) else null
if (listMode) LibraryRow(e, first, navigation, choose, onOpen) else LibraryTile(e, capsules, first, navigation, choose, onOpen, showSource = source == LIBRARY_ALL || source == LIBRARY_FAVORITES)
if (listMode) LibraryRow(e, first, navigation, choose, onOpen) else LibraryTile(e, capsules, first, navigation, choose, onOpen, showSource = source == LIBRARY_ALL || source == LIBRARY_FAVORITES || source == LIBRARY_HIDDEN)
}
LazyVerticalGrid(
columns = if (listMode) GridCells.Fixed(1) else GridCells.Adaptive(tileWidth), state = grid,
@@ -679,17 +695,19 @@ private fun LibraryHeader(
@Composable
private fun LibraryFilters(sources: List<String>, source: String, onSource: (String) -> Unit, accounts: Boolean) {
if (sources.size < 2 && !accounts) return
val chips = sources.size >= 2 || sources.singleOrNull() == LIBRARY_HIDDEN
if (!chips && !accounts) return
Row(
horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth().padding(top = 4.dp, bottom = 2.dp).horizontalScroll(rememberScrollState()),
) {
if (sources.size >= 2) SourceFilterChip(LIBRARY_ALL, stringResource(R.string.stores_tab_all), source == LIBRARY_ALL, dot = null) { onSource(LIBRARY_ALL) }
if (sources.size >= 2) for (src in sources) {
if (chips) SourceFilterChip(LIBRARY_ALL, stringResource(R.string.stores_tab_all), source == LIBRARY_ALL, dot = null) { onSource(LIBRARY_ALL) }
if (chips) for (src in sources) {
val store = Store.byId(src)
val dot = when {
store != null -> sourceColours(src).dot.copy(alpha = if (StoresState.isSignedIn(store) && StoresState.expired[store] != true) 1f else 0.35f)
src == LIBRARY_FAVORITES -> FavoritesColours.dot
src == LIBRARY_HIDDEN -> Color(0xFF9AA0A6)
src == Library.SOURCE_STEAM || src == Library.ADDED || src == Library.SOURCE_COLLECTION -> sourceColours(src).dot
else -> null
}
@@ -698,6 +716,7 @@ private fun LibraryFilters(sources: List<String>, source: String, onSource: (Str
when (src) {
Library.ADDED -> stringResource(R.string.library_filter_added)
LIBRARY_FAVORITES -> stringResource(R.string.soundtracks_favorites)
LIBRARY_HIDDEN -> stringResource(R.string.apps_filter_hidden)
else -> store?.shortLabel ?: sourceLabel(src)
},
source == src, dot,
@@ -1058,7 +1077,7 @@ internal fun DisplayButton() {
HeaderIconButton(title, Icons.Filled.Visibility, "display") {
val from = at ?: return@HeaderIconButton
Steps.ask(StepAsk(
anchor = from, side = StepSide.Left, accent = pal.signal, pillCorner = 8.dp, items = 4,
anchor = from, side = StepSide.Left, accent = pal.signal, pillCorner = 8.dp, items = 5,
handle = { Icon(Icons.Filled.Visibility, null, tint = pal.signal, modifier = Modifier.size(18.dp)) },
) {
StepTitle(title)
@@ -1081,6 +1100,10 @@ internal fun DisplayButton() {
stringResource(R.string.library_display_size), selected = LibraryDisplay.size, enabled = open,
modifier = Modifier.fillMaxWidth().stepItem(3),
) { LibraryDisplay.toggleSize(ctx) }
StepChoice(
stringResource(R.string.apps_filter_hidden), selected = LibraryDisplay.hidden, enabled = open,
modifier = Modifier.fillMaxWidth().stepItem(4),
) { LibraryDisplay.toggleHidden(ctx) }
}
})
}
@@ -83,12 +83,21 @@ private const val DRIFT_STEP_NS = 15_000_000L
internal fun SteamHome(s: FrontEndState, a: FrontEndActions, modifier: Modifier) {
val ctx = androidx.compose.ui.platform.LocalContext.current
LaunchedEffect(Unit) { com.droiddeck.launcher.frontend.SteamFeatured.load(ctx) }
val featured = com.droiddeck.launcher.frontend.SteamFeatured.games
rememberHiddenSync()
val featuredAll = com.droiddeck.launcher.frontend.SteamFeatured.games
val signedIn = s.offlineAccount != null
val owned by produceState(emptyList<Pair<Int, java.io.File>>(), signedIn) {
value = if (!signedIn) emptyList() else withContext(Dispatchers.IO) { runCatching { Library.steamLibraryArt(ctx).shuffled() }.getOrDefault(emptyList()) }
val account = LibraryHidden.account
val scanned by produceState<Pair<java.io.File?, List<Pair<Int, java.io.File>>>>(account to emptyList(), signedIn, LibraryHidden.steam, account) {
val art = if (!signedIn) emptyList() else withContext(Dispatchers.IO) { runCatching { Library.steamLibraryArt(ctx).shuffled() }.getOrDefault(emptyList()) }
value = account to art
}
val games = remember(s.steamGames) { s.steamGames.sortedWith(compareByDescending<Library.SteamGame> { it.lastPlayed }.thenBy { it.gameId }) }
val ownedAll = if (scanned.first == account) scanned.second else emptyList()
val concealed = remember(s.steamGames, LibraryHidden.keys, LibraryHidden.steam) {
LibraryHidden.steam + s.steamGames.filter { LibraryHidden.isHidden(hideKey(it), it) }.map { it.appId.toLong() }
}
val owned = remember(ownedAll, concealed) { ownedAll.filter { it.first.toLong() !in concealed } }
val featured = remember(featuredAll, concealed) { featuredAll.filter { it.appId.toLong() !in concealed } }
val games = remember(s.steamGames, LibraryHidden.keys, LibraryHidden.steam) { s.steamGames.filterNot { LibraryHidden.isHidden(hideKey(it), it) }.sortedWith(compareByDescending<Library.SteamGame> { it.lastPlayed }.thenBy { it.gameId }) }
val narrow = LocalNarrowPane.current
var words by remember { mutableStateOf<Rect?>(null) }
val mode = com.droiddeck.launcher.session.SessionService.MODE_STEAM
+2
View File
@@ -1605,6 +1605,8 @@
<string name="pip_unavailable">تعذّر على Android فتح نافذة ضمن النافذة.</string>
<string name="game_more">المزيد</string>
<string name="game_edit_art">تعديل الصور</string>
<string name="game_unhide">إزالة من المخفية</string>
<string name="game_hide_failed">تعذّرت المزامنة مع Steam. أغلق Steam وحاول مرة أخرى.</string>
<string name="stores_in_steam_label">في Steam</string>
<string name="game_shortcut">اختصار</string>
<string name="game_shortcut_add">إضافة إلى الشاشة الرئيسية</string>
@@ -1651,6 +1651,8 @@
<string name="pip_unavailable">Android no pudo abrir imagen en imagen.</string>
<string name="game_more">Más</string>
<string name="game_edit_art">Editar imágenes</string>
<string name="game_unhide">Quitar de ocultas</string>
<string name="game_hide_failed">No se pudo sincronizar con Steam. Cierra Steam e inténtalo de nuevo.</string>
<string name="stores_in_steam_label">En Steam</string>
<string name="game_shortcut">Acceso directo</string>
<string name="game_shortcut_add">Agregar a la pantalla de inicio</string>
+2
View File
@@ -1573,6 +1573,8 @@
<string name="pip_unavailable">Android не можа да отвори картина в картината.</string>
<string name="game_more">Още</string>
<string name="game_edit_art">Редактиране на изображенията</string>
<string name="game_unhide">Премахване от скритите</string>
<string name="game_hide_failed">Синхронизирането със Steam не успя. Затворете Steam и опитайте отново.</string>
<string name="stores_in_steam_label">В Steam</string>
<string name="game_shortcut">Пряк път</string>
<string name="game_shortcut_add">Добавяне към началния екран</string>
+2
View File
@@ -1589,6 +1589,8 @@
<string name="pip_unavailable">Android nemohl otevřít obraz v obraze.</string>
<string name="game_more">Další</string>
<string name="game_edit_art">Upravit grafiku</string>
<string name="game_unhide">Odebrat ze skrytých</string>
<string name="game_hide_failed">Synchronizace se Steamem se nezdařila. Zavřete Steam a zkuste to znovu.</string>
<string name="stores_in_steam_label">Ve Steamu</string>
<string name="game_shortcut">Zkratka</string>
<string name="game_shortcut_add">Přidat na domovskou obrazovku</string>
+2
View File
@@ -1573,6 +1573,8 @@
<string name="pip_unavailable">Android kunne ikke åbne billede i billede.</string>
<string name="game_more">Mere</string>
<string name="game_edit_art">Rediger grafik</string>
<string name="game_unhide">Fjern fra skjulte</string>
<string name="game_hide_failed">Kunne ikke synkronisere med Steam. Luk Steam og prøv igen.</string>
<string name="stores_in_steam_label">I Steam</string>
<string name="game_shortcut">Genvej</string>
<string name="game_shortcut_add">Tilføj til hjemmeskærm</string>
+2
View File
@@ -1565,6 +1565,8 @@
<string name="pip_unavailable">Android konnte Bild im Bild nicht öffnen.</string>
<string name="game_more">Mehr</string>
<string name="game_edit_art">Grafiken bearbeiten</string>
<string name="game_unhide">Nicht mehr ausblenden</string>
<string name="game_hide_failed">Synchronisierung mit Steam fehlgeschlagen. Schließe Steam und versuche es erneut.</string>
<string name="stores_in_steam_label">In Steam</string>
<string name="game_shortcut">Verknüpfung</string>
<string name="game_shortcut_add">Zum Startbildschirm hinzufügen</string>
+2
View File
@@ -1573,6 +1573,8 @@
<string name="pip_unavailable">Το Android δεν μπόρεσε να ανοίξει τη λειτουργία εικόνας εντός εικόνας.</string>
<string name="game_more">Περισσότερα</string>
<string name="game_edit_art">Επεξεργασία εικαστικών</string>
<string name="game_unhide">Κατάργηση από τις κρυφές</string>
<string name="game_hide_failed">Αποτυχία συγχρονισμού με το Steam. Κλείστε το Steam και δοκιμάστε ξανά.</string>
<string name="stores_in_steam_label">Στο Steam</string>
<string name="game_shortcut">Συντόμευση</string>
<string name="game_shortcut_add">Προσθήκη στην αρχική οθόνη</string>
+2
View File
@@ -1581,6 +1581,8 @@
<string name="pip_unavailable">Android no pudo abrir imagen en imagen.</string>
<string name="game_more">Más</string>
<string name="game_edit_art">Editar imágenes</string>
<string name="game_unhide">Quitar de ocultas</string>
<string name="game_hide_failed">No se pudo sincronizar con Steam. Cierra Steam e inténtalo de nuevo.</string>
<string name="stores_in_steam_label">En Steam</string>
<string name="game_shortcut">Acceso directo</string>
<string name="game_shortcut_add">Añadir a la pantalla de inicio</string>
+2
View File
@@ -1573,6 +1573,8 @@
<string name="pip_unavailable">Android ei pystynyt avaamaan kuva kuvassa -tilaa.</string>
<string name="game_more">Lisää</string>
<string name="game_edit_art">Muokkaa kuvitusta</string>
<string name="game_unhide">Poista piilotetuista</string>
<string name="game_hide_failed">Synkronointi Steamin kanssa epäonnistui. Sulje Steam ja yritä uudelleen.</string>
<string name="stores_in_steam_label">Steamissa</string>
<string name="game_shortcut">Pikakuvake</string>
<string name="game_shortcut_add">Lisää aloitusnäytölle</string>
+2
View File
@@ -1580,6 +1580,8 @@
<string name="pip_unavailable">Android ne peut pas ouvrir le mode PiP.</string>
<string name="game_more">Plus</string>
<string name="game_edit_art">Modifier les illustrations</string>
<string name="game_unhide">Ne plus masquer</string>
<string name="game_hide_failed">Synchronisation avec Steam impossible. Fermez Steam et réessayez.</string>
<string name="stores_in_steam_label">Dans Steam</string>
<string name="game_shortcut">Raccourci</string>
<string name="game_shortcut_add">Ajouter à l\'écran d\'accueil</string>
+2
View File
@@ -1573,6 +1573,8 @@
<string name="pip_unavailable">Android पिक्चर इन पिक्चर नहीं खोल सका।</string>
<string name="game_more">और</string>
<string name="game_edit_art">आर्ट एडिट करें</string>
<string name="game_unhide">छिपे हुए से हटाएं</string>
<string name="game_hide_failed">Steam के साथ सिंक नहीं हो सका। Steam बंद करके फिर कोशिश करें।</string>
<string name="stores_in_steam_label">Steam में</string>
<string name="game_shortcut">शॉर्टकट</string>
<string name="game_shortcut_add">होम स्क्रीन पर जोड़ें</string>
+2
View File
@@ -1573,6 +1573,8 @@
<string name="pip_unavailable">Az Android nem tudta megnyitni a kép a képben módot.</string>
<string name="game_more">Továbbiak</string>
<string name="game_edit_art">Illusztrációk szerkesztése</string>
<string name="game_unhide">Eltávolítás a rejtettek közül</string>
<string name="game_hide_failed">Nem sikerült szinkronizálni a Steammel. Zárd be a Steamet, és próbáld újra.</string>
<string name="stores_in_steam_label">A Steamben</string>
<string name="game_shortcut">Parancsikon</string>
<string name="game_shortcut_add">Hozzáadás a kezdőképernyőhöz</string>
+2
View File
@@ -1566,6 +1566,8 @@
<string name="pip_unavailable">Android tidak dapat membuka gambar dalam gambar.</string>
<string name="game_more">Lainnya</string>
<string name="game_edit_art">Edit gambar</string>
<string name="game_unhide">Hapus dari tersembunyi</string>
<string name="game_hide_failed">Gagal menyinkronkan dengan Steam. Tutup Steam lalu coba lagi.</string>
<string name="stores_in_steam_label">Di Steam</string>
<string name="game_shortcut">Pintasan</string>
<string name="game_shortcut_add">Tambahkan ke layar utama</string>
+2
View File
@@ -1572,6 +1572,8 @@
<string name="pip_unavailable">Android non è riuscito ad aprire il picture in picture.</string>
<string name="game_more">Altro</string>
<string name="game_edit_art">Modifica grafica</string>
<string name="game_unhide">Rimuovi dai nascosti</string>
<string name="game_hide_failed">Impossibile sincronizzare con Steam. Chiudi Steam e riprova.</string>
<string name="stores_in_steam_label">In Steam</string>
<string name="game_shortcut">Scorciatoia</string>
<string name="game_shortcut_add">Aggiungi alla schermata Home</string>
+2
View File
@@ -1566,6 +1566,8 @@
<string name="pip_unavailable">Androidがピクチャーインピクチャーを開けませんでした。</string>
<string name="game_more">その他</string>
<string name="game_edit_art">アートを編集</string>
<string name="game_unhide">非表示を解除</string>
<string name="game_hide_failed">Steamと同期できませんでした。Steamを終了してもう一度お試しください。</string>
<string name="stores_in_steam_label">Steamに追加済み</string>
<string name="game_shortcut">ショートカット</string>
<string name="game_shortcut_add">ホーム画面に追加</string>
+2
View File
@@ -1566,6 +1566,8 @@
<string name="pip_unavailable">Android에서 PIP를 열 수 없습니다.</string>
<string name="game_more">더보기</string>
<string name="game_edit_art">아트 편집</string>
<string name="game_unhide">숨김 해제</string>
<string name="game_hide_failed">Steam과 동기화하지 못했습니다. Steam을 종료한 후 다시 시도하세요.</string>
<string name="stores_in_steam_label">Steam에 있음</string>
<string name="game_shortcut">바로 가기</string>
<string name="game_shortcut_add">홈 화면에 추가</string>
+2
View File
@@ -1566,6 +1566,8 @@
<string name="pip_unavailable">Android tidak dapat membuka gambar dalam gambar.</string>
<string name="game_more">Lagi</string>
<string name="game_edit_art">Sunting seni</string>
<string name="game_unhide">Alih keluar daripada tersembunyi</string>
<string name="game_hide_failed">Tidak dapat menyegerak dengan Steam. Tutup Steam dan cuba lagi.</string>
<string name="stores_in_steam_label">Dalam Steam</string>
<string name="game_shortcut">Pintasan</string>
<string name="game_shortcut_add">Tambah ke skrin utama</string>
+2
View File
@@ -1573,6 +1573,8 @@
<string name="pip_unavailable">Android kunne ikke åpne bilde-i-bilde.</string>
<string name="game_more">Mer</string>
<string name="game_edit_art">Rediger grafikk</string>
<string name="game_unhide">Fjern fra skjulte</string>
<string name="game_hide_failed">Kunne ikke synkronisere med Steam. Lukk Steam og prøv igjen.</string>
<string name="stores_in_steam_label">I Steam</string>
<string name="game_shortcut">Snarvei</string>
<string name="game_shortcut_add">Legg til på hjem-skjermen</string>
+2
View File
@@ -1573,6 +1573,8 @@
<string name="pip_unavailable">Android kon scherm-in-scherm niet openen.</string>
<string name="game_more">Meer</string>
<string name="game_edit_art">Afbeeldingen bewerken</string>
<string name="game_unhide">Niet meer verbergen</string>
<string name="game_hide_failed">Synchroniseren met Steam is mislukt. Sluit Steam en probeer het opnieuw.</string>
<string name="stores_in_steam_label">In Steam</string>
<string name="game_shortcut">Snelkoppeling</string>
<string name="game_shortcut_add">Toevoegen aan startscherm</string>
+2
View File
@@ -1589,6 +1589,8 @@
<string name="pip_unavailable">Android nie mógł otworzyć obrazu w obrazie.</string>
<string name="game_more">Więcej</string>
<string name="game_edit_art">Edytuj grafiki</string>
<string name="game_unhide">Usuń z ukrytych</string>
<string name="game_hide_failed">Nie udało się zsynchronizować ze Steamem. Zamknij Steama i spróbuj ponownie.</string>
<string name="stores_in_steam_label">W Steam</string>
<string name="game_shortcut">Skrót</string>
<string name="game_shortcut_add">Dodaj do ekranu głównego</string>
@@ -1572,6 +1572,8 @@
<string name="pip_unavailable">O Android não conseguiu abrir o ecrã no ecrã.</string>
<string name="game_more">Mais</string>
<string name="game_edit_art">Editar imagens</string>
<string name="game_unhide">Remover dos ocultos</string>
<string name="game_hide_failed">Não foi possível sincronizar com o Steam. Feche o Steam e tente novamente.</string>
<string name="stores_in_steam_label">No Steam</string>
<string name="game_shortcut">Atalho</string>
<string name="game_shortcut_add">Adicionar ao ecrã principal</string>
+2
View File
@@ -1580,6 +1580,8 @@
<string name="pip_unavailable">O Android não conseguiu abrir o picture-in-picture.</string>
<string name="game_more">Mais</string>
<string name="game_edit_art">Editar artes</string>
<string name="game_unhide">Remover dos ocultos</string>
<string name="game_hide_failed">Não foi possível sincronizar com o Steam. Feche o Steam e tente novamente.</string>
<string name="stores_in_steam_label">Na Steam</string>
<string name="game_shortcut">Atalho</string>
<string name="game_shortcut_add">Adicionar à tela inicial</string>
+2
View File
@@ -1581,6 +1581,8 @@
<string name="pip_unavailable">Android nu a putut deschide imaginea în imagine.</string>
<string name="game_more">Mai multe</string>
<string name="game_edit_art">Editează grafica</string>
<string name="game_unhide">Elimină din ascunse</string>
<string name="game_hide_failed">Nu s-a putut sincroniza cu Steam. Închide Steam și încearcă din nou.</string>
<string name="stores_in_steam_label">În Steam</string>
<string name="game_shortcut">Comandă rapidă</string>
<string name="game_shortcut_add">Adaugă pe ecranul principal</string>
+2
View File
@@ -1589,6 +1589,8 @@
<string name="pip_unavailable">Android не может открыть PiP.</string>
<string name="game_more">Ещё</string>
<string name="game_edit_art">Изменить обложку</string>
<string name="game_unhide">Убрать из скрытых</string>
<string name="game_hide_failed">Не удалось синхронизировать со Steam. Закройте Steam и повторите попытку.</string>
<string name="stores_in_steam_label">В Steam</string>
<string name="game_shortcut">Ярлык</string>
<string name="game_shortcut_add">Добавить на главный экран</string>
+2
View File
@@ -1573,6 +1573,8 @@
<string name="pip_unavailable">Android kunde inte öppna bild-i-bild.</string>
<string name="game_more">Mer</string>
<string name="game_edit_art">Redigera grafik</string>
<string name="game_unhide">Ta bort från dolda</string>
<string name="game_hide_failed">Kunde inte synkronisera med Steam. Stäng Steam och försök igen.</string>
<string name="stores_in_steam_label">I Steam</string>
<string name="game_shortcut">Genväg</string>
<string name="game_shortcut_add">Lägg till på hemskärmen</string>
+2
View File
@@ -1566,6 +1566,8 @@
<string name="pip_unavailable">Android ไม่สามารถเปิดภาพซ้อนภาพได้</string>
<string name="game_more">เพิ่มเติม</string>
<string name="game_edit_art">แก้ไขภาพปก</string>
<string name="game_unhide">นำออกจากที่ซ่อนไว้</string>
<string name="game_hide_failed">ซิงค์กับ Steam ไม่สำเร็จ ปิด Steam แล้วลองอีกครั้ง</string>
<string name="stores_in_steam_label">ใน Steam</string>
<string name="game_shortcut">ช็อตคัต</string>
<string name="game_shortcut_add">เพิ่มไปยังหน้าจอหลัก</string>
+2
View File
@@ -1565,6 +1565,8 @@
<string name="pip_unavailable">Android, pencere içinde pencereyi açamadı.</string>
<string name="game_more">Diğer</string>
<string name="game_edit_art">Görseli düzenle</string>
<string name="game_unhide">Gizlilikten çıkar</string>
<string name="game_hide_failed">Steam ile senkronize edilemedi. Steam\'i kapatıp tekrar deneyin.</string>
<string name="stores_in_steam_label">Steam\'de</string>
<string name="game_shortcut">Kısayol</string>
<string name="game_shortcut_add">Ana ekrana ekle</string>
+2
View File
@@ -1589,6 +1589,8 @@
<string name="pip_unavailable">Android не вдалося відкрити режим «Картинка в картинці».</string>
<string name="game_more">Більше</string>
<string name="game_edit_art">Змінити обкладинку</string>
<string name="game_unhide">Прибрати з прихованих</string>
<string name="game_hide_failed">Не вдалося синхронізувати зі Steam. Закрийте Steam і спробуйте ще раз.</string>
<string name="stores_in_steam_label">У Steam</string>
<string name="game_shortcut">Ярлик</string>
<string name="game_shortcut_add">Додати на головний екран</string>
+2
View File
@@ -1566,6 +1566,8 @@
<string name="pip_unavailable">Android không thể mở hình trong hình.</string>
<string name="game_more">Thêm</string>
<string name="game_edit_art">Sửa ảnh bìa</string>
<string name="game_unhide">Bỏ ẩn</string>
<string name="game_hide_failed">Không thể đồng bộ với Steam. Hãy đóng Steam rồi thử lại.</string>
<string name="stores_in_steam_label">Trong Steam</string>
<string name="game_shortcut">Shortcut</string>
<string name="game_shortcut_add">Thêm vào màn hình chính</string>
@@ -1649,6 +1649,8 @@
<string name="pip_unavailable">Android 无法打开画中画。</string>
<string name="game_more">更多</string>
<string name="game_edit_art">编辑封面</string>
<string name="game_unhide">取消隐藏</string>
<string name="game_hide_failed">无法与 Steam 同步。请关闭 Steam 后重试。</string>
<string name="stores_in_steam_label">已在 Steam 中</string>
<string name="game_shortcut">快捷方式</string>
<string name="game_shortcut_add">添加到主屏幕</string>
@@ -1565,6 +1565,8 @@
<string name="pip_unavailable">Android 無法開啟畫中畫。</string>
<string name="game_more">更多</string>
<string name="game_edit_art">編輯圖片</string>
<string name="game_unhide">取消隱藏</string>
<string name="game_hide_failed">無法與 Steam 同步。請關閉 Steam 後再試。</string>
<string name="stores_in_steam_label">在 Steam 中</string>
<string name="game_shortcut">捷徑</string>
<string name="game_shortcut_add">加至主畫面</string>
@@ -1565,6 +1565,8 @@
<string name="pip_unavailable">Android 無法開啟子母畫面。</string>
<string name="game_more">更多</string>
<string name="game_edit_art">編輯圖片</string>
<string name="game_unhide">取消隱藏</string>
<string name="game_hide_failed">無法與 Steam 同步。請關閉 Steam 後再試。</string>
<string name="stores_in_steam_label">在 Steam 中</string>
<string name="game_shortcut">捷徑</string>
<string name="game_shortcut_add">新增至主螢幕</string>
+2
View File
@@ -1757,6 +1757,8 @@
<string name="pip_unavailable">Android could not open picture in picture.</string>
<string name="game_more">More</string>
<string name="game_edit_art">Edit art</string>
<string name="game_unhide">Remove hidden</string>
<string name="game_hide_failed">Couldn\'t sync with Steam. Close Steam and try again.</string>
<string name="stores_in_steam_label">In Steam</string>
<string name="game_shortcut">Shortcut</string>
<string name="game_shortcut_add">Add to home screen</string>
@@ -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))
}
}