mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 15:26:04 +00:00
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.
This commit is contained in:
1 parent
f9db495e3f
commit
a2433f1965
4 files changed
+85
-26
No files matched your search
@@ -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<String, Item>()
|
||||
|
||||
@@ -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) } }
|
||||
|
||||
@@ -2074,6 +2074,7 @@
|
||||
<string name="stores_download_manager">Download manager</string>
|
||||
<string name="stores_tier_note">Caps how many chunks the engine fetches at once: Balanced 16 · Fast 32 · Max 96 in flight.</string>
|
||||
<string name="stores_parallel">Downloads at a time</string>
|
||||
<string name="stores_download_controls_note">Balanced / Fast / Max pull harder from the store; 2–3 at a time share the link. Speed shown is the install rate.</string>
|
||||
<string name="stores_parallel_note">One manager for all three stores; Steam\'s own downloads are unaffected.</string>
|
||||
<string name="stores_engine_log">Engine log</string>
|
||||
<string name="stores_log_idle">idle</string>
|
||||
|
||||
Reference in new issue
Block a user