finalized no longer passes AutoTypingMap as callback parameter

This commit is contained in:
huanghongxun 2019-02-23 21:16:43 +08:00
parent 7c89fac1e9
commit fff7abc2ac
14 changed files with 27 additions and 49 deletions

View File

@ -110,13 +110,13 @@ public final class ModpackHelper {
if (modpack.getManifest() instanceof CurseManifest)
return new CurseInstallTask(profile.getDependency(), zipFile, modpack, ((CurseManifest) modpack.getManifest()), name)
.finalized(Schedulers.defaultScheduler(), ExceptionalConsumer.fromRunnable(success), failure);
.finalized(Schedulers.defaultScheduler(), success, failure);
else if (modpack.getManifest() instanceof HMCLModpackManifest)
return new HMCLModpackInstallTask(profile, zipFile, modpack, name)
.finalized(Schedulers.defaultScheduler(), ExceptionalConsumer.fromRunnable(success), failure);
.finalized(Schedulers.defaultScheduler(), success, failure);
else if (modpack.getManifest() instanceof MultiMCInstanceConfiguration)
return new MultiMCModpackInstallTask(profile.getDependency(), zipFile, modpack, ((MultiMCInstanceConfiguration) modpack.getManifest()), name)
.finalized(Schedulers.defaultScheduler(), ExceptionalConsumer.fromRunnable(success), failure)
.finalized(Schedulers.defaultScheduler(), success, failure)
.then(new MultiMCInstallVersionSettingTask(profile, ((MultiMCInstanceConfiguration) modpack.getManifest()), name));
else throw new IllegalStateException("Unrecognized modpack: " + modpack);
}

View File

