Skip to content

Commit 9dff163

Browse files
committed
Add readme
1 parent 48c9ccc commit 9dff163

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed
181 KB
Loading

readme.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<img src="https://github.com/eschmar/javafx-custom-file-ext-boilerplate/raw/master/src/main/resources/com/example/pew/icon.png" width="100" alt="Boilerplate recognising .pew files.">
2+
3+
# JavaFX Custom File Extension Viewer boilerplate
4+
5+
This is a boilerplate for creating a JavaFX application that is capable of handling a custom file extension. There are some nuances/caveats to getting this right (especially on MacOS), which are described in the [accompanying blog post](https://eschmann.io/posts/javafx-mac). In this example, the application is set up to handle `.pew` files with the bundle identifier `com.example.pew`. The [Makefile](https://github.com/eschmar/javafx-custom-file-ext-boilerplate/blob/master/Makefile) will generate a MacOS `.app` bundle by executing the following steps:
6+
7+
* Build the JavaFX application using jlink
8+
* Generate a boilerplate `.app` bundle using `blueprint/launcher.applescript`
9+
* Copy over the Java image from the build folder to the app bundle
10+
* Replace the generated `Info.plist` file with a custom one from the `blueprint` folder
11+
* Compile the sketch file to an icon set `AppIcon.iconset` and replace the default droplet icon with it
12+
13+
The result:
14+
15+
<img src="https://github.com/eschmar/javafx-custom-file-ext-boilerplate/raw/master/images/javafx-custom-file-extension.png" width="420" style="max-width: 420px;" alt="Boilerplate recognising .pew files.">
16+
17+
## requirements
18+
19+
* OpenJFX 12
20+
* OpenJDK 12
21+
* Gradle
22+
23+
## usage
24+
25+
```sh
26+
# run:
27+
make -B
28+
29+
# bundle mac app:
30+
make -B plist icons bundle
31+
```
32+
33+
## Caveats
34+
35+
* The java application itself will not carry the application name specified in the MacOS top menu bar, but will be named `java`. This should be solveable by providing the name as an option (`-Xdock:name="Example App"`) to the shell launcher, however that option has always been ignored for me.
36+
* Since the applescript launcher needs to "stay open", in order to receive further file opening events after launch, the launcher will remain in the Mac dock.
37+
* This is not a standard file structure, App Store would just reject this without further adjustments.

src/main/java/com/example/pew/App.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import javafx.application.Application;
44
import javafx.scene.Scene;
55
import javafx.scene.control.Label;
6-
import javafx.scene.layout.StackPane;
76
import javafx.scene.layout.VBox;
87
import javafx.stage.Stage;
98

@@ -21,8 +20,11 @@ public class App extends Application {
2120
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.APP_OPEN_FILE)) {
2221
Desktop.getDesktop().setOpenFileHandler(event -> {
2322
for (File file : event.getFiles()) {
24-
Operator.parseInput(file.getAbsolutePath());
23+
// Handle file path..
2524
}
25+
26+
final String searchTerm = event.getSearchTerm();
27+
// Handle search term..
2628
});
2729
}
2830
}

0 commit comments

Comments
 (0)