[Enhancement] 不在主界面,或者已显示对话框的情况下,暂时不弹出启动器更新对话框 (#6095)

Co-authored-by: Calboot <[email protected]>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: CalbootOnceMore <[email protected]>
Co-authored-by: Copilot <[email protected]>
This commit is contained in:
authored and GitHub committed 2026-06-21 16:25:52 +08:00
1 parent 0e04566b6c
commit 436f664a1c
6 files changed
+89 -11

No files matched your search

@@ -62,6 +62,7 @@ import org.jackhuang.hmcl.ui.terracotta.TerracottaPage;
import org.jackhuang.hmcl.ui.versions.GameListPage;
import org.jackhuang.hmcl.ui.versions.VersionPage;
import org.jackhuang.hmcl.ui.versions.Versions;
import org.jackhuang.hmcl.upgrade.UpdateChecker;
import org.jackhuang.hmcl.util.*;
import org.jackhuang.hmcl.util.i18n.I18n;
import org.jackhuang.hmcl.util.i18n.SupportedLocale;
@@ -380,6 +381,12 @@ public final class Controllers {
stage.setOnCloseRequest(e -> Launcher.stopApplication());
decorator = new DecoratorController(stage, getRootPage());
getRootPage().getMainPage().showUpdateProperty().bind(UpdateChecker.checkingUpdateProperty().not().and(UpdateChecker.outdatedProperty()));
getRootPage().getMainPage().showUpdateDialogProperty().bind(
decorator.backableProperty().not()
.and(getRootPage().getMainPage().showUpdateProperty())
.and(settings().disableAutoShowUpdateDialogProperty().not())
);
if (settings().commonDirectoryTypeProperty().get() == EnumCommonDirectory.CUSTOM &&
!FileUtils.canCreateDirectory(settings().getResolvedCommonDirectory())) {
@@ -639,6 +646,11 @@ public final class Controllers {
timeline.play();
}
public static void dialogLater(Region content) {
if (decorator != null)
decorator.showDialogLater(content);
}
public static CompletableFuture<String> prompt(String title, FutureCallback<String> onResult) {
return prompt(title, onResult, "");
}
@@ -31,7 +31,9 @@ import org.jackhuang.hmcl.ui.construct.JFXDialogPane;
import org.jackhuang.hmcl.ui.decorator.Decorator;
import org.jetbrains.annotations.Nullable;
import java.util.LinkedList;
import java.util.Optional;
import java.util.Queue;
import java.util.function.Consumer;
public final class DialogUtils {
@@ -45,6 +47,8 @@ public final class DialogUtils {
public static final String PROPERTY_PARENT_PANE_REF = DialogUtils.class.getName() + ".dialog.parentPaneRef";
public static final String PROPERTY_PARENT_DIALOG_REF = DialogUtils.class.getName() + ".dialog.parentDialogRef";
public static final String PROPERTY_DIALOG_SHOW_LATER = DialogUtils.class.getName() + ".dialog.showLater";
public static void show(Decorator decorator, Node content) {
if (decorator.getDrawerWrapper() == null) {
Platform.runLater(() -> show(decorator, content));
@@ -121,6 +125,31 @@ public final class DialogUtils {
}
}
public static void showLater(Decorator decorator, Node content) {
if (decorator.getDrawerWrapper() == null) {
Platform.runLater(() -> showLater(decorator, content));
return;
}
showLater(decorator.getDrawerWrapper(), () -> show(decorator, content));
}
@SuppressWarnings("unchecked")
public static void showLater(StackPane container, Runnable showDialogAction) {
if (showDialogAction == null) return;
FXUtils.checkFxUserThread();
if (container.getProperties().get(PROPERTY_DIALOG_INSTANCE) == null) {
showDialogAction.run();
return;
}
Queue<Runnable> queue = (Queue<Runnable>) container.getProperties().get(PROPERTY_DIALOG_SHOW_LATER);
if (queue == null) {
queue = new LinkedList<>();
container.getProperties().put(PROPERTY_DIALOG_SHOW_LATER, queue);
}
queue.add(showDialogAction);
}
@SuppressWarnings("unchecked")
public static void close(Node content) {
FXUtils.checkFxUserThread();
@@ -131,6 +160,8 @@ public final class DialogUtils {
JFXDialogPane pane = (JFXDialogPane) content.getProperties().get(PROPERTY_PARENT_PANE_REF);
JFXDialog dialog = (JFXDialog) content.getProperties().get(PROPERTY_PARENT_DIALOG_REF);
Runnable showNextDialogAction = null;
if (dialog != null && pane != null) {
if (pane.size() == 1 && pane.peek().orElse(null) == content) {
dialog.setOnDialogClosed(e -> pane.pop(content));
@@ -142,6 +173,17 @@ public final class DialogUtils {
container.getProperties().remove(PROPERTY_DIALOG_PANE_INSTANCE);
container.getProperties().remove(PROPERTY_PARENT_DIALOG_REF);
container.getProperties().remove(PROPERTY_PARENT_PANE_REF);
Queue<Runnable> queue = (Queue<Runnable>) container.getProperties().get(PROPERTY_DIALOG_SHOW_LATER);
if (queue != null) {
if (!queue.isEmpty()) {
Runnable next = queue.remove();
if (next != null) showNextDialogAction = next;
}
if (queue.isEmpty()) {
container.getProperties().remove(PROPERTY_DIALOG_SHOW_LATER);
}
}
}
} else {
pane.pop(content);
@@ -151,5 +193,7 @@ public final class DialogUtils {
dialogAware.onDialogClosed();
}
}
if (showNextDialogAction != null) showNextDialogAction.run();
}
}
@@ -22,6 +22,7 @@ import com.jfoenix.controls.JFXSnackbarLayout;
import javafx.animation.Interpolator;
import javafx.beans.InvalidationListener;
import javafx.beans.WeakInvalidationListener;
import javafx.beans.property.BooleanProperty;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.image.Image;
@@ -342,6 +343,10 @@ public class DecoratorController {
navigator.navigate(node, animationProducer, duration, interpolator);
}
public BooleanProperty backableProperty() {
return navigator.backableProperty();
}
private void close() {
if (navigator.getCurrentPage() instanceof DecoratorPage) {
DecoratorPage page = (DecoratorPage) navigator.getCurrentPage();
@@ -426,6 +431,10 @@ public class DecoratorController {
DialogUtils.close(node);
}
public void showDialogLater(Node node) {
DialogUtils.showLater(decorator, node);
}
// ==== Toast ====
public void showToast(String content) {
@@ -79,7 +79,6 @@ import java.util.concurrent.CancellationException;
import java.util.function.Consumer;
import static org.jackhuang.hmcl.download.RemoteVersion.Type.RELEASE;
import static org.jackhuang.hmcl.setting.SettingsManager.settings;
import static org.jackhuang.hmcl.setting.SettingsManager.state;
import static org.jackhuang.hmcl.ui.FXUtils.SINE;
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
@@ -92,6 +91,7 @@ public final class MainPage extends StackPane implements DecoratorPage {
private final StringProperty currentGame = new SimpleStringProperty(this, "currentGame");
private final BooleanProperty showUpdate = new SimpleBooleanProperty(this, "showUpdate");
private final BooleanProperty showUpdateDialog = new SimpleBooleanProperty(this, "showUpdateDialog");
private final ObjectProperty<RemoteVersion> latestVersion = new SimpleObjectProperty<>(this, "latestVersion");
private final ObservableList<Version> versions = FXCollections.observableArrayList();
private Profile profile;
@@ -100,6 +100,8 @@ public final class MainPage extends StackPane implements DecoratorPage {
private final StackPane updatePane;
private final JFXButton menuButton;
private RemoteVersion lastShownVersion;
{
HBox titleNode = new HBox(8);
titleNode.setPadding(new Insets(0, 0, 0, 2));
@@ -173,7 +175,8 @@ public final class MainPage extends StackPane implements DecoratorPage {
StackPane.setAlignment(updatePane, Pos.TOP_RIGHT);
FXUtils.onClicked(updatePane, this::onUpgrade);
updatePane.setCursor(Cursor.HAND);
FXUtils.onChange(showUpdateProperty(), this::showUpdate);
FXUtils.onChange(showUpdateProperty(), this::doAnimation);
FXUtils.onChange(showUpdateDialogProperty(), this::showUpdateDialog);
{
HBox hBox = new HBox();
@@ -277,13 +280,12 @@ public final class MainPage extends StackPane implements DecoratorPage {
}
private void showUpdate(boolean show) {
doAnimation(show);
if (show && !settings().disableAutoShowUpdateDialogProperty().get()
&& getLatestVersion() != null
&& !Objects.equals(state().getPromptedVersion(), getLatestVersion().version())) {
Controllers.dialog(new MessageDialogPane.Builder("", i18n("update.bubble.title", getLatestVersion().version()), MessageDialogPane.MessageType.INFO)
private void showUpdateDialog(boolean show) {
if (show && getLatestVersion() != null && !Objects.equals(getLatestVersion(), lastShownVersion)
&& !Objects.equals(state().getPromptedVersion(), getLatestVersion().version())
) {
lastShownVersion = getLatestVersion();
Controllers.dialogLater(new MessageDialogPane.Builder("", i18n("update.bubble.title", getLatestVersion().version()), MessageDialogPane.MessageType.INFO)
.addAction(i18n("button.view"), () -> {
state().setPromptedVersion(getLatestVersion().version());
onUpgrade();
@@ -406,6 +408,18 @@ public final class MainPage extends StackPane implements DecoratorPage {
this.showUpdate.set(showUpdate);
}
public boolean isShowUpdateDialog() {
return showUpdateDialog.get();
}
public BooleanProperty showUpdateDialogProperty() {
return showUpdateDialog;
}
public void setShowUpdateDialog(boolean showUpdateDialog) {
this.showUpdateDialog.set(showUpdateDialog);
}
public RemoteVersion getLatestVersion() {
return latestVersion.get();
}
@@ -120,7 +120,6 @@ public class RootPage extends DecoratorAnimatedPage implements DecoratorPage {
});
FXUtils.onChangeAndOperate(Profiles.selectedInstanceProperty(), mainPage::setCurrentGame);
mainPage.showUpdateProperty().bind(UpdateChecker.outdatedProperty());
mainPage.latestVersionProperty().bind(UpdateChecker.latestVersionProperty());
Profiles.registerVersionsListener(profile -> {
@@ -118,10 +118,10 @@ public final class UpdateChecker {
RemoteVersion finalResult = result;
Platform.runLater(() -> {
checkingUpdate.set(false);
if (finalResult != null) {
latestVersion.set(finalResult);
}
checkingUpdate.set(false);
});
}, "Update Checker", true);
});