feat(stores): show the pre-install size in store game details (#2438)

* feat(stores): show the download size in store game details

* test(stores): preserve other catalog sizes

* fix(stores): restart the pre-install size lookup when the item becomes accessible

* fix(stores): retry size lookups that returned no size

* fix(stores): complete shared size lookups only after a failed one is cleared

* fix(stores): complete synchronous size lookup failures without an API 31 call
This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-11-12 12:12:24 -05:00
1 parent a1dfb96708
commit 76f0c51235
3 files changed
+128 -5

No files matched your search

@@ -43,7 +43,7 @@ object StoreSizes {
if (available != null) return CompletableFuture.completedFuture(available)
val app = context.applicationContext
val version = item.extra["version"].orEmpty()
return sizeRequests.computeIfAbsent(item.key) {
return shared(sizeRequests, item.key) {
CompletableFuture.supplyAsync({
val cached = cache(app, item.store).get(item.id, version)
val bytes = cached ?: runCatching { fetch(app, item) }
@@ -66,6 +66,25 @@ object StoreSizes {
}
}
internal fun shared(
requests: ConcurrentHashMap<String, CompletableFuture<Long?>>,
key: String,
start: () -> CompletableFuture<Long?>,
): CompletableFuture<Long?> {
var created: CompletableFuture<Long?>? = null
val shared = requests.computeIfAbsent(key) { CompletableFuture<Long?>().also { created = it } }
if (created === shared) {
val source = runCatching(start).getOrElse { failure ->
CompletableFuture<Long?>().apply { completeExceptionally(failure) }
}
source.whenComplete { bytes, error ->
if (bytes == null) requests.remove(key, shared)
if (error != null) shared.completeExceptionally(error) else shared.complete(bytes)
}
}
return shared
}
val onDisk = mutableStateMapOf<String, Long>()
fun requestDisk(context: Context, key: String, game: InstalledStoreGame) {
@@ -78,7 +97,7 @@ object StoreSizes {
onDisk[key]?.let { return CompletableFuture.completedFuture(it) }
val app = context.applicationContext
val version = "disk:${game.sidecar.installedAt}:${game.sidecar.installVersion}"
return diskRequests.computeIfAbsent(key) {
return shared(diskRequests, key) {
CompletableFuture.supplyAsync({
val c = cache(app, game.sidecar.store)
c.get("disk:${game.sidecar.id}", version)
@@ -309,7 +309,7 @@ private fun GameStatusLine(source: String, game: Library.SteamGame?, item: Catal
item?.accessible == true -> listOf(stringResource(R.string.stores_eyebrow_library))
else -> listOf(stringResource(R.string.stores_eyebrow_store))
}
val size = if (folder != null && (installed != null || game != null)) diskSize(installed, folder) else (item?.sizeBytes ?: 0L).takeIf { it > 0 }
val size = if (folder != null && (installed != null || game != null)) diskSize(installed, folder) else catalogSize(item).takeIf { it > 0 }
val line = (state + listOfNotNull(size?.let { formatBytes(it) })).filter { it.isNotBlank() }.joinToString(" · ").replaceFirstChar { it.uppercase() }
val muted = colors.onBackground.copy(alpha = 0.78f)
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {
@@ -399,6 +399,7 @@ internal fun GameActions(
val download = rawDownload?.takeIf { it.isActive }
val failed = rawDownload?.takeIf { it.state == DownloadState.FAILED }
val cloud = game?.library == Library.XBOX_CLOUD && installed == null
val downloadBytes = catalogSize(item)
Actions {
when {
s.shortcutPicker && game != null -> {
@@ -474,7 +475,7 @@ internal fun GameActions(
if (item?.installable == true && item.xboxPc) {
SecondaryButton(
if (StoresState.isUnfinished(item)) stringResource(R.string.stores_resume_install)
else if (item.sizeBytes > 0) stringResource(R.string.stores_install_size, formatBytes(item.sizeBytes))
else if (downloadBytes > 0) stringResource(R.string.stores_install_size, formatBytes(downloadBytes))
else stringResource(R.string.stores_install),
) { StoresState.requestInstall(ctx, item) }
}
@@ -492,7 +493,7 @@ internal fun GameActions(
}
item?.installable == true -> {
InstallButton(
if (item.sizeBytes > 0) stringResource(R.string.stores_install_size, formatBytes(item.sizeBytes)) else stringResource(R.string.stores_install),
if (downloadBytes > 0) stringResource(R.string.stores_install_size, formatBytes(downloadBytes)) else stringResource(R.string.stores_install),
leadOn,
) { StoresState.requestInstall(ctx, item) }
if (store == Store.XBOX && item.xboxCloud) {
@@ -1016,6 +1017,13 @@ internal fun FactRow(label: String, value: String, labelWidth: androidx.compose.
}
}
@Composable
internal fun catalogSize(item: CatalogItem?): Long {
val ctx = LocalContext.current
if (item != null) LaunchedEffect(item.key, item.accessible) { StoreSizes.request(ctx, item) }
return item?.let { StoreSizes.size(it) } ?: 0L
}
@Composable
internal fun diskSize(installed: InstalledStoreGame?, folder: File): Long? {
val ctx = LocalContext.current