From 94ae835b42b89a00d4041f8a5a2735427001a11b Mon Sep 17 00:00:00 2001 From: Henry Le Grys Date: Sun, 12 Dec 2021 02:20:42 +0000 Subject: [PATCH] Add support for opening URLs with xdg-open on Linux In environments without GTK, the Swing toolkit isn't available, so desktop calls don't work. If that's the case, fall back to xdg-open --- .../java/com/skcraft/launcher/swing/SwingHelper.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/launcher/src/main/java/com/skcraft/launcher/swing/SwingHelper.java b/launcher/src/main/java/com/skcraft/launcher/swing/SwingHelper.java index c06b6c0..8024e0b 100644 --- a/launcher/src/main/java/com/skcraft/launcher/swing/SwingHelper.java +++ b/launcher/src/main/java/com/skcraft/launcher/swing/SwingHelper.java @@ -12,6 +12,8 @@ import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.skcraft.launcher.LauncherException; +import com.skcraft.launcher.util.Environment; +import com.skcraft.launcher.util.Platform; import com.skcraft.launcher.util.SharedLocale; import com.skcraft.launcher.util.SwingExecutor; import lombok.NonNull; @@ -103,9 +105,19 @@ public final class SwingHelper { public static void openURL(URL url, Component parentComponent) { try { Desktop.getDesktop().browse(url.toURI()); + } catch (UnsupportedOperationException e) { + if (Environment.detectPlatform() == Platform.LINUX) { + // Try xdg-open instead + try { + Runtime.getRuntime().exec(new String[]{"xdg-open", url.toString()}); + } catch (IOException ex) { + showErrorDialog(parentComponent, tr("errors.openUrlError", url.toString()), tr("errorTitle"), ex); + } + } } catch (IOException e) { showErrorDialog(parentComponent, tr("errors.openUrlError", url.toString()), SharedLocale.tr("errorTitle")); } catch (URISyntaxException e) { + log.log(Level.WARNING, "Malformed URL; this is a programming error!", e); } }