Java desktop quirk in RMIR (and IrScrutinizer) on Fedora

Discussion forum for JP1 software tools currently in use, or being developed, such as IR, KM, RemoteMaster, and other misc apps/tools.

Moderator: Moderators

Post Reply
Barf
Expert
Posts: 1522
Joined: Fri Oct 24, 2008 1:54 pm
Location: Munich, Germany
Contact:

Java desktop quirk in RMIR (and IrScrutinizer) on Fedora

Post by Barf »

Suddenly the desktop functions (for example Help -> Forums) in RMIR stopped working for me. After selecting on of these functions, nothing happens; however, when the program is ended, the expected browser action takes place. (IrScrutinizer behaves identically). It is the function java.awt.Desktop.browse that is not working as it should. I believe that relevant change was when I updated my Linux Fedora 33 to 34. It continues to work on Windows, as well as some Linuxes (tested Ubunto 20.04.1). Tested with OpenJdk 11.0.11
as well as Oracle JDK 1.8.0_241 and on deskops Gnome, Cinnamon, Plasma.

I do not know "the right way" to handle this. I suspect that Fedora, or something it depends on ("Wayland"?) is to blame. I also do not know if other Linuxes are affected.

Enclosed is a patch that uses the xdg-open command instead, on systems that support it (which I suspect is "almost all" modern Linuxes).

I plan to add a similar patch to IrScrutinizer.

JP1Frame:

Code: Select all

Index: src/main/java/com/hifiremote/jp1/JP1Frame.java
===================================================================
--- src/main/java/com/hifiremote/jp1/JP1Frame.java      (revision 1828)
+++ src/main/java/com/hifiremote/jp1/JP1Frame.java      (working copy)
@@ -7,7 +7,10 @@
 import java.awt.Desktop;
 import java.awt.Toolkit;
 import java.io.IOException;
+import java.net.URI;
 import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.concurrent.TimeUnit;
 
 import javax.swing.JFrame;
 import javax.swing.JLabel;
@@ -45,6 +48,17 @@
     {
       desktop = Desktop.getDesktop();
     }
+
+    // Determine if there is a working xdg-open command;
+    // if so, we will use it instead of the java.awt.Desptop functions.
+    try {
+      ProcessBuilder processBuilder = new ProcessBuilder(XDG_COMMAND, XDG_COMMAND_TEST_OPTION);
+      Process process = processBuilder.start();
+      process.waitFor(1, TimeUnit.SECONDS);
+      int exit = process.exitValue();
+      useXdgOpen = exit == 0;
+    } catch (IOException | InterruptedException ex) {
+    }
   }
 
   /**
@@ -149,7 +163,19 @@
       }
     }
   }
+   
+  protected void browse(URI uri) throws URISyntaxException, IOException {
+    browse(uri.toURL());
+  }
 
+  protected void browse(URL url) throws URISyntaxException, IOException {
+    if (useXdgOpen) {
+      new ProcessBuilder(XDG_COMMAND, url.toString()).start();
+    } else if (desktop != null) {
+      desktop.browse(url.toURI());
+    }
+  }
+
   /** The message area. */
   private JLabel messageArea = new JLabel( "" );
 
@@ -160,6 +186,9 @@
   protected static PropertyFile properties = null;
 
   protected Desktop desktop = null;
-  
+  protected boolean useXdgOpen = false;
+  private static final String XDG_COMMAND = "xdg-open";
+  private static final String XDG_COMMAND_TEST_OPTION = "--version";
+    
   protected static Preferences preferences = null;
 }
RemoteMaster.java

Code: Select all

Index: src/main/java/com/hifiremote/jp1/RemoteMaster.java
===================================================================
--- src/main/java/com/hifiremote/jp1/RemoteMaster.java	(revision 1828)
+++ src/main/java/com/hifiremote/jp1/RemoteMaster.java	(working copy)
@@ -3375,7 +3375,7 @@
     menu.setMnemonic( KeyEvent.VK_H );
     menuBar.add( menu );
 
-    if ( desktop != null )
+    if ( desktop != null || useXdgOpen)
     {
       readmeItem = new JMenuItem( "Readme", KeyEvent.VK_R );
       readmeItem.addActionListener( this );
@@ -5526,9 +5526,9 @@
         }
 
         HtmlGenerator htmlGen = new HtmlGenerator( remoteConfig );
-        if ( desktop != null && htmlGen.makeHtml( ssList ) )
+        if ( (desktop != null || useXdgOpen ) && htmlGen.makeHtml( ssList ) )
         {
-          desktop.browse( summaryFile.toURI() );
+          browse( summaryFile.toURI() );
         }
       }
       else if ( source == viewSummaryItem )
@@ -5539,9 +5539,9 @@
           String title = "View Summary";
           JOptionPane.showMessageDialog( this, message, title, JOptionPane.INFORMATION_MESSAGE );
         }
-        else if ( desktop != null )
+        else if ( desktop != null  || useXdgOpen )
         {
-          desktop.browse( summaryFile.toURI() );
+          browse( summaryFile.toURI() );
         }
       }
       else if ( source == saveSummaryItem )
@@ -6245,43 +6245,43 @@
       else if ( source == readmeItem )
       {
         File readme = new File( workDir, "Readme.html" );
-        desktop.browse( readme.toURI() );
+        browse( readme.toURI() );
       }
       else if ( source == tutorialItem )
       {
         URL url = new URL(
             "http://www.hifi-remote.com/wiki/index.php?title=JP1_-_Just_How_Easy_Is_It%3F_-_RM-IR_Version" );
-        desktop.browse( url.toURI() );
+        browse( url );
       }
       else if ( source == rmpbReadmeItem )
       {
         File rmpbReadme = new File( workDir, "RMPB_Readme.html" );
-        desktop.browse( rmpbReadme.toURI() );
+        browse( rmpbReadme.toURI() );
       }
       else if ( source == learnedSignalItem )
       {
         File file = new File( workDir, "DecodeIR.html" );
-        desktop.browse( file.toURI() );
+        browse( file.toURI() );
       }
       else if ( source == irpProtocolsItem )
       {
         File file = new File( workDir, "IrpProtocols.html" );
-        desktop.browse( file.toURI() );
+        browse( file.toURI() );
       }
       else if ( source == homePageItem )
       {
         URL url = new URL( "https://controlremote.sourceforge.io/" );
-        desktop.browse( url.toURI() );
+        browse( url.toURI() );
       }
       else if ( source == wikiItem )
       {
         URL url = new URL( "http://www.hifi-remote.com/wiki/index.php?title=Main_Page" );
-        desktop.browse( url.toURI() );
+        browse( url.toURI() );
       }
       else if ( source == forumItem )
       {
         URL url = new URL( "https://www.hifi-remote.com/forums/" );
-        desktop.browse( url.toURI() );
+        browse( url );
       }
 //      else if ( source == powerManagementItem )
 //      {
Barf
Expert
Posts: 1522
Joined: Fri Oct 24, 2008 1:54 pm
Location: Munich, Germany
Contact:

Post by Barf »

The above fix has been checked in by Graham, and will thus be available in the next (development) release. In IrScrutinizer, a corresponding fix has been checked in and is available in the current CI build.
Post Reply