codecentric / NSMenuFX

Other
127 stars 26 forks source link

Create NSMenuFX 3.0 for JDK 11+ #36

Closed msgilligan closed 3 years ago

msgilligan commented 4 years ago

Given the rapid improvements in OpenJDK and OpenJFX, the availability of bundled runtimes via jlink and jpackage, the difficulty of supporting the changes in configuration that occurred between JDK 8 and JDK 11, I propose that we create version 3.0 of NSMenuFX that requires JDK 11 at a minimum.

Among other things, this would enable us to include a module-info.jar file and not worry about backward compatibility with JDKs prior to Java 11.

People that need earlier JDKs could use the 2.1.x versions.

0x4a616e commented 3 years ago

I finally managed to find some time to work on a JDK11 version of NSMenuFX:

<dependency>
  <groupId>de.jangassen</groupId>
  <artifactId>nsmenufx</artifactId>
  <version>3.0.0-BETA1</version>
</dependency>

The new version now uses JNA to directly interact with the native menu bar on macOS. This opens a lot of new possibilities like setting a custom dock icon menu wich is now supported as well.

I managed to keep the API almost identical to the 2.X version, the only thing that changed is the package name which is now de.jangassen.nsmenufx, so migrating should be fairly straight forward. It would be awesome if you could give it a try and provide me with some feedback on how things are working!

You can track recent changes here: https://github.com/0x4a616e/NSMenuFX

0x4a616e commented 3 years ago

One already discovered issue seems to be that you may run into this exception when setting the application menu before the first stage has been shown: de.jangassen.exception.LifecycleException I'm working on a fix. If you set the menu After stage.show(), things should be fine.

wiverson commented 3 years ago

Not sure this is the right place (do you have a preferred forum/chat?) but if you added a few additional features from java.awt.Desktop, e.g. notifications, dock icon bounce/icon setting - you'd have a better solution for desktop for JavaFX than what's in the JDK.

e.g. https://gist.github.com/wiverson/d2edf0d66ad195c96793d0d25290753b and https://stackoverflow.com/questions/64616443/how-to-get-awt-window-for-javafx-stage/64651359#64651359 show some of the crazy workarounds to get stuff to work at all right now. :P

0x4a616e commented 3 years ago

Hi Will, I think the best thing to do would be creating issues and mark them as features. Those are some good ideas and they don't sound too hard to implement using native access! My next plan was to add Touch Bar support but maybe I can squeeze some of this in. If you create some issues, it'd be great if you could do that here https://github.com/0x4a616e/NSMenuFX as most of the development will happen there.

0x4a616e commented 3 years ago

I just published an update that should fix the LifecycleException when setting the menu bar before the first stage was shown:

<dependency>
  <groupId>de.jangassen</groupId>
  <artifactId>nsmenufx</artifactId>
  <version>3.0.0-BETA2</version>
</dependency>

It also allows for using macOS native context menus now.

msgilligan commented 3 years ago

I can't wait to try this out!

vewert commented 3 years ago

@0x4a616e Thanks for your work in updating this project, I'm very exited!

Can you create a Issues section in the new (forked) Repository? I looked and couldn't find it. Or should we be creating issues using the old Repository?

0x4a616e commented 3 years ago

My bad, it was indeed missing! I added the issues section now 🙂

0x4a616e commented 3 years ago

It is finally there:

<dependency>
  <groupId>de.jangassen</groupId>
  <artifactId>nsmenufx</artifactId>
  <version>3.0.0</version>
</dependency>
msgilligan commented 3 years ago

I finally upgraded my first projects! Great work!