-
Bug
-
Resolution: Unresolved
-
P4
-
9.0.4, 10
-
x86
-
os_x
FULL PRODUCT VERSION :
java version "9.0.4"
Java(TM) SE Runtime Environment (build 9.0.4+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
macOS 10.13.3
A DESCRIPTION OF THE PROBLEM :
When using a JavaFX application on macOS is configured to handle custom URI schemes (through Info.plist key CFBundleURLSchemes), the handler set via Desktop.setOpenURIHandler() only receives an OpenURIEvent if the application is already running when the URI is opened. If the URI open (triggered by a web browser or the 'open' command on the terminal) launches the application, no OpenURIEvent will be delivered.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Build the sources
javac -d classes src/com/example/Main.java
2) Create JAR using javapackager
javapackager -createJar -appclass com.example.Main -outdir jar -outfile example -srcdir classes
3) Create self-contained Mac application, set CFBundleURLTypes in Info.plist
javapackager -deploy -verbose -native image -name "Open URI Example" -srcdir jar -appclass com.example.Main \
-outdir dist -outfile Example \
-Bmac.CFBundleIdentifier=com.example.openuri -Bmac.CFBundleVersion=1.0.0 \
-Bmac.signing-key-developer-id-app="Developer ID Application: My Company Ltd GmbH (ABCDEFGHIJKL)" \
-Bmac.signing-key-developer-id-installer="Developer ID Installer: My Company Ltd (ABCDEFGHIJKL)" \
-BdropinResourcesRoot=.
4) Start application via shell $ open javafx-openuri://hello
--> Label is empty
5) Start application first, then on shell $ open javafx-openuri://hello
--> URI is set on Label
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The application should receive an OpenURIEvent if it was launched by opening a URI
ACTUAL -
The application only receives an OpenURIEvent if it was already running.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
The application:
package com.example;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import java.awt.Desktop;
public class Main extends Application {
private Label uriLabel;
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Open URI Example");
VBox root = new VBox();
root.setPadding(new Insets(20, 20, 20, 20));
uriLabel = new Label();
uriLabel.setText("No URI opened");
root.getChildren().add(uriLabel);
Scene scene = new Scene(root, 200, 60);
primaryStage.setScene(scene);
primaryStage.show();
Desktop.getDesktop().setOpenURIHandler((event) -> {
Platform.runLater(() -> {
uriLabel.setText(event.getURI().toString());
});
});
}
public static void main(String[] args) {
launch(args);
}
}
The Info.plist:
<?xml version="1.0" ?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>LSMinimumSystemVersion</key>
<string>10.9</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleAllowMixedLocalizations</key>
<true/>
<key>CFBundleExecutable</key>
<string>Open URI Example</string>
<key>CFBundleIconFile</key>
<string>Open URI Example.icns</string>
<key>CFBundleIdentifier</key>
<string>com.example.openuri</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Open URI Example</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<!-- See http://developer.apple.com/library/mac/#releasenotes/General/SubmittingToMacAppStore/_index.html
for list of AppStore categories -->
<key>LSApplicationCategoryType</key>
<string>Unknown</string>
<key>CFBundleVersion</key>
<string>1.0.0</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright (C) 2018</string>
<key>NSHighResolutionCapable</key>
<string>true</string>
<!-- Open URIs with scheme javafx-openuri:// -->
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>javafx-openuri</string>
</array>
<key>CFBundleURLName</key>
<string></string>
</dict>
</array>
</dict>
</plist>
---------- END SOURCE ----------
java version "9.0.4"
Java(TM) SE Runtime Environment (build 9.0.4+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
macOS 10.13.3
A DESCRIPTION OF THE PROBLEM :
When using a JavaFX application on macOS is configured to handle custom URI schemes (through Info.plist key CFBundleURLSchemes), the handler set via Desktop.setOpenURIHandler() only receives an OpenURIEvent if the application is already running when the URI is opened. If the URI open (triggered by a web browser or the 'open' command on the terminal) launches the application, no OpenURIEvent will be delivered.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Build the sources
javac -d classes src/com/example/Main.java
2) Create JAR using javapackager
javapackager -createJar -appclass com.example.Main -outdir jar -outfile example -srcdir classes
3) Create self-contained Mac application, set CFBundleURLTypes in Info.plist
javapackager -deploy -verbose -native image -name "Open URI Example" -srcdir jar -appclass com.example.Main \
-outdir dist -outfile Example \
-Bmac.CFBundleIdentifier=com.example.openuri -Bmac.CFBundleVersion=1.0.0 \
-Bmac.signing-key-developer-id-app="Developer ID Application: My Company Ltd GmbH (ABCDEFGHIJKL)" \
-Bmac.signing-key-developer-id-installer="Developer ID Installer: My Company Ltd (ABCDEFGHIJKL)" \
-BdropinResourcesRoot=.
4) Start application via shell $ open javafx-openuri://hello
--> Label is empty
5) Start application first, then on shell $ open javafx-openuri://hello
--> URI is set on Label
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The application should receive an OpenURIEvent if it was launched by opening a URI
ACTUAL -
The application only receives an OpenURIEvent if it was already running.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
The application:
package com.example;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import java.awt.Desktop;
public class Main extends Application {
private Label uriLabel;
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Open URI Example");
VBox root = new VBox();
root.setPadding(new Insets(20, 20, 20, 20));
uriLabel = new Label();
uriLabel.setText("No URI opened");
root.getChildren().add(uriLabel);
Scene scene = new Scene(root, 200, 60);
primaryStage.setScene(scene);
primaryStage.show();
Desktop.getDesktop().setOpenURIHandler((event) -> {
Platform.runLater(() -> {
uriLabel.setText(event.getURI().toString());
});
});
}
public static void main(String[] args) {
launch(args);
}
}
The Info.plist:
<?xml version="1.0" ?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>LSMinimumSystemVersion</key>
<string>10.9</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleAllowMixedLocalizations</key>
<true/>
<key>CFBundleExecutable</key>
<string>Open URI Example</string>
<key>CFBundleIconFile</key>
<string>Open URI Example.icns</string>
<key>CFBundleIdentifier</key>
<string>com.example.openuri</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Open URI Example</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<!-- See http://developer.apple.com/library/mac/#releasenotes/General/SubmittingToMacAppStore/_index.html
for list of AppStore categories -->
<key>LSApplicationCategoryType</key>
<string>Unknown</string>
<key>CFBundleVersion</key>
<string>1.0.0</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright (C) 2018</string>
<key>NSHighResolutionCapable</key>
<string>true</string>
<!-- Open URIs with scheme javafx-openuri:// -->
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>javafx-openuri</string>
</array>
<key>CFBundleURLName</key>
<string></string>
</dict>
</array>
</dict>
</plist>
---------- END SOURCE ----------