From b56ea6122a7d92225d2777f5ad16482e15a8884e Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Sat, 24 Oct 2026 16:58:29 -0400 Subject: [PATCH] fix: exclude pending launches and retain Proton update cooldowns --- .../droiddeck/launcher/FrontEndActivity.kt | 10 +++- .../java/com/droiddeck/launcher/ProtonMenu.kt | 8 +-- .../droiddeck/launcher/ProtonMenuAutoTest.kt | 51 +++++++++++++++++++ 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt index 7083dcc360..e2ce59eff8 100644 --- a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt @@ -91,7 +91,7 @@ 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 && pkgStage == null && components.compBusy == null } + private val protons = ProtonMenu(this, ui) { !busy && flood == null && pkgStage == null && components.compBusy == null } private var installed by mutableStateOf(null) private var flood by mutableStateOf(null) @@ -460,7 +460,13 @@ class FrontEndActivity : ComponentActivity() { } private fun launchFlooded(f: PendingFlood) { - if (busy || LinuxRuntimeInstaller.isBusy()) { flood = null; floodProgress = 0f; return } + if (busy || LinuxRuntimeInstaller.isBusy() || protons.protonBusyId != null || + ProtonExtras.installInProgress || pkgStage != null) { + flood = null + floodProgress = 0f + com.droiddeck.launcher.ui.LaunchOrigin.flooding = null + return + } val signal = com.droiddeck.launcher.ui.Themes.byId(theme).signal super.startActivity(f.intent.putExtra(com.droiddeck.launcher.ui.EXTRA_FLOOD, signal.toArgb())) overridePendingTransition(0, 0) diff --git a/app/src/main/java/com/droiddeck/launcher/ProtonMenu.kt b/app/src/main/java/com/droiddeck/launcher/ProtonMenu.kt index 6bb28bc6cd..a226f53cde 100644 --- a/app/src/main/java/com/droiddeck/launcher/ProtonMenu.kt +++ b/app/src/main/java/com/droiddeck/launcher/ProtonMenu.kt @@ -24,7 +24,6 @@ internal class ProtonMenu( var protonStage by mutableStateOf(null) var protonPercent by mutableIntStateOf(-1) private val checking = java.util.concurrent.atomic.AtomicBoolean(false) - private val autoAttempts = HashMap>() @VisibleForTesting internal var installer: (ProtonExtras.Tool, (String, Int) -> Unit) -> String? = { tool, progress -> ProtonExtras.install(activity, tool, progress) } @@ -93,12 +92,13 @@ internal class ProtonMenu( if (activity.isFinishing || activity.isDestroyed || !idle() || protonBusyId != null || ProtonExtras.installInProgress || SessionState.running || LinuxRuntimeInstaller.isBusy() || !LinuxRuntime.isInstalled(activity) || !AutoComponents.online(activity) || AutoComponents.unfavourable(activity)) return + val attempts = activity.getSharedPreferences("proton-auto-updates", android.content.Context.MODE_PRIVATE) val (tool, update) = ProtonExtras.tools.firstNotNullOfOrNull { tool -> val update = ProtonExtras.update(activity, tool) ?: return@firstNotNullOfOrNull null - val previous = autoAttempts[tool.id] - if (previous == null || previous.first != update || now - previous.second !in 0 until 15L * 60 * 1000) tool to update else null + val previous = attempts.getLong("${tool.id}.at", 0L) + if (attempts.getString("${tool.id}.tag", null) != update || now - previous !in 0 until 15L * 60 * 1000) tool to update else null } ?: return - autoAttempts[tool.id] = update to now + attempts.edit().putString("${tool.id}.tag", update).putLong("${tool.id}.at", now).apply() installProton(tool.id, automatic = true) } } diff --git a/app/src/test/java/com/droiddeck/launcher/ProtonMenuAutoTest.kt b/app/src/test/java/com/droiddeck/launcher/ProtonMenuAutoTest.kt index 124fd4e665..87fd554a64 100644 --- a/app/src/test/java/com/droiddeck/launcher/ProtonMenuAutoTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/ProtonMenuAutoTest.kt @@ -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(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(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(launcher, "getFlood")) + ReflectionHelpers.getField(launcher, "protons").protonBusyId = "droiddeck" + FrontEndActivity::class.java.getDeclaredMethod("launchFlooded", pending.javaClass) + .apply { isAccessible = true }.invoke(launcher, pending) + assertNull(shadowOf(launcher).nextStartedActivity) + assertNull(ReflectionHelpers.callInstanceMethod(launcher, "getFlood")) + assertNull(LaunchOrigin.flooding) + } }