From 21fa3b25bd2956e5fec89c508bf8ed61fc5cdc06 Mon Sep 17 00:00:00 2001 From: NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com> Date: Wed, 14 Dec 2022 07:13:22 +1100 Subject: Fix open in skycrypt button not working on linux with some jdks (#490) --- .../moulberry/notenoughupdates/util/Utils.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java') 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; + } + } + } } -- cgit