fix: exclude pending launches and retain Proton update cooldowns

This commit is contained in:
Kurt Himebauch committed 2026-10-24 19:50:10 -04:00
1 parent 8a948fbe45
commit b56ea6122a
3 files changed
+63 -6

No files matched your search

@@ -1,12 +1,16 @@
package com.droiddeck.launcher
import android.app.Activity
import android.content.Intent
import android.os.Handler
import android.os.Looper
import androidx.compose.ui.geometry.Rect
import com.droiddeck.launcher.frontend.AutoComponents
import com.droiddeck.launcher.runtime.LinuxRuntime
import com.droiddeck.launcher.session.ProtonExtras
import com.droiddeck.launcher.session.SessionState
import com.droiddeck.launcher.ui.LaunchOrigin
import com.droiddeck.launcher.ui.Motion
import org.json.JSONObject
import org.junit.After
import org.junit.Assert.*
@@ -17,6 +21,7 @@ import org.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner
import org.robolectric.Shadows.shadowOf
import org.robolectric.annotation.Config
import org.robolectric.util.ReflectionHelpers
import java.io.File
@RunWith(RobolectricTestRunner::class)
@@ -39,6 +44,8 @@ class ProtonMenuAutoTest {
AutoComponents.online = { true }
AutoComponents.unfavourable = { false }
SessionState.running = false
LaunchOrigin.take()
LaunchOrigin.flooding = null
val latest = JSONObject()
for (tool in ProtonExtras.tools) latest.put(tool.id, JSONObject()
.put("tag", "${tool.prefix}-11-12").put("at", System.currentTimeMillis()))
@@ -55,6 +62,8 @@ class ProtonMenuAutoTest {
AutoComponents.online = online
AutoComponents.unfavourable = constrained
SessionState.running = false
LaunchOrigin.take()
LaunchOrigin.flooding = null
}
private fun install(name: String): File = File(root, "root/.local/share/Steam/compatibilitytools.d/$name").apply {
@@ -141,4 +150,46 @@ class ProtonMenuAutoTest {
assertTrue(attempts.isEmpty())
assertNull(menu.protonBusyId)
}
@Test fun aFailedReleaseIsNotRetriedAfterRecreatingTheLauncher() {
install("DroidDeck-Proton-11-11.1")
menu.installer = { tool, _ -> attempts.add(tool.id); "failed" }
menu.ensureAutoUpdates()
waitUntil { menu.protonBusyId == null }
val recreated = Robolectric.buildActivity(Activity::class.java).setup().get()
val next = ProtonMenu(recreated, Handler(Looper.getMainLooper()))
next.installer = { tool, _ -> attempts.add(tool.id); "failed" }
next.ensureAutoUpdates()
assertNull(next.protonBusyId)
assertEquals(listOf("droiddeck"), attempts)
}
@Test fun aPendingAnimatedLaunchPreventsAnAutomaticInstall() {
install("DroidDeck-Proton-11-11.1")
val launcher = Robolectric.buildActivity(FrontEndActivity::class.java).get()
val protons = ReflectionHelpers.getField<ProtonMenu>(launcher, "protons")
protons.installer = { tool, _ -> attempts.add(tool.id); "failed" }
Motion.refresh(launcher)
LaunchOrigin.mark(Rect(0f, 0f, 100f, 100f), "game")
launcher.startActivity(Intent(launcher, SessionActivity::class.java))
assertNotNull(ReflectionHelpers.callInstanceMethod<Any?>(launcher, "getFlood"))
assertNull(shadowOf(launcher).nextStartedActivity)
protons.ensureAutoUpdates()
assertNull(protons.protonBusyId)
assertTrue(attempts.isEmpty())
}
@Test fun anAnimatedLaunchRechecksTheProtonInstallGuardBeforeStarting() {
val launcher = Robolectric.buildActivity(FrontEndActivity::class.java).get()
Motion.refresh(launcher)
LaunchOrigin.mark(Rect(0f, 0f, 100f, 100f), "game")
launcher.startActivity(Intent(launcher, SessionActivity::class.java))
val pending = requireNotNull(ReflectionHelpers.callInstanceMethod<Any?>(launcher, "getFlood"))
ReflectionHelpers.getField<ProtonMenu>(launcher, "protons").protonBusyId = "droiddeck"
FrontEndActivity::class.java.getDeclaredMethod("launchFlooded", pending.javaClass)
.apply { isAccessible = true }.invoke(launcher, pending)
assertNull(shadowOf(launcher).nextStartedActivity)
assertNull(ReflectionHelpers.callInstanceMethod<Any?>(launcher, "getFlood"))
assertNull(LaunchOrigin.flooding)
}
}