fix: cancel Proton seed downloads promptly

This commit is contained in:
xXJsonDeruloXx committed 2026-10-22 09:57:45 -04:00
1 parent c02832ac59
commit 0ab2172857
3 files changed
+25 -4

No files matched your search

@@ -1452,7 +1452,13 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
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"
return catalog.install(this, entry, { SessionState.stopRequested }, progressFor(PROTON_LINES, entry.size / 1_000_000))
val cancellation = com.droiddeck.launcher.core.Downloader.Cancellation { SessionState.stopRequested }
SessionState.installCancellation = cancellation
return try {
catalog.install(this, entry, cancellation, progressFor(PROTON_LINES, entry.size / 1_000_000))
} finally {
if (SessionState.installCancellation === cancellation) SessionState.installCancellation = null
}
}
override fun surfaceCreated(holder: SurfaceHolder) {
@@ -23,6 +23,12 @@ public final class Downloader {
private static final int CONNECT_TIMEOUT_MS = 10_000;
private static final int STALL_TIMEOUT_MS = 15_000;
private static final int HTTP_RANGE_NOT_SATISFIABLE = 416;
private static final java.util.concurrent.ExecutorService CANCEL_EXECUTOR =
java.util.concurrent.Executors.newCachedThreadPool(r -> {
Thread thread = new Thread(r, "download-cancel");
thread.setDaemon(true);
return thread;
});
private Downloader() {}
@@ -37,7 +43,13 @@ public final class Downloader {
public void cancel() {
cancelled.set(true);
HttpURLConnection active = connection.get();
if (active != null) active.disconnect();
if (active != null) disconnectAsync(active);
}
private static void disconnectAsync(HttpURLConnection active) {
CANCEL_EXECUTOR.execute(() -> {
try { active.disconnect(); } catch (RuntimeException ignored) { }
});
}
@Override public boolean getAsBoolean() {
@@ -46,7 +58,7 @@ public final class Downloader {
private void attach(HttpURLConnection active) {
connection.set(active);
if (getAsBoolean()) active.disconnect();
if (getAsBoolean()) disconnectAsync(active);
}
private void detach(HttpURLConnection active) { connection.compareAndSet(active, null); }