fix(task): wrong cancellation implementation. Closes #1035.

This commit is contained in:
huanghongxun
2021-09-17 17:35:24 +08:00
parent e10e1e0613
commit 390f6e016d
6 changed files with 38 additions and 22 deletions

View File

@@ -57,6 +57,7 @@ import org.jetbrains.annotations.Nullable;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CancellationException;
import static org.jackhuang.hmcl.ui.FXUtils.runInFX;
import static org.jackhuang.hmcl.ui.versions.VersionPage.wrap;
@@ -166,9 +167,13 @@ public class DownloadPage extends BorderPane implements DecoratorPage {
FileDownloadTask task = new FileDownloadTask(NetworkUtils.toURL(file.getFile().getUrl()), dest.toFile());
task.setName(file.getName());
return task;
}).whenComplete(exception -> {
}).whenComplete(Schedulers.javafx(), exception -> {
if (exception != null) {
Controllers.dialog(DownloadProviders.localizeErrorMessage(exception), i18n("install.failed.downloading"), MessageDialogPane.MessageType.ERROR);
if (exception instanceof CancellationException) {
Controllers.showToast(i18n("message.cancelled"));
} else {
Controllers.dialog(DownloadProviders.localizeErrorMessage(exception), i18n("install.failed.downloading"), MessageDialogPane.MessageType.ERROR);
}
} else {
Controllers.showToast(i18n("install.success"));
}

View File

@@ -420,6 +420,7 @@ logwindow.export_game_crash_logs=Export game crash info
main_page=Home
message.cancelled=Operation was cancelled
message.confirm=Confirm
message.copied=Copied to clipboard
message.doing=Please wait

View File

@@ -420,6 +420,7 @@ logwindow.export_game_crash_logs=導出遊戲崩潰訊息
main_page=首頁
message.cancelled=操作被取消
message.confirm=提示
message.copied=已複製到剪貼板
message.doing=請耐心等待

View File

@@ -420,6 +420,7 @@ logwindow.export_game_crash_logs=导出游戏崩溃信息
main_page=主页
message.cancelled=操作被取消
message.confirm=提示
message.copied=已复制到剪贴板
message.doing=请耐心等待