mirror of
https://github.com/xpipe-io/xpipe.git
synced 2025-04-18 10:13:38 +00:00
Guard against nested event loop exceptions
This commit is contained in:
parent
d4a713f29b
commit
8c51eac399
2 changed files with 23 additions and 4 deletions
|
@ -84,7 +84,7 @@ public class AppDialog {
|
|||
var transition = new PauseTransition(Duration.millis(200));
|
||||
transition.setOnFinished(e -> {
|
||||
if (wait) {
|
||||
Platform.exitNestedEventLoop(key, null);
|
||||
PlatformThread.exitNestedEventLoop(key);
|
||||
}
|
||||
});
|
||||
transition.play();
|
||||
|
@ -95,7 +95,7 @@ public class AppDialog {
|
|||
}
|
||||
});
|
||||
if (wait) {
|
||||
Platform.enterNestedEventLoop(key);
|
||||
PlatformThread.enterNestedEventLoop(key);
|
||||
waitForDialogClose(o);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -274,6 +274,25 @@ public class PlatformThread {
|
|||
return true;
|
||||
}
|
||||
|
||||
public static void enterNestedEventLoop(Object key) {
|
||||
try {
|
||||
Platform.enterNestedEventLoop(key);
|
||||
} catch (IllegalStateException ex) {
|
||||
// We might be in an animation or layout call
|
||||
ErrorEvent.fromThrowable(ex).omit().expected().handle();
|
||||
}
|
||||
}
|
||||
|
||||
public static void exitNestedEventLoop(Object key) {
|
||||
try {
|
||||
Platform.exitNestedEventLoop(key, null);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// The event loop might have died somehow
|
||||
// Or we passed an invalid key
|
||||
ErrorEvent.fromThrowable(ex).omit().expected().handle();
|
||||
}
|
||||
}
|
||||
|
||||
public static void runNestedLoopIteration() {
|
||||
if (!Platform.canStartNestedEventLoop()) {
|
||||
return;
|
||||
|
@ -281,9 +300,9 @@ public class PlatformThread {
|
|||
|
||||
var key = new Object();
|
||||
Platform.runLater(() -> {
|
||||
Platform.exitNestedEventLoop(key, null);
|
||||
exitNestedEventLoop(key);
|
||||
});
|
||||
Platform.enterNestedEventLoop(key);
|
||||
enterNestedEventLoop(key);
|
||||
}
|
||||
|
||||
public static void runLaterIfNeeded(Runnable r) {
|
||||
|
|
Loading…
Add table
Reference in a new issue