From 711413c52fa73c7d3cfdc5c2dca455412bffd469 Mon Sep 17 00:00:00 2001 From: Gravita Date: Mon, 2 Aug 2021 02:51:38 +0700 Subject: [PATCH] [FIX] Try fix Downloader cancel() --- .../src/main/java11/pro/gravit/utils/Downloader.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/LauncherCore/src/main/java11/pro/gravit/utils/Downloader.java b/LauncherCore/src/main/java11/pro/gravit/utils/Downloader.java index 44dcc17a..7f3445cf 100644 --- a/LauncherCore/src/main/java11/pro/gravit/utils/Downloader.java +++ b/LauncherCore/src/main/java11/pro/gravit/utils/Downloader.java @@ -189,6 +189,7 @@ public static class ProgressTrackingBodyHandler implements HttpResponse.BodyH private final HttpResponse.BodyHandler delegate; private final DownloadCallback callback; private ProgressTrackingBodySubscriber subscriber; + private boolean isCanceled = false; public ProgressTrackingBodyHandler(HttpResponse.BodyHandler delegate, DownloadCallback callback) { this.delegate = delegate; @@ -198,10 +199,14 @@ public ProgressTrackingBodyHandler(HttpResponse.BodyHandler delegate, Downloa @Override public HttpResponse.BodySubscriber apply(HttpResponse.ResponseInfo responseInfo) { subscriber = new ProgressTrackingBodySubscriber(delegate.apply(responseInfo)); + if (isCanceled) { + subscriber.cancel(); + } return subscriber; } public void cancel() { + isCanceled = true; if (subscriber != null) { subscriber.cancel(); } @@ -210,6 +215,7 @@ public void cancel() { private class ProgressTrackingBodySubscriber implements HttpResponse.BodySubscriber { private final HttpResponse.BodySubscriber delegate; private Flow.Subscription subscription; + private boolean isCanceled = false; public ProgressTrackingBodySubscriber(HttpResponse.BodySubscriber delegate) { this.delegate = delegate; @@ -223,6 +229,9 @@ public CompletionStage getBody() { @Override public void onSubscribe(Flow.Subscription subscription) { this.subscription = subscription; + if (isCanceled) { + subscription.cancel(); + } delegate.onSubscribe(subscription); } @@ -247,6 +256,7 @@ public void onComplete() { } public void cancel() { + isCanceled = true; if (subscription != null) { subscription.cancel(); }