From 62d218fe3751b66665bab602449cf6bbaa88b54a Mon Sep 17 00:00:00 2001 From: ovurrsl Date: Thu, 22 Oct 2026 19:36:10 +0300 Subject: [PATCH] fix: cancelling the first-run Proton install also stops its catalog download installProton fetched the catalog before its cancellation existed, so a stop had to wait for the catalog request. The cancellation is now registered first and passed through DesktopCatalog.fetch to a cancellable downloadString, which disconnects the request and does not count a cancelled fetch as a source failure. --- .../com/droiddeck/launcher/SessionActivity.kt | 4 ++-- .../droiddeck/launcher/core/Downloader.java | 21 +++++++++++++++++-- .../launcher/runtime/DesktopCatalog.kt | 4 ++-- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index 48ca0d4de7..fb3edbb4ac 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -1635,11 +1635,11 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { private fun installProton(): String? { uiHandler.post { loading.percent = -1; loading.say(getString(PROTON_LINES.downloading), PROTON_LINES.topic, readable = true) } val catalog = com.droiddeck.launcher.runtime.DesktopCatalog - val entry = catalog.fetch(catalog.STEAM_SEED_URL)?.firstOrNull { it.id == catalog.PROTON_SEED_ID } - ?: return "catalog unreachable" val cancellation = com.droiddeck.launcher.core.Downloader.Cancellation { SessionState.stopRequested } SessionState.installCancellation = cancellation return try { + val entry = catalog.fetch(catalog.STEAM_SEED_URL, cancellation)?.firstOrNull { it.id == catalog.PROTON_SEED_ID } + ?: return if (cancellation.asBoolean) "cancelled" else "catalog unreachable" catalog.install(this, entry, cancellation, progressFor(PROTON_LINES, entry.size / 1_000_000)) } finally { if (SessionState.installCancellation === cancellation) SessionState.installCancellation = null 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 8a56876714..1b8f61c3fb 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/Downloader.java +++ b/app/src/main/java/com/droiddeck/launcher/core/Downloader.java @@ -65,10 +65,17 @@ public final class Downloader { } public static String downloadString(String url) { + return downloadString(url, null); + } + + public static String downloadString(String url, java.util.function.BooleanSupplier cancelled) { List sources = DownloadSource.INSTANCE.candidates(url); for (int i = 0; i < sources.size(); i++) { + if (isCancelled(cancelled)) return null; if (i > 0) Log.i(TAG, "retrying " + url + " via " + sources.get(i)); - Fetch fetch = fetch(sources.get(i)); + Fetch fetch = fetch(sources.get(i), cancelled); + // A cancelled fetch says nothing about the source, so it must not count as a failure. + if (isCancelled(cancelled)) return null; if (fetch.body != null) { DownloadSource.INSTANCE.succeeded(sources.get(i)); return fetch.body; @@ -325,9 +332,15 @@ public final class Downloader { } private static Fetch fetch(String url) { + return fetch(url, null); + } + + private static Fetch fetch(String url, java.util.function.BooleanSupplier cancelled) { HttpURLConnection connection = null; + Cancellation token = cancelled instanceof Cancellation ? (Cancellation) cancelled : null; try { connection = open(url, STALL_TIMEOUT_MS); + if (token != null) token.attach(connection); int code = connection.getResponseCode(); if (code / 100 != 2) { Log.w(TAG, url + " -> HTTP " + code); @@ -339,10 +352,14 @@ public final class Downloader { return new Fetch(new String(out.toByteArray(), StandardCharsets.UTF_8), false); } } catch (Exception e) { + if (isCancelled(cancelled)) return new Fetch(null, false); Log.w(TAG, "GET " + url, e); return new Fetch(null, false); } finally { - if (connection != null) connection.disconnect(); + if (connection != null) { + if (token != null) token.detach(connection); + connection.disconnect(); + } } } diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/DesktopCatalog.kt b/app/src/main/java/com/droiddeck/launcher/runtime/DesktopCatalog.kt index 30d33050d0..b7977a909d 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/DesktopCatalog.kt +++ b/app/src/main/java/com/droiddeck/launcher/runtime/DesktopCatalog.kt @@ -22,8 +22,8 @@ object DesktopCatalog { val icon: String, val category: String, ) - fun fetch(url: String = CATALOG_URL): List? { - val body = Downloader.downloadString(url) ?: return null + fun fetch(url: String = CATALOG_URL, cancelled: java.util.function.BooleanSupplier? = null): List? { + val body = Downloader.downloadString(url, cancelled) ?: return null return try { val json = JSONObject(body) val arr = json.getJSONArray("packages")