From a2433f1965d428a5a7e2774f8c9b3fe13746641d Mon Sep 17 00:00:00 2001 From: The412Banner Date: Thu, 8 Oct 2026 19:09:16 -0400 Subject: [PATCH] Stores: the speed shown is the install rate, and the queue's two knobs share one row The engine's speed is a burst rate at the network side: on a card that writes at 26 MB/s the fetchers wait on the writer, its windows jump between 0.4 and 20 MB/s while the bar advances at the write rate. The queue now measures the shown speed from the byte deltas itself - an exponential average over three seconds, sampled at most every quarter second - and derives the ETA from it, for all three stores; the engine's figure stays in its log lines and is stripped from the detail line under the bar. The speed tier and downloads-at-a-time controls sit on one compact row with a single caption, on the Downloads page and in the cog's popup. --- .../launcher/stores/download/DownloadQueue.kt | 58 +++++++++++++++---- .../droiddeck/launcher/ui/StoresDownloads.kt | 44 +++++++++----- app/src/main/res/values/strings.xml | 1 + docs/progress-log.md | 8 +++ 4 files changed, 85 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/stores/download/DownloadQueue.kt b/app/src/main/java/com/droiddeck/launcher/stores/download/DownloadQueue.kt index dc5dc146c..4a80396dd 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/download/DownloadQueue.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/download/DownloadQueue.kt @@ -33,19 +33,57 @@ object DownloadQueue { /** What a running job reports with. */ class JobHandle internal constructor(val key: String, internal val cancelled: AtomicBoolean) { val isCancelled: Boolean get() = cancelled.get() - fun stage(stage: DownloadStage, detail: String = "") = update(key) { it.copy(stage = stage, detail = detail.ifEmpty { it.detail }, state = DownloadState.RUNNING) } - /** Bytes so far (negative = unchanged), the total (<= 0 = unchanged), a line, the speed (negative = unchanged). */ - fun progress(bytesDone: Long, bytesTotal: Long, detail: String? = null, speedBps: Long = -1L) = update(key) { - val done = if (bytesDone >= 0) bytesDone else it.bytesDone - val total = if (bytesTotal > 0) bytesTotal else it.bytesTotal - val speed = if (speedBps >= 0) speedBps else it.speedBps - val eta = if (speed > 0 && total > done) (total - done) / speed else -1L - it.copy(state = DownloadState.RUNNING, stage = DownloadStage.DOWNLOAD, bytesDone = done, bytesTotal = total, detail = detail ?: it.detail, speedBps = speed, etaSeconds = eta) - } + fun stage(stage: DownloadStage, detail: String = "") = update(key) { it.copy(stage = stage, detail = stripSpeed(detail).ifEmpty { it.detail }, state = DownloadState.RUNNING) } + /** + * Bytes so far (negative = unchanged), the total (<= 0 = unchanged), a line. [speedBps] is the + * engine's own figure: a burst rate at the network side, which jumps while the write side + * paces the bar, so it is not what the page shows - the queue measures the install rate + * from the byte deltas itself ([measure]); the engine's figure stays in its log lines. + */ + fun progress(bytesDone: Long, bytesTotal: Long, detail: String? = null, @Suppress("UNUSED_PARAMETER") speedBps: Long = -1L) = measure(key, bytesDone, bytesTotal, detail?.let(::stripSpeed)) fun log(line: String) = StoresState.logLine(line) } - private class Item(var entry: DownloadEntry, val factory: () -> DownloadJob, var job: DownloadJob? = null, val cancelled: AtomicBoolean = AtomicBoolean(false), var pauseRequested: Boolean = false) + /** "Downloading: data.pak 12.3 MB/s" → "Downloading: data.pak": the engine's burst rate is not shown twice. */ + private fun stripSpeed(s: String): String = s.replace(Regex("\\s+\\S+ [KM]B/s\\s*$"), "").trimEnd() + + /** How far back the shown speed looks: a few seconds, so the figure settles instead of following each file. */ + private const val SPEED_WINDOW_MS = 3000.0 + + private fun measure(key: String, bytesDone: Long, bytesTotal: Long, detail: String?) { + synchronized(lock) { + val item = items[key] ?: return + val e = item.entry + val done = if (bytesDone >= 0) bytesDone else e.bytesDone + val total = if (bytesTotal > 0) bytesTotal else e.bytesTotal + val now = System.currentTimeMillis() + if (bytesDone >= 0) { + if (item.speedAt == 0L) { item.speedAt = now; item.speedBytes = done } + else { + val dt = now - item.speedAt + // Sampled no faster than every quarter second, as an exponential average over + // SPEED_WINDOW_MS: one big file landing moves it, it does not define it. + if (dt >= 250) { + val inst = (done - item.speedBytes).coerceAtLeast(0) * 1000.0 / dt + val alpha = 1.0 - Math.exp(-dt / SPEED_WINDOW_MS) + item.speedEwma = if (item.speedEwma <= 0.0) inst else item.speedEwma + (inst - item.speedEwma) * alpha + item.speedAt = now; item.speedBytes = done + } + } + } + val speed = item.speedEwma.toLong() + val eta = if (speed > 0 && total > done) (total - done) / speed else -1L + item.entry = e.copy(state = DownloadState.RUNNING, stage = DownloadStage.DOWNLOAD, bytesDone = done, bytesTotal = total, detail = detail ?: e.detail, speedBps = speed, etaSeconds = eta) + publishLocked() + } + } + + private class Item(var entry: DownloadEntry, val factory: () -> DownloadJob, var job: DownloadJob? = null, val cancelled: AtomicBoolean = AtomicBoolean(false), var pauseRequested: Boolean = false) { + /** The shown speed's state: the last sample's clock and bytes, and the running average (bytes/s). */ + var speedAt = 0L + var speedBytes = 0L + var speedEwma = 0.0 + } private val lock = Any() private val items = LinkedHashMap() diff --git a/app/src/main/java/com/droiddeck/launcher/ui/StoresDownloads.kt b/app/src/main/java/com/droiddeck/launcher/ui/StoresDownloads.kt index 76ee75cf4..5dc563367 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/StoresDownloads.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/StoresDownloads.kt @@ -167,14 +167,8 @@ private fun DownloadSettings(s: FrontEndState, a: FrontEndActions) { val colors = MaterialTheme.colorScheme val pal = LocalPalette.current SectionTitle(stringResource(R.string.stores_download_manager), null) - Column(verticalArrangement = Arrangement.spacedBy(10.dp)) { - SettingCard(stringResource(R.string.setup_stores_speed), stringResource(R.string.stores_tier_note)) { - SegmentedTabs(StoreDownloadTier.ALL.map { it.id to stringResource(it.label) }, s.gameStoresSpeedTier) { a.onGameStoresSpeedTier(it) } - } - SettingCard(stringResource(R.string.stores_parallel), stringResource(R.string.stores_parallel_note)) { - var parallel by remember { mutableStateOf(DownloadQueue.parallel(ctx)) } - SegmentedTabs(listOf(1 to "1", 2 to "2", 3 to "3"), parallel) { parallel = it; DownloadQueue.setParallel(ctx, it) } - } + Column(verticalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.fillMaxWidth().clip(Shape12).background(colors.surface).border(1.dp, pal.line, Shape12).padding(horizontal = 14.dp, vertical = 10.dp)) { + DownloadControls(s, a) } SectionTitle(stringResource(R.string.stores_engine_log), null) Box(Modifier.fillMaxWidth().heightIn(min = 60.dp, max = 220.dp).clip(Shape12).background(Color.Black).border(1.dp, pal.line, Shape12).padding(12.dp)) { @@ -187,14 +181,33 @@ private fun DownloadSettings(s: FrontEndState, a: FrontEndActions) { Text(stringResource(R.string.stores_downloads_footnote), fontSize = 12.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(top = 12.dp)) } +/** + * The queue's two knobs on one line - the speed tier on the left, downloads at a time on the + * right - with one caption under them; the same control sits in the cog's popup. A narrow page + * puts the two controls on two tight lines. + */ @Composable -private fun SettingCard(label: String, note: String, control: @Composable () -> Unit) { +internal fun DownloadControls(s: FrontEndState, a: FrontEndActions) { + val ctx = LocalContext.current val colors = MaterialTheme.colorScheme - Column(verticalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.fillMaxWidth().clip(Shape12).background(colors.surface).border(1.dp, LocalPalette.current.line, Shape12).padding(horizontal = 14.dp, vertical = 10.dp)) { - Text(label, fontSize = 12.sp, color = colors.onSurfaceVariant) - control() - Text(note, fontSize = 12.sp, color = colors.onSurfaceVariant) + var parallel by remember { mutableStateOf(DownloadQueue.parallel(ctx)) } + val tier: @Composable () -> Unit = { + Column(verticalArrangement = Arrangement.spacedBy(4.dp)) { + Text(stringResource(R.string.setup_stores_speed), fontSize = 12.sp, color = colors.onSurfaceVariant) + SegmentedTabs(StoreDownloadTier.ALL.map { it.id to stringResource(it.label) }, s.gameStoresSpeedTier) { a.onGameStoresSpeedTier(it) } + } } + val count: @Composable () -> Unit = { + Column(verticalArrangement = Arrangement.spacedBy(4.dp)) { + Text(stringResource(R.string.stores_parallel), fontSize = 12.sp, color = colors.onSurfaceVariant) + SegmentedTabs(listOf(1 to "1", 2 to "2", 3 to "3"), parallel) { parallel = it; DownloadQueue.setParallel(ctx, it) } + } + } + BoxWithConstraints(Modifier.fillMaxWidth()) { + if (maxWidth >= 460.dp) Row(horizontalArrangement = Arrangement.spacedBy(16.dp), verticalAlignment = Alignment.Bottom) { tier(); count() } + else Column(verticalArrangement = Arrangement.spacedBy(8.dp)) { tier(); count() } + } + Text(stringResource(R.string.stores_download_controls_note), fontSize = 12.sp, color = colors.onSurfaceVariant) } /** @@ -216,9 +229,8 @@ internal fun StoresSettingsDialog(s: FrontEndState, a: FrontEndActions, onDismis s.storesOpenTab, ) { a.onStoresOpenTab(it) } } - SettingsRow(stringResource(R.string.setup_stores_speed), stringResource(R.string.setup_stores_speed_hint)) { - SegmentedTabs(StoreDownloadTier.ALL.map { it.id to stringResource(it.label) }, s.gameStoresSpeedTier) { a.onGameStoresSpeedTier(it) } - } + // The queue's two knobs as one compact row, the same control the Downloads page has. + Column(Modifier.fillMaxWidth().padding(horizontal = 14.dp, vertical = 11.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) { DownloadControls(s, a) } } } Rise(2) { Actions { SecondaryButton(stringResource(R.string.common_ok), onClick = close) } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4556a10f0..62de30485 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2074,6 +2074,7 @@ Download manager Caps how many chunks the engine fetches at once: Balanced 16 · Fast 32 · Max 96 in flight. Downloads at a time + Balanced / Fast / Max pull harder from the store; 2–3 at a time share the link. Speed shown is the install rate. One manager for all three stores; Steam\'s own downloads are unaffected. Engine log idle diff --git a/docs/progress-log.md b/docs/progress-log.md index 0ebdd2cfc..5f4057a29 100644 --- a/docs/progress-log.md +++ b/docs/progress-log.md @@ -95,6 +95,14 @@ without it and Setup says "Stores engine not built"). v2 record has the same keys for them. `cleanStoreText` drops those keys, strips tags, decodes entities; the library tries the product's lead, then v2 `overview`, then v2 `description`, and shows nothing when all are templates. Epic's and Amazon's text goes through the same cleaner. +- **Speed shown = install rate.** Device evidence (Epic › Metalstorm, 1.68 GB on Max to the SD + card): the engine's windows burst at 0.4–20 MB/s with 0–3 of 20 requests in flight while the card + writes at 26 MB/s - the fetchers wait on the write side, so the engine's `speedBps` jumped while + the bar advanced at the write rate. `DownloadQueue` now measures the shown speed itself from the + byte deltas (an exponential average over 3 s, sampled at most every 250 ms) and derives the ETA + from it, for all three stores; the engine's own figure stays in its log lines, and the detail + line under the bar has it stripped. The tier and downloads-at-a-time controls sit on one compact + row with a single caption, on the Downloads page and in the cog's popup. - **Device-proven on the AYANEO Pocket FIT, 2026-10-08 (GOG):** sign-in, the library (33 owned), DOOM I Enhanced installed through the GOG engine to the SD Games root, shown in Games with the GOG chip and real art, registered as a non-Steam game in the Steam client (grid art present), and