diff --git a/app/src/main/java/com/droiddeck/launcher/frontend/Library.kt b/app/src/main/java/com/droiddeck/launcher/frontend/Library.kt index 1fd87f97d2..44c7c80737 100644 --- a/app/src/main/java/com/droiddeck/launcher/frontend/Library.kt +++ b/app/src/main/java/com/droiddeck/launcher/frontend/Library.kt @@ -128,6 +128,14 @@ object Library { return out.values.toList() } + fun steamLibraryArt(context: Context): List> { + val cache = File(LinuxRuntime.rootDir(context), "root/.local/share/Steam/appcache/librarycache") + return cache.listFiles().orEmpty().mapNotNull { dir -> + val appId = dir.name.toIntOrNull()?.takeIf { it !in NOT_GAMES } ?: return@mapNotNull null + steamCacheImage(cache, appId, STEAM_CAPSULES)?.let { appId to it } + } + } + fun launchableGames(context: Context, strictRead: Boolean = false, added: List? = null): List { val roots = steamLibraries(context).map { it.first } return (steamGames(context, strictRead) + (added ?: AddedGames.scan(context)).map { g -> addedGame(context, g, roots) }).distinctBy { it.gameId } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/SteamHome.kt b/app/src/main/java/com/droiddeck/launcher/ui/SteamHome.kt index c3c5db6c2e..8851330c53 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/SteamHome.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/SteamHome.kt @@ -32,6 +32,7 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.produceState import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.geometry.Rect @@ -66,6 +67,8 @@ import coil.request.ImageRequest import coil.size.Scale import coil.transform.RoundedCornersTransformation import kotlin.math.roundToInt +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext private const val WALL_MIN_GAMES = 4 private const val WALL_DISTINCT = 40 @@ -77,6 +80,10 @@ 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 + val signedIn = s.offlineAccount != null + val owned by produceState(emptyList>(), signedIn) { + value = if (!signedIn) emptyList() else withContext(Dispatchers.IO) { runCatching { Library.steamLibraryArt(ctx).shuffled() }.getOrDefault(emptyList()) } + } val games = remember(s.steamGames) { s.steamGames.sortedWith(compareByDescending { it.lastPlayed }.thenBy { it.gameId }) } val narrow = LocalNarrowPane.current var words by remember { mutableStateOf(null) } @@ -106,10 +113,10 @@ internal fun SteamHome(s: FrontEndState, a: FrontEndActions, modifier: Modifier) when { games.isEmpty() -> EmptyLibrary( avoid = words, - wall = if (featured.isEmpty()) null else { { CapsuleWall(emptyList(), featured = featured) } }, + wall = if (owned.isEmpty() && featured.isEmpty()) null else { { CapsuleWall(emptyList(), owned = owned, featured = featured) } }, ) { Box(Modifier.fillMaxSize().graphicsLayer { scaleX = 1.06f; scaleY = 1.06f }) { WallFade() } } games.size < WALL_MIN_GAMES -> CapsuleFan(games) - else -> CapsuleWall(games, featured = featured) + else -> CapsuleWall(games, owned = owned, featured = featured) } }, scrim = { if (games.size >= WALL_MIN_GAMES) WallFade() }, @@ -150,18 +157,21 @@ internal fun CapsuleWall( games: List, driftMs: Int = if (games.isEmpty()) 75_000 else 40_000, modifier: Modifier = Modifier, + owned: List> = emptyList(), featured: List = emptyList(), ) { val pal = LocalPalette.current val blank = remember(pal) { WallCapsule(Brush.linearGradient(listOf(pal.surface, pal.background)), edge = pal.line) } - val padding = remember(games, featured) { - val owned = games.map { it.appId }.toSet() - featured.filter { it.appId !in owned }.take((WALL_DISTINCT - games.size).coerceAtLeast(0)) + val padding = remember(games, owned, featured) { + val shown = games.map { it.appId }.toMutableSet() + val library = owned.filter { shown.add(it.first) }.map { (id, art) -> id.toString() to art } + val store = if (owned.isEmpty()) featured.filter { shown.add(it.appId) }.map { it.name to it.art } else emptyList() + (library + store).take((WALL_DISTINCT - games.size).coerceAtLeast(0)) } TiltedWall(games.size + padding.size, driftMs, modifier) { i -> when { i < games.size -> WallCapsule(artBrush(hueOf(games[i].name)), games[i].art) - i - games.size < padding.size -> padding[i - games.size].let { WallCapsule(artBrush(hueOf(it.name)), it.art) } + i - games.size < padding.size -> padding[i - games.size].let { (seed, art) -> WallCapsule(artBrush(hueOf(seed)), art) } else -> blank } }