2525import com .sun .jna .Platform ;
2626import com .sun .jna .platform .unix .X11 ;
2727import de .bwravencl .controllerbuddy .constants .Constants ;
28+ import de .bwravencl .controllerbuddy .dbus .freedesktop .OpenURI ;
29+ import de .bwravencl .controllerbuddy .dbus .freedesktop .Request ;
2830import de .bwravencl .controllerbuddy .dbus .gnome .Extensions ;
2931import de .bwravencl .controllerbuddy .gui .GuiUtils .FrameDragListener ;
3032import de .bwravencl .controllerbuddy .input .Input ;
135137import java .util .Timer ;
136138import java .util .TimerTask ;
137139import java .util .concurrent .Callable ;
140+ import java .util .concurrent .CompletableFuture ;
138141import java .util .concurrent .Executors ;
139142import java .util .concurrent .ScheduledExecutorService ;
140143import java .util .concurrent .TimeUnit ;
218221import org .apache .commons .cli .HelpFormatter ;
219222import org .apache .commons .cli .Options ;
220223import org .apache .commons .cli .ParseException ;
224+ import org .freedesktop .dbus .DBusMatchRule ;
221225import org .freedesktop .dbus .connections .impl .DBusConnectionBuilder ;
222226import org .lwjgl .glfw .GLFW ;
223227import org .lwjgl .system .Configuration ;
@@ -1467,16 +1471,46 @@ public static void main(final String[] args) {
14671471 }
14681472
14691473 private static void openBrowser (final Component parentComponent , final URI uri ) {
1470- if (Desktop .isDesktopSupported () && Desktop .getDesktop ().isSupported (Desktop .Action .BROWSE )) {
1471- try {
1472- Desktop .getDesktop ().browse (uri );
1473- } catch (final IOException e ) {
1474- throw new RuntimeException (e );
1474+ if (Desktop .isDesktopSupported ()) {
1475+ final var desktop = Desktop .getDesktop ();
1476+
1477+ if (desktop .isSupported (Desktop .Action .BROWSE )) {
1478+ try {
1479+ desktop .browse (uri );
1480+ return ;
1481+ } catch (final Throwable t ) {
1482+ log .log (Level .WARNING , t .getMessage (), t );
1483+ }
14751484 }
1485+ }
1486+
1487+ if (isLinux ) {
1488+ new Thread (() -> {
1489+ var success = false ;
1490+
1491+ try (final var dBusConnection = DBusConnectionBuilder .forSessionBus ().build ()) {
1492+ final var openUriInterface = dBusConnection .getRemoteObject ("org.freedesktop.portal.Desktop" ,
1493+ "/org/freedesktop/portal/desktop" , OpenURI .class );
1494+
1495+ final var responseCompletableFuture = new CompletableFuture <Request .Response >();
1496+
1497+ try (final var _ = dBusConnection .addSigHandler (new DBusMatchRule (Request .Response .class ),
1498+ responseCompletableFuture ::complete )) {
1499+ final var requestPath = openUriInterface .OpenURI ("" , uri .toString (), Collections .emptyMap ())
1500+ .getPath ();
1501+ final var response = responseCompletableFuture .get (3 , TimeUnit .SECONDS );
1502+ success = response .getPath ().equals (requestPath ) && response .getResponse ().intValue () == 0 ;
1503+ }
1504+ } catch (final Throwable t ) {
1505+ log .log (Level .WARNING , t .getMessage (), t );
1506+ }
1507+
1508+ if (!success ) {
1509+ EventQueue .invokeLater (() -> showPleaseVisitDialog (parentComponent , uri ));
1510+ }
1511+ }).start ();
14761512 } else {
1477- JOptionPane .showMessageDialog (parentComponent ,
1478- MessageFormat .format (strings .getString ("PLEASE_VISIT_DIALOG_TEXT" ), uri ),
1479- strings .getString ("INFORMATION_DIALOG_TITLE" ), JOptionPane .INFORMATION_MESSAGE );
1513+ showPleaseVisitDialog (parentComponent , uri );
14801514 }
14811515 }
14821516
@@ -1496,6 +1530,12 @@ private static void printCommandLineMessage(final String message) {
14961530 }
14971531 }
14981532
1533+ private static void showPleaseVisitDialog (final Component parentComponent , final URI uri ) {
1534+ JOptionPane .showMessageDialog (parentComponent ,
1535+ MessageFormat .format (strings .getString ("PLEASE_VISIT_DIALOG_TEXT" ), uri ),
1536+ strings .getString ("INFORMATION_DIALOG_TITLE" ), JOptionPane .INFORMATION_MESSAGE );
1537+ }
1538+
14991539 private static void terminate (final int status , final Main main ) {
15001540 if (main != null && main .taskRunner != null ) {
15011541 main .taskRunner .shutdown ();
0 commit comments