feat(launch): show compatibility install progress (#1629)

This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-10-26 15:41:46 -04:00
1 parent b3561bf658
commit 2d8957a401
5 files changed
+416 -12

No files matched your search

@@ -91,12 +91,16 @@ class FrontEndActivity : ComponentActivity() {
private val components = ComponentsMenu(this, ui)
private val decky = DeckyMenu(this, ui)
private val updates = UpdatesMenu(this, ui)
private val protons = ProtonMenu(this, ui) { !busy && flood == null && pkgStage == null && components.compBusy == null }
private val protons = ProtonMenu(this, ui) { !busy && flood == null && compatLaunch == null && pkgStage == null && components.compBusy == null }
private var installed by mutableStateOf<String?>(null)
private var flood by mutableStateOf<PendingFlood?>(null)
private var floodProgress by androidx.compose.runtime.mutableFloatStateOf(0f)
private class PendingFlood(val from: androidx.compose.ui.geometry.Rect, val intent: Intent)
private class CompatLaunch(val intent: Intent, val loading: com.droiddeck.launcher.session.LoadingState, var menuInstall: Boolean)
private var compatLaunch by mutableStateOf<CompatLaunch?>(null)
private var compatLaunchPoll: Runnable? = null
private var compatLaunchVisible = false
private var returning by mutableStateOf<ReturningFlood?>(null)
private class ReturningFlood(val color: Int, val to: androidx.compose.ui.geometry.Rect?)
private var ready by mutableStateOf(false)
@@ -134,9 +138,14 @@ class FrontEndActivity : ComponentActivity() {
private var catalog by mutableStateOf<List<DesktopCatalog.Entry>?>(null)
private var catalogLoading by mutableStateOf(false)
private var packageRows by mutableStateOf<List<PackageRow>?>(null)
private var pkgId by mutableStateOf<String?>(null)
private var pkgStage by mutableStateOf<String?>(null)
private var pkgPercent by mutableIntStateOf(-1)
private object PackageOperation {
val id = mutableStateOf<String?>(null)
val stage = mutableStateOf<String?>(null)
val percent = mutableIntStateOf(-1)
}
private var pkgId by PackageOperation.id
private var pkgStage by PackageOperation.stage
private var pkgPercent by PackageOperation.percent
private var desktopInstalled by mutableStateOf(false)
private var desktopPresent by mutableStateOf(false)
private var battleNetInstalled by mutableStateOf(false)
@@ -440,13 +449,14 @@ class FrontEndActivity : ComponentActivity() {
override fun startActivity(intent: Intent?) {
if (intent?.component?.className == SessionActivity::class.java.name) {
if (compatLaunch != null) return
when {
busy || LinuxRuntimeInstaller.isBusy() -> {
android.widget.Toast.makeText(this, R.string.main_wait_runtime, android.widget.Toast.LENGTH_SHORT).show()
return
}
protons.protonBusyId != null || ProtonExtras.installInProgress -> {
android.widget.Toast.makeText(this, R.string.main_wait_proton_install, android.widget.Toast.LENGTH_SHORT).show()
waitForCompat(intent)
return
}
pkgStage != null -> {
@@ -474,6 +484,8 @@ class FrontEndActivity : ComponentActivity() {
flood = null
floodProgress = 0f
com.droiddeck.launcher.ui.LaunchOrigin.flooding = null
if (!busy && !LinuxRuntimeInstaller.isBusy() && pkgStage == null &&
(protons.protonBusyId != null || ProtonExtras.installInProgress)) waitForCompat(f.intent)
return
}
val signal = com.droiddeck.launcher.ui.Themes.byId(theme).signal
@@ -481,6 +493,71 @@ class FrontEndActivity : ComponentActivity() {
overridePendingTransition(0, 0)
}
private fun waitForCompat(next: Intent, menuInstall: Boolean = protons.protonBusyId != null) {
if (compatLaunch != null) return
com.droiddeck.launcher.ui.LaunchOrigin.take()
com.droiddeck.launcher.ui.LaunchOrigin.flooding = null
val waiting = CompatLaunch(Intent(next), com.droiddeck.launcher.session.LoadingState(this), menuInstall)
compatLaunch = waiting
val poll = object : Runnable {
override fun run() {
if (isDestroyed || isFinishing || compatLaunch !== waiting) return
if (protons.protonBusyId != null || ProtonExtras.installInProgress) {
waiting.menuInstall = waiting.menuInstall || protons.protonBusyId != null
val percent = if (protons.protonBusyId != null) protons.protonPercent else -1
val stage = protons.protonStage ?: getString(R.string.load_compat_wait)
waiting.loading.say(if (percent >= 0) getString(R.string.load_compat_progress, stage, percent) else stage,
com.droiddeck.launcher.session.LoadingState.Topic.RUNTIME, readable = true)
waiting.loading.percent = percent
waiting.loading.tick()
ui.postDelayed(this, 250)
return
}
if (!compatLaunchVisible) { ui.postDelayed(this, 250); return }
val problem = protons.protonProblem.takeIf { waiting.menuInstall }
if (problem == null && (busy || LinuxRuntimeInstaller.isBusy() || pkgStage != null)) {
waiting.loading.say(pkgStage ?: stage.takeIf { it.isNotBlank() } ?: getString(R.string.main_wait_runtime),
com.droiddeck.launcher.session.LoadingState.Topic.RUNTIME, readable = true)
waiting.loading.percent = if (pkgStage != null) pkgPercent else percent
waiting.loading.tick()
ui.postDelayed(this, 250)
return
}
compatLaunchPoll = null
if (problem != null) waiting.loading.showEnded(problem)
else {
compatLaunch = null
startActivity(waiting.intent)
}
}
}
compatLaunchPoll = poll
poll.run()
}
private fun cancelCompatLaunch() {
compatLaunchPoll?.let(ui::removeCallbacks)
compatLaunchPoll = null
compatLaunch = null
}
private fun restoreCompatLaunch(state: Bundle) {
savedIntent(state, KEY_COMPAT_LAUNCH)?.let { next ->
val problem = state.getString(KEY_COMPAT_PROBLEM)
if (problem == null) waitForCompat(next, state.getBoolean(KEY_COMPAT_MENU_INSTALL))
else compatLaunch = CompatLaunch(next,
com.droiddeck.launcher.session.LoadingState(this).apply { showEnded(problem) }, false)
}
}
private fun saveCompatLaunch(state: Bundle) {
compatLaunch?.let {
state.putParcelable(KEY_COMPAT_LAUNCH, it.intent)
state.putBoolean(KEY_COMPAT_MENU_INSTALL, it.menuInstall)
if (it.loading.ended) state.putString(KEY_COMPAT_PROBLEM, it.loading.step)
}
}
private var shortcutPicker by mutableStateOf(false)
private var shortcutLibraryScanning by mutableStateOf(false)
@Volatile private var libraryScanGeneration = 0
@@ -542,7 +619,7 @@ class FrontEndActivity : ComponentActivity() {
}
private fun launchGame(game: Library.SteamGame, returnHome: Boolean = false): Boolean {
if (protons.protonBusyId != null || ProtonExtras.installInProgress || pkgStage != null) {
if (pkgStage != null) {
android.widget.Toast.makeText(this, R.string.main_wait_install_game, android.widget.Toast.LENGTH_SHORT).show()
return false
}
@@ -654,7 +731,7 @@ class FrontEndActivity : ComponentActivity() {
android.widget.Toast.makeText(this, R.string.epic_client_uninstalling, android.widget.Toast.LENGTH_SHORT).show()
return false
}
if (protons.protonBusyId != null || ProtonExtras.installInProgress || pkgStage != null) {
if (pkgStage != null) {
android.widget.Toast.makeText(this, R.string.main_wait_install_game, android.widget.Toast.LENGTH_SHORT).show()
return false
}
@@ -1216,12 +1293,21 @@ class FrontEndActivity : ComponentActivity() {
com.droiddeck.launcher.ui.LaunchOrigin.flooding = null
}
}
androidx.activity.compose.BackHandler(compatLaunch != null) { cancelCompatLaunch() }
compatLaunch?.loading?.let { loading ->
com.droiddeck.launcher.ui.LoadingOverlay(
loading.step, loading.percent, loading.elapsed, getString(R.string.load_compat_hint), loading.ended,
loading.topic, loading.readable, title = getString(R.string.load_compat_title),
onCancel = ::cancelCompatLaunch, onClose = ::cancelCompatLaunch,
)
}
}
}
}
if (savedInstanceState == null) ui.post { startSteamAtStartupIfEnabled() }
else {
restoreCompatLaunch(savedInstanceState)
pendingSwitch = savedIntent(savedInstanceState, KEY_PENDING_SWITCH)
savedIntent(savedInstanceState, KEY_SWITCHING_TO)?.let { awaitSessionEnd(it, savedInstanceState.getLong(KEY_SWITCH_DEADLINE)) }
}
@@ -1308,6 +1394,14 @@ class FrontEndActivity : ComponentActivity() {
}
override fun dispatchKeyEvent(event: KeyEvent): Boolean {
if (compatLaunch != null) {
if (event.keyCode == KeyEvent.KEYCODE_BACK || event.keyCode == KeyEvent.KEYCODE_BUTTON_B) {
if (event.action == KeyEvent.ACTION_UP) cancelCompatLaunch()
return true
}
if (!compatLaunch!!.loading.ended && event.keyCode !in listOf(
KeyEvent.KEYCODE_VOLUME_UP, KeyEvent.KEYCODE_VOLUME_DOWN, KeyEvent.KEYCODE_VOLUME_MUTE)) return true
}
if (event.keyCode == KeyEvent.KEYCODE_BUTTON_A) com.droiddeck.launcher.ui.HeldKeys.confirm = event.action == KeyEvent.ACTION_DOWN
if (showComponents && (event.keyCode == KeyEvent.KEYCODE_BUTTON_L1 || event.keyCode == KeyEvent.KEYCODE_BUTTON_R1)) {
if (event.action == KeyEvent.ACTION_DOWN && event.repeatCount == 0) {
@@ -1324,8 +1418,20 @@ class FrontEndActivity : ComponentActivity() {
}
}
override fun dispatchGenericMotionEvent(event: android.view.MotionEvent): Boolean {
if (compatLaunch != null && !compatLaunch!!.loading.ended &&
com.droiddeck.launcher.input.PadBridge.isControllerMotionEvent(event)) return true
return super.dispatchGenericMotionEvent(event)
}
override fun onPause() {
compatLaunchVisible = false
super.onPause()
}
override fun onResume() {
super.onResume()
compatLaunchVisible = true
orientation = SessionPrefs.orientation(this)
launcherOrientation = com.droiddeck.launcher.core.AppUiPrefs.orientation(this)
requestedOrientation = launcherOrientation
@@ -1378,6 +1484,7 @@ class FrontEndActivity : ComponentActivity() {
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
saveCompatLaunch(outState)
pendingSwitch?.let { outState.putParcelable(KEY_PENDING_SWITCH, it) }
switchingTo?.let {
outState.putParcelable(KEY_SWITCHING_TO, it)
@@ -1390,6 +1497,7 @@ class FrontEndActivity : ComponentActivity() {
else @Suppress("DEPRECATION") state.getParcelable(key)
override fun onDestroy() {
cancelCompatLaunch()
updates.unregister()
super.onDestroy()
}
@@ -1594,7 +1702,7 @@ class FrontEndActivity : ComponentActivity() {
}
private fun openBattleNet(args: List<String> = emptyList()) {
if (protons.protonBusyId != null || ProtonExtras.installInProgress || pkgStage != null) {
if (pkgStage != null) {
android.widget.Toast.makeText(this, R.string.main_wait_install_game, android.widget.Toast.LENGTH_SHORT).show()
return
}
@@ -2316,6 +2424,9 @@ class FrontEndActivity : ComponentActivity() {
private const val SESSION_SWITCH_WAIT_MS = 30_000L
private const val SESSION_SWITCH_POLL_MS = 250L
private const val KEY_PENDING_SWITCH = "pending_switch"
private const val KEY_COMPAT_LAUNCH = "compat_launch"
private const val KEY_COMPAT_MENU_INSTALL = "compat_menu_install"
private const val KEY_COMPAT_PROBLEM = "compat_problem"
private const val KEY_SWITCHING_TO = "switching_to"
private const val KEY_SWITCH_DEADLINE = "switch_deadline"
private val SESSION_ENDED = setOf(SessionPhase.IDLE, SessionPhase.FAILED)
@@ -20,10 +20,19 @@ internal class ProtonMenu(
private val ui: Handler,
private val idle: () -> Boolean = { true },
) {
var protonRows by mutableStateOf<List<ProtonRow>>(emptyList())
var protonBusyId by mutableStateOf<String?>(null)
var protonStage by mutableStateOf<String?>(null)
var protonPercent by mutableIntStateOf(-1)
// Install workers and their results outlive the activity that starts them.
private object Operation {
val rows = mutableStateOf<List<ProtonRow>>(emptyList())
val busyId = mutableStateOf<String?>(null)
val stage = mutableStateOf<String?>(null)
val percent = mutableIntStateOf(-1)
val problem = mutableStateOf<String?>(null)
}
var protonRows by Operation.rows
var protonBusyId by Operation.busyId
var protonStage by Operation.stage
var protonPercent by Operation.percent
var protonProblem by Operation.problem
private val checking = java.util.concurrent.atomic.AtomicBoolean(false)
@VisibleForTesting internal var installer: (ProtonExtras.Tool, (String, Int) -> Unit) -> String? =
{ tool, progress -> ProtonExtras.install(activity, tool, progress) }
@@ -33,6 +42,7 @@ internal class ProtonMenu(
if (protonBusyId != null || ProtonExtras.installInProgress || SessionState.running) return
ProtonExtras.unqueue(activity, tool)
protonBusyId = id
protonProblem = null
protonStage = activity.getString(R.string.store_starting)
protonPercent = -1
Thread({
@@ -43,6 +53,7 @@ internal class ProtonMenu(
}.getOrElse { it.message ?: it.javaClass.simpleName }
if (problem == null && !automatic && tool.id == ProtonExtras.OWN) ProtonExtras.setDeclined(activity, false)
ui.post {
protonProblem = problem
protonBusyId = null
protonStage = null
protonPercent = -1
@@ -60,6 +71,7 @@ internal class ProtonMenu(
val tool = ProtonExtras.tools.firstOrNull { it.id == id } ?: return
if (protonBusyId != null || SessionState.running) return
protonBusyId = id
protonProblem = null
protonStage = activity.getString(R.string.main_removing_named, dir ?: tool.name)
protonPercent = -1
Thread({
@@ -98,6 +110,7 @@ internal class ProtonMenu(
!LinuxRuntime.isInstalled(activity) || !AutoComponents.online(activity) || AutoComponents.unfavourable(activity)) return
if (ProtonExtras.installedAll(activity, ProtonExtras.tools.first { it.id == ProtonExtras.OWN }).size > 1) {
protonBusyId = ProtonExtras.OWN
protonProblem = null
Thread({
ProtonExtras.tidy(activity)
val tidied = ProtonExtras.installedAll(activity, ProtonExtras.tools.first { it.id == ProtonExtras.OWN }).size <= 1
+4
View File
@@ -1287,6 +1287,10 @@
<string name="main_wait_runtime">Wait for the runtime operation to finish</string>
<string name="main_wait_proton_install">Wait for the compatibility tool install to finish</string>
<string name="load_compat_title">Preparing compatibility tools</string>
<string name="load_compat_wait">Waiting for compatibility setup to finish</string>
<string name="load_compat_hint">Your session will start when setup finishes.</string>
<string name="load_compat_progress">%1$s · %2$d%%</string>
<string name="main_wait_desktop_install">Wait for the desktop app install to finish</string>
<string name="main_wait_install_game">Wait for the install to finish before launching a game</string>
<string name="main_saves_close_session">Close the Steam session first, so the game can\'t save over the import</string>
@@ -0,0 +1,268 @@
package com.droiddeck.launcher
import android.content.Intent
import android.os.Bundle
import android.os.Looper
import com.droiddeck.launcher.session.LoadingState
import com.droiddeck.launcher.session.ProtonExtras
import com.droiddeck.launcher.session.SessionService
import com.droiddeck.launcher.ui.LaunchOrigin
import java.time.Duration
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import org.junit.After
import org.junit.Assert.*
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner
import org.robolectric.Shadows.shadowOf
import org.robolectric.annotation.Config
import org.robolectric.util.ReflectionHelpers
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [28], manifest = Config.NONE)
class CompatLaunchTest {
private lateinit var activity: FrontEndActivity
private lateinit var protons: ProtonMenu
@Before fun setUp() {
installing(false)
LaunchOrigin.take()
activity = Robolectric.buildActivity(FrontEndActivity::class.java).get()
protons = ReflectionHelpers.getField(activity, "protons")
ReflectionHelpers.setField(activity, "compatLaunchVisible", true)
protons.protonBusyId = "droiddeck"
protons.protonProblem = null
protons.protonStage = "Downloading DroidDeck Proton"
protons.protonPercent = 37
setString("setPkgStage", null)
}
@After fun cleanUp() {
cancel()
protons.protonBusyId = null
protons.protonProblem = null
protons.protonStage = null
protons.protonPercent = -1
setString("setPkgStage", null)
installing(false)
LaunchOrigin.take()
}
@Test fun waitingShowsRealProgressThenStartsTheOriginalRequestOnce() {
activity.startActivity(request("steam://rungameid/42"))
assertNull(shadowOf(activity).nextStartedActivity)
assertEquals(37, loading().percent)
assertTrue(loading().step.contains("37%"))
protons.protonStage = "Verifying download"
protons.protonPercent = -1
advance()
assertEquals("Verifying download", loading().step)
assertEquals(-1, loading().percent)
protons.protonBusyId = null
advance()
assertEquals("steam://rungameid/42", shadowOf(activity).nextStartedActivity.getStringExtra(SessionService.EXTRA_STEAM_URL))
assertNull(waiting())
advance()
assertNull(shadowOf(activity).nextStartedActivity)
}
@Test fun cancellingTheLaunchLeavesTheInstallRunningAndPreventsALateStart() {
activity.startActivity(request("first"))
cancel()
assertEquals("droiddeck", protons.protonBusyId)
protons.protonBusyId = null
advance()
assertNull(waiting())
assertNull(shadowOf(activity).nextStartedActivity)
}
@Test fun installationFailureStaysOnTheLoadingErrorWithoutStarting() {
activity.startActivity(request("first"))
protons.protonProblem = "Checksum verification failed"
protons.protonBusyId = null
advance()
assertTrue(loading().ended)
assertEquals("Checksum verification failed", loading().step)
assertNull(shadowOf(activity).nextStartedActivity)
}
@Test fun repeatedLaunchesDoNotReplaceThePendingGame() {
activity.startActivity(request("first"))
activity.startActivity(request("second"))
protons.protonBusyId = null
advance()
assertEquals("first", shadowOf(activity).nextStartedActivity.getStringExtra(SessionService.EXTRA_STEAM_URL))
assertNull(shadowOf(activity).nextStartedActivity)
}
@Test fun anInstallOutsideTheLauncherUsesIndeterminateProgress() {
protons.protonBusyId = null
installing(true)
activity.startActivity(request("first"))
assertEquals(-1, loading().percent)
assertNull(shadowOf(activity).nextStartedActivity)
installing(false)
advance()
assertNotNull(shadowOf(activity).nextStartedActivity)
}
@Test fun finishingInTheBackgroundWaitsUntilTheLauncherIsVisible() {
activity.startActivity(request("first"))
ReflectionHelpers.setField(activity, "compatLaunchVisible", false)
protons.protonBusyId = null
advance()
assertNull(shadowOf(activity).nextStartedActivity)
ReflectionHelpers.setField(activity, "compatLaunchVisible", true)
advance()
assertNotNull(shadowOf(activity).nextStartedActivity)
}
@Test fun aRestoredCompletedRequestWaitsForResume() {
activity.startActivity(request("first"))
val saved = save()
cancel()
protons.protonBusyId = null
recreate(saved)
advance()
assertNull(shadowOf(activity).nextStartedActivity)
ReflectionHelpers.setField(activity, "compatLaunchVisible", true)
advance()
assertEquals("first", shadowOf(activity).nextStartedActivity.getStringExtra(SessionService.EXTRA_STEAM_URL))
}
@Test fun overlappingPackageWorkKeepsTheOriginalLaunchUntilItFinishes() {
activity.startActivity(request("first"))
setString("setPkgStage", "Installing desktop")
ReflectionHelpers.callInstanceMethod<Void>(activity, "setPkgPercent", ReflectionHelpers.ClassParameter.from(Int::class.javaPrimitiveType, 64))
protons.protonBusyId = null
advance()
assertNotNull(waiting())
assertNull(shadowOf(activity).nextStartedActivity)
assertEquals("Installing desktop", loading().step)
assertEquals(64, loading().percent)
setString("setPkgStage", null)
advance()
assertEquals("first", shadowOf(activity).nextStartedActivity.getStringExtra(SessionService.EXTRA_STEAM_URL))
advance()
assertNull(shadowOf(activity).nextStartedActivity)
}
@Test fun overlappingRuntimeWorkDoesNotDropThePendingLaunch() {
activity.startActivity(request("first"))
setString("setStage", "Updating runtime")
ReflectionHelpers.callInstanceMethod<Void>(activity, "setBusy", ReflectionHelpers.ClassParameter.from(Boolean::class.javaPrimitiveType, true))
protons.protonBusyId = null
advance()
assertNotNull(waiting())
assertNull(shadowOf(activity).nextStartedActivity)
assertEquals("Updating runtime", loading().step)
ReflectionHelpers.callInstanceMethod<Void>(activity, "setBusy", ReflectionHelpers.ClassParameter.from(Boolean::class.javaPrimitiveType, false))
advance()
assertEquals("first", shadowOf(activity).nextStartedActivity.getStringExtra(SessionService.EXTRA_STEAM_URL))
}
@Test fun aPackageDownloadStillBlocksTheLaunchAfterRecreationAndReportsOldWorkerProgress() {
activity.startActivity(request("first"))
setString("setPkgStage", "Downloading AppImage")
ReflectionHelpers.callInstanceMethod<Void>(activity, "setPkgPercent", ReflectionHelpers.ClassParameter.from(Int::class.javaPrimitiveType, 23))
val workerActivity = activity
val saved = save()
cancel()
recreate(saved)
ReflectionHelpers.setField(activity, "compatLaunchVisible", true)
protons.protonBusyId = null
advance()
assertNotNull(waiting())
assertNull(shadowOf(activity).nextStartedActivity)
assertEquals("Downloading AppImage", loading().step)
assertEquals(23, loading().percent)
android.os.Handler(Looper.getMainLooper()).post {
setString("setPkgStage", "Placing AppImage", workerActivity)
ReflectionHelpers.callInstanceMethod<Void>(workerActivity, "setPkgPercent", ReflectionHelpers.ClassParameter.from(Int::class.javaPrimitiveType, 90))
}
advance()
assertEquals("Placing AppImage", loading().step)
assertEquals(90, loading().percent)
assertNull(shadowOf(activity).nextStartedActivity)
android.os.Handler(Looper.getMainLooper()).post { setString("setPkgStage", null, workerActivity) }
advance()
assertEquals("first", shadowOf(activity).nextStartedActivity.getStringExtra(SessionService.EXTRA_STEAM_URL))
advance()
assertNull(shadowOf(activity).nextStartedActivity)
}
@Test fun aFailedInstallAfterRecreationKeepsItsProgressAndError() = recreationFailure(false)
@Test fun aFailedInstallBeforeRestorationStillShowsItsError() = recreationFailure(true)
private fun recreationFailure(finishBeforeRestore: Boolean) {
val entered = CountDownLatch(1)
val finish = CountDownLatch(1)
protons.protonBusyId = null
protons.installer = { _, progress ->
progress("Verifying download", 64)
entered.countDown()
check(finish.await(5, TimeUnit.SECONDS))
"Checksum verification failed"
}
try {
protons.installProton("droiddeck")
assertTrue(entered.await(5, TimeUnit.SECONDS))
activity.startActivity(request("first"))
val saved = save()
cancel()
if (finishBeforeRestore) {
finish.countDown()
waitForInstall()
}
recreate(saved)
if (!finishBeforeRestore) {
advance()
assertEquals(64, loading().percent)
finish.countDown()
waitForInstall()
}
ReflectionHelpers.setField(activity, "compatLaunchVisible", true)
advance()
assertEquals("Checksum verification failed", loading().step)
assertTrue(loading().ended)
assertNull(shadowOf(activity).nextStartedActivity)
} finally {
finish.countDown()
waitForInstall()
}
}
private fun waitForInstall() {
val deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(5)
while (protons.protonBusyId != null && System.nanoTime() < deadline) {
shadowOf(Looper.getMainLooper()).idle()
Thread.sleep(10)
}
assertNull(protons.protonBusyId)
}
private fun save() = Bundle().also {
ReflectionHelpers.callInstanceMethod<Void>(activity, "saveCompatLaunch", ReflectionHelpers.ClassParameter.from(Bundle::class.java, it))
}
private fun recreate(saved: Bundle) {
activity = Robolectric.buildActivity(FrontEndActivity::class.java).get()
protons = ReflectionHelpers.getField(activity, "protons")
ReflectionHelpers.callInstanceMethod<Void>(activity, "restoreCompatLaunch", ReflectionHelpers.ClassParameter.from(Bundle::class.java, saved))
}
private fun setString(method: String, value: String?, target: FrontEndActivity = activity) {
ReflectionHelpers.callInstanceMethod<Void>(target, method, ReflectionHelpers.ClassParameter.from(String::class.java, value))
}
private fun request(url: String) = Intent(activity, SessionActivity::class.java).putExtra(SessionService.EXTRA_STEAM_URL, url)
private fun installing(on: Boolean) = ReflectionHelpers.setStaticField(ProtonExtras::class.java, "installInProgress", on)
private fun waiting(): Any? = ReflectionHelpers.callInstanceMethod(activity, "getCompatLaunch")
private fun loading(): LoadingState = ReflectionHelpers.getField(requireNotNull(waiting()), "loading")
private fun cancel() { ReflectionHelpers.callInstanceMethod<Void>(activity, "cancelCompatLaunch") }
private fun advance() = shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(250))
}
@@ -56,6 +56,10 @@ class ProtonMenuAutoTest {
.put("tag", "${tool.prefix}-11-12").put("at", System.currentTimeMillis()))
File(activity.filesDir, "proton-latest.json").writeText(latest.toString())
menu = ProtonMenu(activity, Handler(Looper.getMainLooper())) { idle }
menu.protonBusyId = null
menu.protonProblem = null
menu.protonStage = null
menu.protonPercent = -1
menu.installer = { tool, progress ->
progress("Installing ${tool.name}", 50)
install("${tool.prefix}-11-12")
@@ -64,6 +68,10 @@ class ProtonMenuAutoTest {
}
@After fun reset() {
menu.protonBusyId = null
menu.protonProblem = null
menu.protonStage = null
menu.protonPercent = -1
AutoComponents.online = online
AutoComponents.unfavourable = constrained
SessionState.running = false