Java – We have the Technology

ShowRunnerOnLinux_2020-04-20 13-36-24
Java App running on Linux

We recently proved that Java desktop programs can be easily deployed to Windows and Linux. Now we have proved that other complex parts of the program to run a series of Impress Shows in a loop.

  1. Running the command line to launch the Impress program to show the slide show.
  2. Finding out when the show is complete.
  3. Clicking the mouse repeatedly so that the show ends when it finally reaches the black screen.

1 and 2 are pretty easy. In Qt there is a class that executes a command in another process. And you can wait on it or check to see if it is complete. We can’t wait of course since Impress just waits forever for a click on a black screen at the end. Soooo.

3 is not so easy on Qt. The solution differs by OS. On windows you need to call the Kernel to send events to be dispatched through the event handler. UINPUT calls. On Linux, the easiest solution I found was to launch the “xtodo click 1” command to perform a mouse click. The xtodo command is easily installed on Linux, but this is another step to make the program work. But the Java solution is much easier.

Java Solution to Problems

In java, there is of course a class to launch programs. So executing a command in another process is no problem. However there is a little bit of funky business when it comes to checking to see if the process is complete. To check, you don’t do a wait for a short time and see if it timed out, but instead, you check for the Exit Code and if you get an exception, then the process is not complete. Odd. But it works. See the code gist below.

But the Mouse click problem is really simple, and works across OSs. Just use the Robot Class. The Robot class clicks the mouse and a variety of other things. So no kernel calls or launching other utilities that need to be installed. It just works. Same code everywhere.

So here is the example program running on Windows 10, on the left and Linux Mint 19 on a 4K monitor on the right. The example is in the center with the Qt version of the app to the left for comparison. The example just launches one show, clicks the mouse every 5 seconds and senses when the show has exited. Here are some gists of the code:

Timer Code

Start / Stop Impress Slide Shows

Here’s the code to start and stop the slide shows that uses the timer code above.

Maybe these will help you in your solutions.

The code for the complete app will appear here on GitHub and on my SourceForge page. Note I’ll probably change the name of the Repo at some point, when I figure out how.

May you walk in the light of the Crystal.
:ww

Update: April 23, 2020

I’ve been struggling with getting the app to work on Linux. The program would not launch slide show files with Impress, or anything else including the text editor xed.

ImpressShowRunner 2020-04-23 22-00-03.png

After quite a bit of work, and lots of searches, I found a reference to an Eclipse bug [ Java IDE ] where the Runtime.exec() method failed. After running the program as a jar file on Linux, it turns out that an Eclipse bug is the problem. The program launches shows reliably. There are remaining issues with spaces, dashes and parenthesis in paths to the show files. These problems are far more tractable than the runtime error.

I’ll be posting new versions and details here on the SourceForge Siteand the sources are here on GitHub. The repository name will probably change soon.

:ww