* Suppport feature #2554. Fix the width of task progess bar. * Simply codes. * Fix checkstyle. --------- Co-authored-by: burningtnt <pangyl08@163.com“>
This commit is contained in:
@@ -33,7 +33,10 @@ import org.jackhuang.hmcl.launch.*;
|
|||||||
import org.jackhuang.hmcl.mod.ModpackCompletionException;
|
import org.jackhuang.hmcl.mod.ModpackCompletionException;
|
||||||
import org.jackhuang.hmcl.mod.ModpackConfiguration;
|
import org.jackhuang.hmcl.mod.ModpackConfiguration;
|
||||||
import org.jackhuang.hmcl.mod.ModpackProvider;
|
import org.jackhuang.hmcl.mod.ModpackProvider;
|
||||||
import org.jackhuang.hmcl.setting.*;
|
import org.jackhuang.hmcl.setting.DownloadProviders;
|
||||||
|
import org.jackhuang.hmcl.setting.LauncherVisibility;
|
||||||
|
import org.jackhuang.hmcl.setting.Profile;
|
||||||
|
import org.jackhuang.hmcl.setting.VersionSetting;
|
||||||
import org.jackhuang.hmcl.task.*;
|
import org.jackhuang.hmcl.task.*;
|
||||||
import org.jackhuang.hmcl.ui.*;
|
import org.jackhuang.hmcl.ui.*;
|
||||||
import org.jackhuang.hmcl.ui.construct.*;
|
import org.jackhuang.hmcl.ui.construct.*;
|
||||||
@@ -216,9 +219,10 @@ public final class LauncherHelper {
|
|||||||
Controllers.dialog(i18n("version.launch_script.success", scriptFile.getAbsolutePath()));
|
Controllers.dialog(i18n("version.launch_script.success", scriptFile.getAbsolutePath()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}).thenRunAsync(() -> {
|
}).withFakeProgress(
|
||||||
launchingLatch.await();
|
i18n("message.doing"),
|
||||||
}).withStage("launch.state.waiting_launching"))
|
() -> launchingLatch.getCount() == 0, 6.95
|
||||||
|
).withStage("launch.state.waiting_launching"))
|
||||||
.withStagesHint(Lang.immutableListOf(
|
.withStagesHint(Lang.immutableListOf(
|
||||||
"launch.state.java",
|
"launch.state.java",
|
||||||
"launch.state.dependencies",
|
"launch.state.dependencies",
|
||||||
@@ -617,7 +621,7 @@ public final class LauncherHelper {
|
|||||||
/**
|
/**
|
||||||
* Directly start java downloading.
|
* Directly start java downloading.
|
||||||
*
|
*
|
||||||
* @param javaVersion target Java version
|
* @param javaVersion target Java version
|
||||||
* @param downloadProvider download provider
|
* @param downloadProvider download provider
|
||||||
* @return JavaVersion, null if we failed to download java, failed if an error occurred when downloading.
|
* @return JavaVersion, null if we failed to download java, failed if an error occurred when downloading.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -301,7 +301,7 @@ public final class TaskListPane extends StackPane {
|
|||||||
private final Label title = new Label();
|
private final Label title = new Label();
|
||||||
private final Label state = new Label();
|
private final Label state = new Label();
|
||||||
private final DoubleBinding binding = Bindings.createDoubleBinding(() ->
|
private final DoubleBinding binding = Bindings.createDoubleBinding(() ->
|
||||||
getWidth() - getPadding().getLeft() - getPadding().getRight(),
|
getWidth() - getPadding().getLeft() - getPadding().getRight() - getInsets().getLeft() - getInsets().getRight(),
|
||||||
paddingProperty(), widthProperty());
|
paddingProperty(), widthProperty());
|
||||||
|
|
||||||
public ProgressListNode(Task<?> task) {
|
public ProgressListNode(Task<?> task) {
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import java.util.*;
|
|||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.function.BooleanSupplier;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@@ -806,9 +807,11 @@ public abstract class Task<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Task<T> withStage(String stage) {
|
public Task<T> withStage(String stage) {
|
||||||
StageTask task = new StageTask();
|
return new StageTask(stage);
|
||||||
task.setStage(stage);
|
}
|
||||||
return task;
|
|
||||||
|
public Task<T> withFakeProgress(String name, BooleanSupplier done, double k) {
|
||||||
|
return new FakeProgressTask(done, k).setExecutor(Schedulers.defaultScheduler()).setName(name).setSignificance(TaskSignificance.MAJOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<T> withStagesHint(List<String> stages) {
|
public Task<T> withStagesHint(List<String> stages) {
|
||||||
@@ -1100,7 +1103,10 @@ public abstract class Task<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class StageTask extends Task<T> {
|
private final class StageTask extends Task<T> {
|
||||||
|
private StageTask(String stage) {
|
||||||
|
this.setStage(stage);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Task<?>> getDependents() {
|
public Collection<Task<?>> getDependents() {
|
||||||
@@ -1108,7 +1114,43 @@ public abstract class Task<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() throws Exception {
|
public void execute() {
|
||||||
|
setResult(Task.this.getResult());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final class FakeProgressTask extends Task<T> {
|
||||||
|
private static final double MAX_VALUE = 0.98D;
|
||||||
|
|
||||||
|
private final BooleanSupplier done;
|
||||||
|
|
||||||
|
private final double k;
|
||||||
|
|
||||||
|
private FakeProgressTask(BooleanSupplier done, double k) {
|
||||||
|
this.done = done;
|
||||||
|
this.k = k;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<Task<?>> getDependents() {
|
||||||
|
return Collections.singleton(Task.this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute() throws InterruptedException {
|
||||||
|
if (!done.getAsBoolean()) {
|
||||||
|
updateProgress(0.0D);
|
||||||
|
|
||||||
|
final long start = System.currentTimeMillis();
|
||||||
|
final double k2 = k / MAX_VALUE;
|
||||||
|
while (!done.getAsBoolean()) {
|
||||||
|
updateProgressImmediately(-k / ((System.currentTimeMillis() - start) / 1000D + k2) + MAX_VALUE);
|
||||||
|
|
||||||
|
Thread.sleep(1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateProgress(1.0D);
|
||||||
setResult(Task.this.getResult());
|
setResult(Task.this.getResult());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user