finalized no longer passes AutoTypingMap as callback parameter
This commit is contained in:
@@ -110,13 +110,13 @@ public final class ModpackHelper {
|
|||||||
|
|
||||||
if (modpack.getManifest() instanceof CurseManifest)
|
if (modpack.getManifest() instanceof CurseManifest)
|
||||||
return new CurseInstallTask(profile.getDependency(), zipFile, modpack, ((CurseManifest) modpack.getManifest()), name)
|
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)
|
else if (modpack.getManifest() instanceof HMCLModpackManifest)
|
||||||
return new HMCLModpackInstallTask(profile, zipFile, modpack, name)
|
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)
|
else if (modpack.getManifest() instanceof MultiMCInstanceConfiguration)
|
||||||
return new MultiMCModpackInstallTask(profile.getDependency(), zipFile, modpack, ((MultiMCInstanceConfiguration) modpack.getManifest()), name)
|
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));
|
.then(new MultiMCInstallVersionSettingTask(profile, ((MultiMCInstanceConfiguration) modpack.getManifest()), name));
|
||||||
else throw new IllegalStateException("Unrecognized modpack: " + modpack);
|
else throw new IllegalStateException("Unrecognized modpack: " + modpack);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ public class AccountLoginPane extends StackPane {
|
|||||||
progressBar.setVisible(true);
|
progressBar.setVisible(true);
|
||||||
lblCreationWarning.setText("");
|
lblCreationWarning.setText("");
|
||||||
Task.ofResult(() -> oldAccount.logInWithPassword(password))
|
Task.ofResult(() -> oldAccount.logInWithPassword(password))
|
||||||
.finalizedResult(Schedulers.javafx(), authInfo -> {
|
.finalized(Schedulers.javafx(), authInfo -> {
|
||||||
success.accept(authInfo);
|
success.accept(authInfo);
|
||||||
fireEvent(new DialogCloseEvent());
|
fireEvent(new DialogCloseEvent());
|
||||||
progressBar.setVisible(false);
|
progressBar.setVisible(false);
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ public class AddAccountPane extends StackPane {
|
|||||||
Object additionalData = getAuthAdditionalData();
|
Object additionalData = getAuthAdditionalData();
|
||||||
|
|
||||||
Task.ofResult(() -> factory.create(new Selector(), username, password, additionalData))
|
Task.ofResult(() -> factory.create(new Selector(), username, password, additionalData))
|
||||||
.finalizedResult(Schedulers.javafx(), account -> {
|
.finalized(Schedulers.javafx(), account -> {
|
||||||
int oldIndex = Accounts.getAccounts().indexOf(account);
|
int oldIndex = Accounts.getAccounts().indexOf(account);
|
||||||
if (oldIndex == -1) {
|
if (oldIndex == -1) {
|
||||||
Accounts.getAccounts().add(account);
|
Accounts.getAccounts().add(account);
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ public class AddAuthlibInjectorServerPane extends StackPane implements DialogAwa
|
|||||||
|
|
||||||
Task.of(() -> {
|
Task.of(() -> {
|
||||||
serverBeingAdded = AuthlibInjectorServer.locateServer(url);
|
serverBeingAdded = AuthlibInjectorServer.locateServer(url);
|
||||||
}).finalized(Schedulers.javafx(), (variables, isDependentsSucceeded, exception) -> {
|
}).finalized(Schedulers.javafx(), (isDependentsSucceeded, exception) -> {
|
||||||
addServerPane.setDisable(false);
|
addServerPane.setDisable(false);
|
||||||
nextPane.hideSpinner();
|
nextPane.hideSpinner();
|
||||||
|
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ public final class ModpackPage extends StackPane implements WizardPage {
|
|||||||
spinnerPane.showSpinner();
|
spinnerPane.showSpinner();
|
||||||
Task.ofResult(() -> CompressingUtils.findSuitableEncoding(selectedFile.toPath()))
|
Task.ofResult(() -> CompressingUtils.findSuitableEncoding(selectedFile.toPath()))
|
||||||
.thenResult(encoding -> manifest = ModpackHelper.readModpackManifest(selectedFile.toPath(), encoding))
|
.thenResult(encoding -> manifest = ModpackHelper.readModpackManifest(selectedFile.toPath(), encoding))
|
||||||
.finalizedResult(Schedulers.javafx(), manifest -> {
|
.finalized(Schedulers.javafx(), manifest -> {
|
||||||
spinnerPane.hideSpinner();
|
spinnerPane.hideSpinner();
|
||||||
controller.getSettings().put(MODPACK_MANIFEST, manifest);
|
controller.getSettings().put(MODPACK_MANIFEST, manifest);
|
||||||
lblName.setText(manifest.getName());
|
lblName.setText(manifest.getName());
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public final class VanillaInstallWizardProvider implements WizardProvider {
|
|||||||
if (settings.containsKey("optifine"))
|
if (settings.containsKey("optifine"))
|
||||||
builder.version((RemoteVersion) settings.get("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)));
|
.then(Task.of(Schedulers.javafx(), () -> profile.setSelectedVersion(name)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ public final class VersionsPage extends BorderPane implements WizardPage, Refres
|
|||||||
@Override
|
@Override
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
transitionHandler.setContent(spinner, ContainerAnimations.FADE.getAnimationProducer());
|
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) {
|
if (isDependentsSucceeded) {
|
||||||
List<VersionsPageItem> items = loadVersions();
|
List<VersionsPageItem> items = loadVersions();
|
||||||
|
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ public final class ModListPage extends Control {
|
|||||||
modManager.refreshMods();
|
modManager.refreshMods();
|
||||||
return new LinkedList<>(modManager.getMods());
|
return new LinkedList<>(modManager.getMods());
|
||||||
}
|
}
|
||||||
}).finalizedResult(Schedulers.javafx(), (list, isDependentsSucceeded, exception) -> {
|
}).finalized(Schedulers.javafx(), (list, isDependentsSucceeded, exception) -> {
|
||||||
loadingProperty().set(false);
|
loadingProperty().set(false);
|
||||||
if (isDependentsSucceeded)
|
if (isDependentsSucceeded)
|
||||||
FXUtils.onWeakChangeAndOperate(parentTab.getSelectionModel().selectedItemProperty(), newValue -> {
|
FXUtils.onWeakChangeAndOperate(parentTab.getSelectionModel().selectedItemProperty(), newValue -> {
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import org.jackhuang.hmcl.util.Logging;
|
|||||||
import org.jackhuang.hmcl.util.io.FileUtils;
|
import org.jackhuang.hmcl.util.io.FileUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.FileAlreadyExistsException;
|
import java.nio.file.FileAlreadyExistsException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -52,7 +51,7 @@ public class WorldListPage extends ListPage<WorldListItem> {
|
|||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
Task.ofResult(() -> World.getWorlds(savesDir).parallel().collect(Collectors.toList()))
|
Task.ofResult(() -> World.getWorlds(savesDir).parallel().collect(Collectors.toList()))
|
||||||
.finalizedResult(Schedulers.javafx(), (result, isDependentsSucceeded, exception) -> {
|
.finalized(Schedulers.javafx(), (result, isDependentsSucceeded, exception) -> {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
if (isDependentsSucceeded)
|
if (isDependentsSucceeded)
|
||||||
itemsProperty().setAll(result.stream().map(WorldListItem::new).collect(Collectors.toList()));
|
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
|
// Only accept one world file because user is required to confirm the new world name
|
||||||
// Or too many input dialogs are popped.
|
// Or too many input dialogs are popped.
|
||||||
Task.ofResult(() -> new World(zipFile.toPath()))
|
Task.ofResult(() -> new World(zipFile.toPath()))
|
||||||
.finalizedResult(Schedulers.javafx(), world -> {
|
.finalized(Schedulers.javafx(), world -> {
|
||||||
Controllers.inputDialog(i18n("world.name.enter"), (name, resolve, reject) -> {
|
Controllers.inputDialog(i18n("world.name.enter"), (name, resolve, reject) -> {
|
||||||
Task.of(() -> world.install(savesDir, name))
|
Task.of(() -> world.install(savesDir, name))
|
||||||
.finalized(Schedulers.javafx(), var -> {
|
.finalized(Schedulers.javafx(), () -> {
|
||||||
itemsProperty().add(new WorldListItem(new World(savesDir.resolve(name))));
|
itemsProperty().add(new WorldListItem(new World(savesDir.resolve(name))));
|
||||||
resolve.run();
|
resolve.run();
|
||||||
}, e -> {
|
}, e -> {
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public class DefaultGameBuilder extends GameBuilder {
|
|||||||
result = result.then(dependencyManager.installLibraryAsync(remoteVersion));
|
result = result.then(dependencyManager.installLibraryAsync(remoteVersion));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}).finalized((variables, isDependentsSucceeded, exception) -> {
|
}).finalized((isDependentsSucceeded, exception) -> {
|
||||||
if (!isDependentsSucceeded)
|
if (!isDependentsSucceeded)
|
||||||
dependencyManager.getGameRepository().getVersionRoot(name).delete();
|
dependencyManager.getGameRepository().getVersionRoot(name).delete();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
@@ -53,7 +53,7 @@ final class FinalizedTask extends Task {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() throws Exception {
|
public void execute() throws Exception {
|
||||||
callback.execute(getVariables(), isDependentsSucceeded(), pred.getLastException());
|
callback.execute(isDependentsSucceeded(), pred.getLastException());
|
||||||
|
|
||||||
if (!isDependentsSucceeded())
|
if (!isDependentsSucceeded())
|
||||||
throw new SilentException();
|
throw new SilentException();
|
||||||
|
|||||||
@@ -320,12 +320,13 @@ public abstract class Task {
|
|||||||
return new FinalizedTask(this, scheduler, b, ReflectionHelper.getCaller().toString());
|
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) {
|
// T, K here is necessary, or javac cannot infer type of failure
|
||||||
return finalized(scheduler, (variables, isDependentsSucceeded, exception) -> {
|
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 (isDependentsSucceeded) {
|
||||||
if (success != null)
|
if (success != null)
|
||||||
try {
|
try {
|
||||||
success.accept(variables);
|
success.run();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logging.LOG.log(Level.WARNING, "Failed to execute " + success, e);
|
Logging.LOG.log(Level.WARNING, "Failed to execute " + success, e);
|
||||||
if (failure != null)
|
if (failure != null)
|
||||||
@@ -421,4 +422,8 @@ public abstract class Task {
|
|||||||
SUCCEEDED,
|
SUCCEEDED,
|
||||||
FAILED
|
FAILED
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface FinalizedCallback {
|
||||||
|
void execute(boolean isDependentsSucceeded, Exception exception) throws Exception;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,14 +55,12 @@ public abstract class TaskResult<V> extends Task {
|
|||||||
return new Subtask<>(id, scheduler, 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) {
|
public <T extends Exception, K extends Exception> Task finalized(Scheduler scheduler, ExceptionalConsumer<V, T> success, ExceptionalConsumer<Exception, K> failure) {
|
||||||
return finalized(scheduler, variables -> success.accept(getResult()), failure);
|
return finalized(scheduler, () -> success.accept(getResult()), failure);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task finalizedResult(Scheduler scheduler, FinalizedCallback<V> callback) {
|
public Task finalized(Scheduler scheduler, FinalizedCallback<V> callback) {
|
||||||
return new FinalizedTask(this, scheduler,
|
return finalized(scheduler, ((isDependentsSucceeded, exception) -> callback.execute(getResult(), isDependentsSucceeded, exception)));
|
||||||
(variables, isDependentsSucceeded, exception) -> callback.execute(getResult(), isDependentsSucceeded, exception),
|
|
||||||
ReflectionHelper.getCaller().toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Subtask<R> extends TaskResult<R> {
|
private class Subtask<R> extends TaskResult<R> {
|
||||||
|
|||||||
Reference in New Issue
Block a user