diff options
| author | NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com> | 2022-12-14 07:13:22 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-13 21:13:22 +0100 |
| commit | 21fa3b25bd2956e5fec89c508bf8ed61fc5cdc06 (patch) | |
| tree | ca654a1dc2463f5ba907c85c579f8bbac323ae42 /src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java | |
| parent | dd91ed7db4a4323126a04ac88bd8a4c6d6c9c82d (diff) | |
| download | notenoughupdates-21fa3b25bd2956e5fec89c508bf8ed61fc5cdc06.tar.gz notenoughupdates-21fa3b25bd2956e5fec89c508bf8ed61fc5cdc06.tar.bz2 notenoughupdates-21fa3b25bd2956e5fec89c508bf8ed61fc5cdc06.zip | |
Fix open in skycrypt button not working on linux with some jdks (#490)
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java')
| -rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java index a3f2296c..0ea1dafb 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java @@ -71,10 +71,13 @@ import java.awt.*; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; +import java.io.IOException; import java.io.InputStreamReader; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.math.BigInteger; +import java.net.URI; +import java.net.URISyntaxException; import java.nio.FloatBuffer; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -2037,4 +2040,21 @@ public class Utils { System.out.println(message); } } + + public static boolean openUrl(String url) { + try { + Desktop desk = Desktop.getDesktop(); + desk.browse(new URI(url)); + return true; + } catch (UnsupportedOperationException | IOException | URISyntaxException ignored) { + Runtime runtime = Runtime.getRuntime(); + try { + runtime.exec("xdg-open " + url); + return true; + } catch (IOException e) { + Utils.playSound(new ResourceLocation("game.player.hurt"), true); + return false; + } + } + } } |
