From 24f3dec453ec45b03e1f4b68f295c3a15970f62d Mon Sep 17 00:00:00 2001 From: Yellow Fish Date: Wed, 12 Sep 2018 21:37:27 +0800 Subject: [PATCH] Fixed #450 --- .../java/org/jackhuang/hmcl/ui/FXUtils.java | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java index cfe0dbc7d..19b96d32e 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java @@ -55,6 +55,7 @@ import java.util.function.Function; import java.util.function.Supplier; import java.util.logging.Level; +import static org.jackhuang.hmcl.util.Lang.thread; import static org.jackhuang.hmcl.util.Lang.tryCast; public final class FXUtils { @@ -249,11 +250,15 @@ public final class FXUtils { } break; default: - try { - java.awt.Desktop.getDesktop().open(file); - } catch (Throwable e) { - Logging.LOG.log(Level.SEVERE, "Unable to open " + path + " by java.awt.Desktop.getDesktop()::open", e); - } + thread(() -> { + if (java.awt.Desktop.isDesktopSupported()) { + try { + java.awt.Desktop.getDesktop().open(file); + } catch (Throwable e) { + Logging.LOG.log(Level.SEVERE, "Unable to open " + path + " by java.awt.Desktop.getDesktop()::open", e); + } + } + }); } } @@ -265,17 +270,21 @@ public final class FXUtils { public static void openLink(String link) { if (link == null) return; - try { - java.awt.Desktop.getDesktop().browse(new URI(link)); - } catch (Throwable e) { - if (OperatingSystem.CURRENT_OS == OperatingSystem.OSX) + thread(() -> { + if (java.awt.Desktop.isDesktopSupported()) { try { - Runtime.getRuntime().exec(new String[] { "/usr/bin/open", link }); - } catch (IOException ex) { - Logging.LOG.log(Level.WARNING, "Unable to open link: " + link, ex); + java.awt.Desktop.getDesktop().browse(new URI(link)); + } catch (Throwable e) { + if (OperatingSystem.CURRENT_OS == OperatingSystem.OSX) + try { + Runtime.getRuntime().exec(new String[]{"/usr/bin/open", link}); + } catch (IOException ex) { + Logging.LOG.log(Level.WARNING, "Unable to open link: " + link, ex); + } + Logging.LOG.log(Level.WARNING, "Failed to open link: " + link, e); } - Logging.LOG.log(Level.WARNING, "Failed to open link: " + link, e); - } + } + }); } public static void bindInt(JFXTextField textField, Property property) {