-
Notifications
You must be signed in to change notification settings - Fork 860
[Enhancement] 不在主界面,或者已显示对话框的情况下,暂时不弹出启动器更新对话框 #5768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
939a064
d6fcc57
918516f
a2cfa1d
76d5b80
bc30519
803c668
e907605
dadecc7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,7 +31,9 @@ | |
| 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 @@ private 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,30 @@ public void changed(ObservableValue<? extends Boolean> observable, Boolean oldVa | |
| } | ||
| } | ||
|
|
||
| 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) { | ||
| 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 +159,8 @@ public static void close(Node content) { | |
| 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 +172,12 @@ public static void close(Node content) { | |
| 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 && !queue.isEmpty()) { | ||
| Runnable next = queue.remove(); | ||
| if (next != null) showNextDialogAction = next; | ||
| } | ||
| } | ||
| } else { | ||
| pane.pop(content); | ||
|
|
@@ -151,5 +187,7 @@ public static void close(Node content) { | |
| dialogAware.onDialogClosed(); | ||
| } | ||
| } | ||
|
|
||
| if (showNextDialogAction != null) showNextDialogAction.run(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This runs the next queued dialog action immediately after Useful? React with 👍 / 👎. |
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is recommended to add a null check for
showDialogActionbefore adding it to the queue to prevent potentialNullPointerExceptionwhen the action is eventually executed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没有这个回调那这方法啥用没有啊