删除 Lang.timer (#5537)

This commit is contained in:
Glavo
2026-02-14 22:04:04 +08:00
committed by GitHub
parent 64ce1854f5
commit 25fef6b5c2
2 changed files with 0 additions and 54 deletions

View File

@@ -31,16 +31,12 @@ import javafx.scene.text.TextFlow;
import org.jackhuang.hmcl.ui.Controllers;
import org.jackhuang.hmcl.ui.FXUtils;
import org.jackhuang.hmcl.ui.SVG;
import org.jackhuang.hmcl.util.Lang;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Locale;
import java.util.Timer;
import java.util.TimerTask;
import static org.jackhuang.hmcl.ui.FXUtils.onEscPressed;
import static org.jackhuang.hmcl.ui.FXUtils.runInFX;
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
public final class MessageDialogPane extends HBox {
@@ -219,36 +215,6 @@ public final class MessageDialogPane extends HBox {
return this;
}
public Builder cancelOnTimeout(long timeoutMs) {
if (dialog.getCancelButton() == null) {
throw new IllegalStateException("Call ok/yesOrNo/actionOrCancel before calling cancelOnTimeout");
}
ButtonBase cancelButton = dialog.getCancelButton();
String originalText = cancelButton.getText();
Timer timer = Lang.getTimer();
timer.scheduleAtFixedRate(new TimerTask() {
long timeout = timeoutMs;
@Override
public void run() {
if (timeout <= 0) {
cancel();
runInFX(() -> {
cancelButton.fire();
});
return;
}
timeout -= 1000;
long currentTimeout = timeout;
runInFX(() -> cancelButton.setText(originalText + " (" + (currentTimeout / 1000) + ")"));
}
}, 1000, 1000);
return this;
}
public MessageDialogPane build() {
return dialog;
}

View File

@@ -419,26 +419,6 @@ public final class Lang {
action.accept(it1.next(), it2.next());
}
private static Timer timer;
public static synchronized Timer getTimer() {
if (timer == null) {
timer = new Timer(true);
}
return timer;
}
public static synchronized TimerTask setTimeout(Runnable runnable, long delayMs) {
TimerTask task = new TimerTask() {
@Override
public void run() {
runnable.run();
}
};
getTimer().schedule(task, delayMs);
return task;
}
public static Throwable resolveException(Throwable e) {
if (e instanceof ExecutionException || e instanceof CompletionException)
return resolveException(e.getCause());