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
SwingUtil.invokeLater(new Runnable() {
@Override
public
void run() {
try { try {
java.awt.Desktop.getDesktop() java.awt.Desktop.getDesktop()
.browse(uri); .browse(uri);
} catch (IOException | URISyntaxException e) { } catch (IOException e) {
throw new RuntimeException(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)) {
// make sure this doesn't block the current UI
SwingUtil.invokeLater(new Runnable() {
@Override
public
void run() {
try {
java.awt.Desktop.getDesktop() java.awt.Desktop.getDesktop()
.mail(uri); .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)) {
final String finalPath = path;
// make sure this doesn't block the current UI
SwingUtil.invokeLater(new Runnable() {
@Override
public
void run() {
try {
java.awt.Desktop.getDesktop() java.awt.Desktop.getDesktop()
.open(new File(path)); .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");