fix(steam): show progress while applying client updates

Forward extraction and installation messages from the x64 bootstrap log and replace stale download percentages with the applying-update state. Add regression coverage for phase ordering and log forwarding.

Fixes #812
This commit is contained in:
HCOOKIELYT authored and Kurt Himebauch committed 2026-11-05 11:56:42 -05:00
1 parent fe1dd8ca72
commit 0544933abd
6 files changed
+176 -1

No files matched your search

@@ -77,6 +77,7 @@ class LoadingState(context: Context, private val steam: Boolean = true) {
var stepText: String? = null
var downloadAt = -1
var downloadPercent = -1
var applyingAt = -1
var clientDownloadAt = -1
var clientDownload: String? = null
var clientPercent = -1
@@ -99,10 +100,16 @@ class LoadingState(context: Context, private val steam: Boolean = true) {
val done = m.groupValues[1].toLong()
val total = maxOf(1L, m.groupValues[2].toLong())
downloadPercent = (done * 100 / total).toInt()
} else if (steam && UPDATE_APPLYING.matches(line)) {
applyingAt = at
}
}
}
return when {
applyingAt > stepAt && applyingAt > downloadAt -> Line(
context.getString(com.droiddeck.launcher.R.string.loadstate_steam_update_applying), -1,
Topic.STEAM, readable = true,
)
downloadAt > stepAt && downloadPercent >= 0 -> Line(
context.getString(com.droiddeck.launcher.R.string.loadstate_steam_update, downloadPercent), downloadPercent,
Topic.STEAM, readable = true,
@@ -151,6 +158,7 @@ class LoadingState(context: Context, private val steam: Boolean = true) {
private const val TAIL_BYTES = 48L * 1024
private val UPDATE_PROGRESS = Regex("""Downloading update \((\d+) of (\d+) KB\)""")
private val UPDATE_APPLYING = Regex("""^\s*(?:\[[^\]]+\]\s*)*(?:Extracting package|Installing update)\.\.\.\s*$""")
private val INSTALL_COUNT = Regex("""downloading Steam: (\S+) \((\d+)/(\d+)\)""")
private val INSTALL_MEGABYTES = Regex("""^, (\d+) of (\d+) MB""")
}
@@ -2088,6 +2088,7 @@
<string name="loadstate_starting">正在启动会话…</string>
<string name="loadstate_elapsed">已用时 %1$d:%2$02d · 仍在处理</string>
<string name="loadstate_steam_update">正在下载 Steam 客户端更新 · %1$d%%</string>
<string name="loadstate_steam_update_applying">正在应用 Steam 客户端更新…</string>
<string name="loadstate_steam_client">正在下载 Steam 客户端 · %1$s</string>
<string name="pextra_busy">已有兼容性工具正在安装</string>
+1
View File
@@ -2224,6 +2224,7 @@
<string name="loadstate_starting">Starting the session…</string>
<string name="loadstate_elapsed">%1$d:%2$02d elapsed · still working</string>
<string name="loadstate_steam_update">Downloading the Steam client update · %1$d%%</string>
<string name="loadstate_steam_update_applying">Applying the Steam client update…</string>
<string name="loadstate_steam_client">Downloading the Steam client · %1$s</string>
<string name="pextra_busy">A compatibility tool install is already running</string>
@@ -0,0 +1,108 @@
package com.droiddeck.launcher.session
import android.app.Application
import java.io.File
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [28], application = Application::class, qualifiers = "en")
class LoadingStateUpdateTest {
@get:Rule val temp = TemporaryFolder()
@Test fun extractingReplacesAnIncompleteDownload() {
assertApplying(read("Downloading update (50 of 100 KB)", "Extracting package..."))
}
@Test fun installingClearsTheCompletedDownloadPercentage() {
assertApplying(read("Downloading update (100 of 100 KB)", "Installing update..."))
}
@Test fun acceptsForwardedMessagesAndBootstrapPrefixes() {
for (message in listOf(
"Installing update...",
"[2026-10-25 12:00:02] Extracting package...",
"[----] Installing update...\r",
"[2026-10-25 12:00:02] [----] Extracting package...",
)) assertApplying(read(message))
}
@Test fun aNewDownloadReplacesAnOlderApplyingStage() {
val state = read("Installing update...", "Downloading update (25 of 100 KB)")
assertEquals(25, state.percent)
assertEquals("Downloading the Steam client update · 25%", state.step)
}
@Test fun aNewScriptStepReplacesAnOlderApplyingStage() {
val state = read("Installing update...", "== STEP 12:00:03 checking the Linux runtime")
assertEquals("checking the Linux runtime", state.step)
assertEquals(LoadingState.Topic.RUNTIME, state.topic)
assertEquals(-1, state.percent)
}
@Test fun unrelatedOutputKeepsTheApplyingStage() {
assertApplying(read("Installing update...", "Loading cached metrics", ""))
}
@Test fun similarlyNamedMessagesDoNotReplaceTheDownload() {
val state = read(
"Downloading update (50 of 100 KB)",
"worker: Installing update...",
"Installing update for Proton...",
"[12:00:02] error: Extracting package...",
)
assertEquals(50, state.percent)
assertEquals("Downloading the Steam client update · 50%", state.step)
}
@Test fun anOlderRuntimeCanReturnToItsPartCountAfterApplying() {
val state = read("Installing update...", "== STEP 12:00:03 downloading Steam: a_all (1/2)")
assertEquals(50, state.percent)
assertEquals("Downloading the Steam client · a_all", state.step)
}
@Test fun desktopStartupDoesNotConsumeSteamApplyingMessages() {
val state = read(
"== STEP 12:00:01 starting the desktop", "Installing update...", steam = false,
)
assertEquals("starting the desktop", state.step)
assertEquals(LoadingState.Topic.DESKTOP, state.topic)
}
@Test fun anExistingLoadingStateFollowsUpdatesAcrossPolls() {
val context = RuntimeEnvironment.getApplication()
val log = log("Downloading update (100 of 100 KB)")
val state = LoadingState(context)
state.update(context, log)
assertEquals(100, state.percent)
log.appendText("\n[12:00:02] Installing update...")
state.update(context, log)
assertApplying(state)
log.appendText("\nDownloading update (20 of 100 KB)")
state.update(context, log)
assertEquals(20, state.percent)
}
private fun read(vararg lines: String, steam: Boolean = true): LoadingState {
val context = RuntimeEnvironment.getApplication()
return LoadingState(context, steam).apply { update(context, log(*lines)) }
}
private fun log(vararg lines: String): File = temp.newFile().apply {
writeText((listOf("== STEP 12:00:00 starting the Steam client") + lines).joinToString("\n"))
}
private fun assertApplying(state: LoadingState) {
assertEquals(-1, state.percent)
assertEquals("Applying the Steam client update…", state.step)
assertEquals(LoadingState.Topic.STEAM, state.topic)
assertTrue(state.readable)
}
}
@@ -819,7 +819,7 @@ x64_exec() {
mkdir -p "$STEAM_X64/logs"
touch "$STEAM_X64/logs/bootstrap_log.txt"
( tail -n0 -F --pid=$$ "$STEAM_X64/logs/bootstrap_log.txt" 2>/dev/null |
grep --line-buffered -oE 'Downloading update \([0-9,]+ of [0-9,]+ KB\)' | sed -u 's/,//g' >&2 ) &
grep --line-buffered -oE 'Downloading update \([0-9,]+ of [0-9,]+ KB\)|^[[:space:]]*(\[[^]]+\][[:space:]]*)*(Extracting package|Installing update)\.\.\.[[:space:]]*$' | sed -u 's/,//g' >&2 ) &
echo "== x86-64 client: steamrt64 $(x64_manifest_version steamrt64) (the client may update itself)" >&2
x64_webhelper_gpu && { x64_gpu_watch >&2 & }
exec "${BL_FEX:-/usr/local/bin/FEX}" "$STEAM_X64/steamrt64/steam" "$@"
+57
View File
@@ -0,0 +1,57 @@
from pathlib import Path
import re
import shutil
import subprocess
import unittest
SCRIPT = Path(__file__).resolve().parents[1] / 'linuxfs/overlay/usr/local/bin/droiddeck-steam-x64'
class SteamUpdateProgressTest(unittest.TestCase):
def forward(self, lines):
matches = re.findall(
r'(?m)^\s*(grep --line-buffered .*\| sed -u .* >&2) \) &$',
SCRIPT.read_text(encoding='utf-8'),
)
self.assertEqual(1, len(matches), 'Find the production bootstrap forwarding pipeline')
result = subprocess.run(
[shutil.which('bash') or 'bash', '-c', matches[0]],
input='\n'.join(lines) + '\n', text=True, capture_output=True, check=True, timeout=10,
)
self.assertEqual('', result.stdout)
return result.stderr.splitlines()
def test_downloads_keep_their_normalized_progress(self):
self.assertEqual(['Downloading update (1250 of 5000 KB)'], self.forward([
'[2026-10-25 12:00:01] Downloading update (1,250 of 5,000 KB)...',
]))
def test_forwards_extracting_and_installing_from_bootstrap_logs(self):
lines = [
'[2026-10-25 12:00:02] Extracting package...',
'[2026-10-25 12:00:03] Installing update...',
]
self.assertEqual(lines, self.forward(lines))
def test_accepts_plain_and_console_prefixed_messages(self):
lines = [
'Extracting package...', '[----] Installing update...',
'[2026-10-25 12:00:02] [----] Extracting package...',
]
self.assertEqual(lines, self.forward(lines))
def test_ignores_unrelated_and_similarly_named_messages(self):
self.assertEqual([], self.forward([
'Loading cached metrics', 'worker: Installing update...',
'Installing update for Proton...', '[12:00:02] error: Extracting package...',
]))
def test_preserves_stage_order_when_a_download_restarts(self):
self.assertEqual([
'Downloading update (100 of 100 KB)', 'Installing update...',
'Downloading update (20 of 100 KB)',
], self.forward([
'Downloading update (100 of 100 KB)', 'Installing update...',
'Downloading update (20 of 100 KB)',
]))