mirror of
https://github.com/SKCraft/Launcher.git
synced 2025-01-06 19:18:27 +01:00
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
This commit is contained in:
parent
08335637f9
commit
94ae835b42
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user