@ -62,7 +62,7 @@ public class AccountLoginPane extends StackPane {
progressBar.setVisible(true);
lblCreationWarning.setText("");
Task.ofResult(() -> oldAccount.logInWithPassword(password))
.finalizedResult(Schedulers.javafx(), authInfo -> {
.finalized(Schedulers.javafx(), authInfo -> {
success.accept(authInfo);
fireEvent(new DialogCloseEvent());
progressBar.setVisible(false);

View File

@ -196,7 +196,7 @@ public class AddAccountPane extends StackPane {
Object additionalData = getAuthAdditionalData();
Task.ofResult(() -> factory.create(new Selector(), username, password, additionalData))
.finalizedResult(Schedulers.javafx(), account -> {
.finalized(Schedulers.javafx(), account -> {
int oldIndex = Accounts.getAccounts().indexOf(account);
if (oldIndex == -1) {
Accounts.getAccounts().add(account);

View File

@ -106,7 +106,7 @@ public class AddAuthlibInjectorServerPane extends StackPane implements DialogAwa
Task.of(() -> {
serverBeingAdded = AuthlibInjectorServer.locateServer(url);
}).finalized(Schedulers.javafx(), (variables, isDependentsSucceeded, exception) -> {
}).finalized(Schedulers.javafx(), (isDependentsSucceeded, exception) -> {
addServerPane.setDisable(false);
nextPane.hideSpinner();

View File

@ -111,7 +111,7 @@ public final class ModpackPage extends StackPane implements WizardPage {
spinnerPane.showSpinner();
Task.ofResult(() -> CompressingUtils.findSuitableEncoding(selectedFile.toPath()))
.thenResult(encoding -> manifest = ModpackHelper.readModpackManifest(selectedFile.toPath(), encoding))
.finalizedResult(Schedulers.javafx(), manifest -> {
.finalized(Schedulers.javafx(), manifest -> {
spinnerPane.hideSpinner();
controller.getSettings().put(MODPACK_MANIFEST, manifest);
lblName.setText(manifest.getName());

View File

@ -59,7 +59,7 @@ public final class VanillaInstallWizardProvider implements WizardProvider {
if (settings.containsKey("optifine"))
builder.version((RemoteVersion) settings.get("optifine"));
return builder.buildAsync().finalized((a, b, c) -> profile.getRepository().refreshVersions())
return builder.buildAsync().finalized((a, b) -> profile.getRepository().refreshVersions())
.then(Task.of(Schedulers.javafx(), () -> profile.setSelectedVersion(name)));
}

View File

@ -128,7 +128,7 @@ public final class VersionsPage extends BorderPane implements WizardPage, Refres
@Override
public void refresh() {
transitionHandler.setContent(spinner, ContainerAnimations.FADE.getAnimationProducer());
executor = versionList.refreshAsync(gameVersion, downloadProvider).finalized((variables, isDependentsSucceeded, exception) -> {
executor = versionList.refreshAsync(gameVersion, downloadProvider).finalized((isDependentsSucceeded, exception) -> {
if (isDependentsSucceeded) {
List<VersionsPageItem> items = loadVersions();

View File

@ -92,7 +92,7 @@ public final class ModListPage extends Control {
modManager.refreshMods();
return new LinkedList<>(modManager.getMods());
}
}).finalizedResult(Schedulers.javafx(), (list, isDependentsSucceeded, exception) -> {
}).finalized(Schedulers.javafx(), (list, isDependentsSucceeded, exception) -> {
loadingProperty().set(false);
if (isDependentsSucceeded)
FXUtils.onWeakChangeAndOperate(parentTab.getSelectionModel().selectedItemProperty(), newValue -> {

View File

@ -29,7 +29,6 @@ import org.jackhuang.hmcl.util.Logging;
import org.jackhuang.hmcl.util.io.FileUtils;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Path;
import java.util.List;
@ -52,7 +51,7 @@ public class WorldListPage extends ListPage<WorldListItem> {
setLoading(true);
Task.ofResult(() -> World.getWorlds(savesDir).parallel().collect(Collectors.toList()))
.finalizedResult(Schedulers.javafx(), (result, isDependentsSucceeded, exception) -> {
.finalized(Schedulers.javafx(), (result, isDependentsSucceeded, exception) -> {
setLoading(false);
if (isDependentsSucceeded)
itemsProperty().setAll(result.stream().map(WorldListItem::new).collect(Collectors.toList()));
@ -74,10 +73,10 @@ public class WorldListPage extends ListPage<WorldListItem> {
// Only accept one world file because user is required to confirm the new world name
// Or too many input dialogs are popped.
Task.ofResult(() -> new World(zipFile.toPath()))
.finalizedResult(Schedulers.javafx(), world -> {
.finalized(Schedulers.javafx(), world -> {
Controllers.inputDialog(i18n("world.name.enter"), (name, resolve, reject) -> {
Task.of(() -> world.install(savesDir, name))
.finalized(Schedulers.javafx(), var -> {
.finalized(Schedulers.javafx(), () -> {
itemsProperty().add(new WorldListItem(new World(savesDir.resolve(name))));
resolve.run();
}, e -> {

View File

@ -69,7 +69,7 @@ public class DefaultGameBuilder extends GameBuilder {
result = result.then(dependencyManager.installLibraryAsync(remoteVersion));
return result;
}).finalized((variables, isDependentsSucceeded, exception) -> {
}).finalized((isDependentsSucceeded, exception) -> {
if (!isDependentsSucceeded)
dependencyManager.getGameRepository().getVersionRoot(name).delete();
});

View File

@ -1,24 +0,0 @@
/*
* Hello Minecraft! Launcher
* Copyright (C) 2019 huangyuhui <huanghongxun2008@126.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.jackhuang.hmcl.task;
import org.jackhuang.hmcl.util.AutoTypingMap;
public interface FinalizedCallback {
void execute(AutoTypingMap<String> variables, boolean isDependentsSucceeded, Exception exception) throws Exception;
}

View File

@ -53,7 +53,7 @@ final class FinalizedTask extends Task {
@Override
public void execute() throws Exception {
callback.execute(getVariables(), isDependentsSucceeded(), pred.getLastException());
callback.execute(isDependentsSucceeded(), pred.getLastException());
if (!isDependentsSucceeded())
throw new SilentException();

View File

@ -320,12 +320,13 @@ public abstract class Task {
return new FinalizedTask(this, scheduler, b, ReflectionHelper.getCaller().toString());
}
public final <T extends Exception, K extends Exception> Task finalized(Scheduler scheduler, ExceptionalConsumer<AutoTypingMap<String>, T> success, ExceptionalConsumer<Exception, K> failure) {
return finalized(scheduler, (variables, isDependentsSucceeded, exception) -> {
// T, K here is necessary, or javac cannot infer type of failure
public final <T extends Exception, K extends Exception> Task finalized(Scheduler scheduler, ExceptionalRunnable<T> success, ExceptionalConsumer<Exception, K> failure) {
return finalized(scheduler, (isDependentsSucceeded, exception) -> {
if (isDependentsSucceeded) {
if (success != null)
try {
success.accept(variables);
success.run();
} catch (Exception e) {
Logging.LOG.log(Level.WARNING, "Failed to execute " + success, e);
if (failure != null)
@ -421,4 +422,8 @@ public abstract class Task {
SUCCEEDED,
FAILED
}
public interface FinalizedCallback {
void execute(boolean isDependentsSucceeded, Exception exception) throws Exception;
}
}

View File

@ -55,14 +55,12 @@ public abstract class TaskResult<V> extends Task {
return new Subtask<>(id, scheduler, task);
}
public <T extends Exception, K extends Exception> Task finalizedResult(Scheduler scheduler, ExceptionalConsumer<V, T> success, ExceptionalConsumer<Exception, K> failure) {
return finalized(scheduler, variables -> success.accept(getResult()), failure);
public <T extends Exception, K extends Exception> Task finalized(Scheduler scheduler, ExceptionalConsumer<V, T> success, ExceptionalConsumer<Exception, K> failure) {
return finalized(scheduler, () -> success.accept(getResult()), failure);
}
public Task finalizedResult(Scheduler scheduler, FinalizedCallback<V> callback) {
return new FinalizedTask(this, scheduler,
(variables, isDependentsSucceeded, exception) -> callback.execute(getResult(), isDependentsSucceeded, exception),
ReflectionHelper.getCaller().toString());
public Task finalized(Scheduler scheduler, FinalizedCallback<V> callback) {
return finalized(scheduler, ((isDependentsSucceeded, exception) -> callback.execute(getResult(), isDependentsSucceeded, exception)));
}
private class Subtask<R> extends TaskResult<R> {