Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8239590

JavaFX: fileopen events lost during startup

    XMLWordPrintable

Details

    Description

      ADDITIONAL SYSTEM INFORMATION :
      macOS Catalina 10.15.0, 10.15.1, 10.15.2, 10.15.3
      JDK 11, 12, 13, 14-RC
      OpenJFX 11, 12, 13, 14-ea+4...ea+8, 15-ea+1

      A DESCRIPTION OF THE PROBLEM :
      When setting an OpenFilesHandler via desktop.setOpenFileHandler(...), non-JavaFX applications will receive File open events created by double-clicking on a registered document file.

      In JavaFX applications, all file open events generated before registering the OpenFilesHandler are lost, so it is not possible to create a JavaFX-Application that opens registered document types by double clicking.

      As a workaround for JavaFX-applications, the OpenFilesHandler can be set before the JavaFX platform starts, and the files contained in the OpenFilesEvents stored and later passed on to the application. But this totally breaks the rest of the desktop integration, i. e. the global menu bar will not work any more (it is empty except for the application title, and the application frame contains the rest of the menu).

      I tried debugging this to the best I can, and I saw that initial file open events are stored in two places:
      - com.apple.eawt._AppEventHandler (sends events once a handler is set in setHandler)
      - com.sun.glass.ui.Application (should send events when setEventHandler is called for the second time, but debugging shows it is only called once)

      I also don't quite get the logic behind com.sun.glass.ui.Application.EventHandler class which has an no-op handleOpenFilesAction() method that is never overwritten. It looks like com.sun.glass.ui.Application is trying to duplicate functionality from com.apple.eawt._AppEventHandler, which seems not only unnecessary, but also results in the file open events being snatched away from the working com.apple.eawt._AppEventHandler implementation.

      I'd be willing to contribute more, but even a clean checkout of current JavaFX code does not compile without issues (some tests seem to be locale dependent, others run on a timeout).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      create a JavaFX application with a registered file type, then
      1. before application is running: double click a file of the registered type or right-click in finder and select "open with ..."
      2. when the application is running: double click a file of the registered type or right-click in finder and select "open with ..."

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Step 1: should start the application and open the selected document
      Step 2: should open the selected document in the running application

      ACTUAL -
      Step 1: starts the application but doesn't open the selected document
      Step 2: opens the selected document in the running application


      ---------- BEGIN SOURCE ----------
      Sorry, but to verify this, a complete *packaged* and *installed* application is needed because otherwise file open notifications will not be sent (i. e. when the program is started from within a debugger). It should be possible to use a JEP343/jpackage test case, but I don't have access to these.
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      A workaround is mentioned in the accepted answer to this [stackoverflow question](https://stackoverflow.com/questions/29101472/pass-parameters-to-javafx-application-by-double-click-on-file). This worked in Java 8, but does not work any more with jigsaw. The workaround can be changed to work in post-jigsaw Java (9+), but then completely breaks the rest of the java.desktop API (which ironically was introduced to solve this exact problem).


      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

              kcr Kevin Rushforth
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated: