This commit is contained in:
Yellow Fish 2018-09-12 21:37:27 +08:00
parent 4e6237c062
commit 24f3dec453

View File

@ -55,6 +55,7 @@ import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.logging.Level; import java.util.logging.Level;
import static org.jackhuang.hmcl.util.Lang.thread;
import static org.jackhuang.hmcl.util.Lang.tryCast; import static org.jackhuang.hmcl.util.Lang.tryCast;
public final class FXUtils { public final class FXUtils {
@ -249,11 +250,15 @@ public final class FXUtils {
} }
break; break;
default: default:
try { thread(() -> {
java.awt.Desktop.getDesktop().open(file); if (java.awt.Desktop.isDesktopSupported()) {
} catch (Throwable e) { try {
Logging.LOG.log(Level.SEVERE, "Unable to open " + path + " by java.awt.Desktop.getDesktop()::open", e); 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) { public static void openLink(String link) {
if (link == null) if (link == null)
return; return;
try { thread(() -> {
java.awt.Desktop.getDesktop().browse(new URI(link)); if (java.awt.Desktop.isDesktopSupported()) {
} catch (Throwable e) {
if (OperatingSystem.CURRENT_OS == OperatingSystem.OSX)
try { try {
Runtime.getRuntime().exec(new String[] { "/usr/bin/open", link }); java.awt.Desktop.getDesktop().browse(new URI(link));
} catch (IOException ex) { } catch (Throwable e) {
Logging.LOG.log(Level.WARNING, "Unable to open link: " + link, ex); 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<Number> property) { public static void bindInt(JFXTextField textField, Property<Number> property) {