Suppport feature #2554. Fix the width of task progess bar. (#2573)

* 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:
Burning_TNT
2024-01-07 22:41:08 +08:00
committed by GitHub
parent f558be7193
commit 5b7149b967
3 changed files with 57 additions and 11 deletions

View File

@@ -33,7 +33,10 @@ import org.jackhuang.hmcl.launch.*;
import org.jackhuang.hmcl.mod.ModpackCompletionException;
import org.jackhuang.hmcl.mod.ModpackConfiguration;
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.ui.*;
import org.jackhuang.hmcl.ui.construct.*;
@@ -216,9 +219,10 @@ public final class LauncherHelper {
Controllers.dialog(i18n("version.launch_script.success", scriptFile.getAbsolutePath()));
});
}
}).thenRunAsync(() -> {
launchingLatch.await();
}).withStage("launch.state.waiting_launching"))
}).withFakeProgress(
i18n("message.doing"),
() -> launchingLatch.getCount() == 0, 6.95
).withStage("launch.state.waiting_launching"))
.withStagesHint(Lang.immutableListOf(
"launch.state.java",
"launch.state.dependencies",
@@ -617,7 +621,7 @@ public final class LauncherHelper {
/**
* Directly start java downloading.
*
* @param javaVersion target Java version
* @param javaVersion target Java version
* @param downloadProvider download provider
* @return JavaVersion, null if we failed to download java, failed if an error occurred when downloading.
*/

View File

@@ -301,7 +301,7 @@ public final class TaskListPane extends StackPane {
private final Label title = new Label();
private final Label state = new Label();
private final DoubleBinding binding = Bindings.createDoubleBinding(() ->
getWidth() - getPadding().getLeft() - getPadding().getRight(),
getWidth() - getPadding().getLeft() - getPadding().getRight() - getInsets().getLeft() - getInsets().getRight(),
paddingProperty(), widthProperty());
public ProgressListNode(Task<?> task) {

View File

@@ -36,6 +36,7 @@ import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.function.BooleanSupplier;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.logging.Level;
@@ -806,9 +807,11 @@ public abstract class Task<T> {
}
public Task<T> withStage(String stage) {
StageTask task = new StageTask();
task.setStage(stage);
return task;
return new StageTask(stage);
}
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) {
@@ -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
public Collection<Task<?>> getDependents() {
@@ -1108,7 +1114,43 @@ public abstract class Task<T> {
}
@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());
}
}