mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 12:56:06 +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
@@ -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
|
||||
|
||||
Reference in new issue
Block a user