diff --git a/app/src/main/java/com/droiddeck/launcher/MainActivity.kt b/app/src/main/java/com/droiddeck/launcher/MainActivity.kt index ff22490c29..5d43f9dd23 100644 --- a/app/src/main/java/com/droiddeck/launcher/MainActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/MainActivity.kt @@ -1997,6 +1997,10 @@ class MainActivity : ComponentActivity() { private fun startSession(intent: Intent, steamSession: Boolean = false): Boolean { if (busy || LinuxRuntimeInstaller.isBusy()) return false + if (SessionState.installing != null && !SessionState.running) { + android.widget.Toast.makeText(this, R.string.main_wait_desktop_install, android.widget.Toast.LENGTH_SHORT).show() + return false + } if (com.droiddeck.launcher.storage.StorageState.cleaning) { android.widget.Toast.makeText(this, R.string.storage_cleanup_busy, android.widget.Toast.LENGTH_SHORT).show() return false diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index cd1ed6367f..97ef4d4041 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -1326,10 +1326,14 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { } - private val installingRuntime get() = SessionState.installing != null + private var localInstalling = false + private val installingRuntime get() = localInstalling || SessionState.installing != null private fun installThenStart(runtime: Boolean, desktop: Boolean, proton: Boolean = false) { if (SessionState.stopRequested) return + val worker = Any() + activeInstallWorker = worker + localInstalling = true SessionState.installing = if (runtime) "runtime" else if (desktop) "desktop" else "proton" SessionEvents.transition( SessionPhase.INSTALLING_RUNTIME, @@ -1347,22 +1351,26 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { if (problem == null) SessionEvents.record("runtime.ready") else failedComponent = "runtime" } if (problem == null && desktop && !SessionState.stopRequested) { - SessionState.installing = "desktop" + if (activeInstallWorker === worker) SessionState.installing = "desktop" SessionEvents.transition(SessionPhase.INSTALLING_RUNTIME, "desktop.installing", mapOf("component" to "desktop")) problem = installDesktop() if (problem == null) SessionEvents.record("desktop.ready") else failedComponent = "desktop" } if (problem == null && proton && !SessionState.stopRequested) { - SessionState.installing = "proton" + if (activeInstallWorker === worker) SessionState.installing = "proton" SessionEvents.transition(SessionPhase.INSTALLING_RUNTIME, "proton.installing", mapOf("component" to "proton")) val protonProblem = installProton() if (protonProblem == null) SessionEvents.record("proton.ready") else SessionEvents.record("proton.skipped", mapOf("reason" to protonProblem)) } uiHandler.post { - SessionState.installing = null + localInstalling = false + if (activeInstallWorker === worker) { + activeInstallWorker = null + SessionState.installing = null + } if (SessionState.stopRequested) { - SessionState.stopRequested = false + if (activeInstallWorker == null) SessionState.stopRequested = false SessionEvents.transition(SessionPhase.IDLE, "session.cancelled") collectStartArtifacts("session start cancelled") finish() @@ -3195,6 +3203,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { private const val LEAVE_TIMEOUT_MS = 1_500L private const val TAG = "SessionActivity" private var startedScreens = 0 + @Volatile private var activeInstallWorker: Any? = null private const val FEX_MISSING = "droiddeck-fex: x86 Linux programs need" private const val UNBUFFERED_SOURCES = InputDevice.SOURCE_CLASS_JOYSTICK or InputDevice.SOURCE_CLASS_TRACKBALL or InputDevice.SOURCE_CLASS_POSITION private const val CURSOR_PAD_HOLD_MS = 1200L diff --git a/app/src/main/java/com/droiddeck/launcher/core/Downloader.java b/app/src/main/java/com/droiddeck/launcher/core/Downloader.java index acad82b853..a924667383 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/Downloader.java +++ b/app/src/main/java/com/droiddeck/launcher/core/Downloader.java @@ -172,6 +172,7 @@ public final class Downloader { private static Outcome attempt(String url, File destination, boolean resume, Identity identity, String expectedSha256, java.util.function.BooleanSupplier cancelled, java.util.function.Consumer progress) { + if (isCancelled(cancelled)) return Outcome.CANCELLED; HttpURLConnection connection = null; long have = resume && destination.isFile() ? destination.length() : 0; try { @@ -237,6 +238,7 @@ public final class Downloader { } } } + if (isCancelled(cancelled)) return Outcome.CANCELLED; if (total > 0 && written < total) return Outcome.RETRY; return Outcome.DONE; } catch (Exception e) {