Fixed issues with making sure that Desktop.* methods do not block

the current UI when running from the Swing EDT.
This commit is contained in:
nathan 2018-01-11 16:14:06 +01:00
parent 61554d3f75
commit 8a1ce599a2

View File

@ -80,12 +80,17 @@ class Desktop {
} }
else if (java.awt.Desktop.isDesktopSupported() && java.awt.Desktop.getDesktop() else if (java.awt.Desktop.isDesktopSupported() && java.awt.Desktop.getDesktop()
.isSupported(java.awt.Desktop.Action.BROWSE)) { .isSupported(java.awt.Desktop.Action.BROWSE)) {
EventQueue.invokeLater(() -> { // make sure this doesn't block the current UI
try { SwingUtil.invokeLater(new Runnable() {
java.awt.Desktop.getDesktop() @Override
.browse(uri); public
} catch (IOException | URISyntaxException e) { void run() {
throw new RuntimeException(e); try {
java.awt.Desktop.getDesktop()
.browse(uri);
} catch (IOException e) {
e.printStackTrace();
}
} }
}); });
} }
@ -140,8 +145,19 @@ class Desktop {
} }
else if (java.awt.Desktop.isDesktopSupported() && java.awt.Desktop.getDesktop() else if (java.awt.Desktop.isDesktopSupported() && java.awt.Desktop.getDesktop()
.isSupported(java.awt.Desktop.Action.MAIL)) { .isSupported(java.awt.Desktop.Action.MAIL)) {
java.awt.Desktop.getDesktop() // make sure this doesn't block the current UI
.mail(uri); SwingUtil.invokeLater(new Runnable() {
@Override
public
void run() {
try {
java.awt.Desktop.getDesktop()
.mail(uri);
} catch (IOException e) {
e.printStackTrace();
}
}
});
} }
else { else {
throw new IOException("Current OS and desktop configuration does not support launching an email client"); throw new IOException("Current OS and desktop configuration does not support launching an email client");
@ -188,8 +204,21 @@ class Desktop {
} }
else if (java.awt.Desktop.isDesktopSupported() && java.awt.Desktop.getDesktop() else if (java.awt.Desktop.isDesktopSupported() && java.awt.Desktop.getDesktop()
.isSupported(java.awt.Desktop.Action.OPEN)) { .isSupported(java.awt.Desktop.Action.OPEN)) {
java.awt.Desktop.getDesktop() final String finalPath = path;
.open(new File(path));
// make sure this doesn't block the current UI
SwingUtil.invokeLater(new Runnable() {
@Override
public
void run() {
try {
java.awt.Desktop.getDesktop()
.open(new File(finalPath));
} catch (IOException e) {
e.printStackTrace();
}
}
});
} }
else { else {
throw new IOException("Current OS and desktop configuration does not support opening a directory to browse"); throw new IOException("Current OS and desktop configuration does not support opening a directory to browse");