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,12 +250,16 @@ public final class FXUtils {
} }
break; break;
default: default:
thread(() -> {
if (java.awt.Desktop.isDesktopSupported()) {
try { try {
java.awt.Desktop.getDesktop().open(file); java.awt.Desktop.getDesktop().open(file);
} catch (Throwable e) { } catch (Throwable e) {
Logging.LOG.log(Level.SEVERE, "Unable to open " + path + " by java.awt.Desktop.getDesktop()::open", e); Logging.LOG.log(Level.SEVERE, "Unable to open " + path + " by java.awt.Desktop.getDesktop()::open", e);
} }
} }
});
}
} }
/** /**
@ -265,18 +270,22 @@ public final class FXUtils {
public static void openLink(String link) { public static void openLink(String link) {
if (link == null) if (link == null)
return; return;
thread(() -> {
if (java.awt.Desktop.isDesktopSupported()) {
try { try {
java.awt.Desktop.getDesktop().browse(new URI(link)); java.awt.Desktop.getDesktop().browse(new URI(link));
} catch (Throwable e) { } catch (Throwable e) {
if (OperatingSystem.CURRENT_OS == OperatingSystem.OSX) if (OperatingSystem.CURRENT_OS == OperatingSystem.OSX)
try { try {
Runtime.getRuntime().exec(new String[] { "/usr/bin/open", link }); Runtime.getRuntime().exec(new String[]{"/usr/bin/open", link});
} catch (IOException ex) { } catch (IOException ex) {
Logging.LOG.log(Level.WARNING, "Unable to open link: " + link, 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) {
textField.textProperty().bindBidirectional(property, SafeIntStringConverter.INSTANCE); textField.textProperty().bindBidirectional(property, SafeIntStringConverter.INSTANCE);