JP1 Remotes Forum Index JP1 Remotes


FAQFAQ SearchSearch 7 days of topics7 Days MemberlistMemberlist UsergroupsUsergroups RegisterRegister
ProfileProfile Log in to check your private messagesLog in to check your private messages Log inLog in

Java desktop quirk in RMIR (and IrScrutinizer) on Fedora

 
Post new topic   Reply to topic    JP1 Remotes Forum Index -> JP1 - Software
View previous topic :: View next topic  
Author Message
Barf
Expert


Joined: 24 Oct 2008
Posts: 1414
Location: Munich, Germany

                    
PostPosted: Mon Jun 28, 2021 5:43 am    Post subject: Java desktop quirk in RMIR (and IrScrutinizer) on Fedora Reply with quote

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:

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:

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( "http://www.hifi-remote.com/forums/" );
-        desktop.browse( url.toURI() );
+        browse( url );
       }
 //      else if ( source == powerManagementItem )
 //      {
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Barf
Expert


Joined: 24 Oct 2008
Posts: 1414
Location: Munich, Germany

                    
PostPosted: Thu Jul 01, 2021 1:41 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic       JP1 Remotes Forum Index -> JP1 - Software All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


 

Powered by phpBB © 2001, 2005 phpBB Group
Top 7 Advantages of Playing Online Slots The Evolution of Remote Control