dorkbox / SystemTray

Cross-platform SystemTray support for Swing/AWT, macOS, GtkStatusIcon, and AppIndicator on Java 8+
Other
448 stars 58 forks source link

compile error: no such class: sun.lwawt.macosx.event.NSEvent #119

Closed bdw429s closed 1 year ago

bdw429s commented 4 years ago

Getting this error on OpenJDK 11

[ERROR] dorkbox.systemTray.SystemTray: Error changing SystemTray mouse trigger for MacOSX.
javassist.CannotCompileException: [source error] no such class: sun.lwawt.macosx.event.NSEvent
        at javassist.CtBehavior.setBody(CtBehavior.java:474)
        at javassist.CtBehavior.setBody(CtBehavior.java:440)
        at dorkbox.systemTray.util.SystemTrayFixes.fixMacOS(SystemTrayFixes.java:307)
        at dorkbox.systemTray.SystemTray.init(SystemTray.java:1030)
        at dorkbox.systemTray.SystemTray.get(SystemTray.java:1167)
        at runwar.tray.Tray.hookTray(Tray.java:67)
        at runwar.Server.startServer(Server.java:686)
        at runwar.Start.main(Start.java:124)
Caused by: compile error: no such class: sun.lwawt.macosx.event.NSEvent
        at javassist.compiler.MemberResolver.searchImports(MemberResolver.java:479)
        at javassist.compiler.MemberResolver.lookupClass(MemberResolver.java:422)
        at javassist.compiler.MemberResolver.lookupClassByJvmName(MemberResolver.java:329)
        at javassist.compiler.MemberResolver.resolveJvmClassName(MemberResolver.java:519)
        at javassist.compiler.MemberCodeGen.resolveClassName(MemberCodeGen.java:1190)
        at javassist.compiler.CodeGen.atDeclarator(CodeGen.java:757)
        at javassist.compiler.ast.Declarator.accept(Declarator.java:103)
        at javassist.compiler.CodeGen.atStmnt(CodeGen.java:381)
        at javassist.compiler.ast.Stmnt.accept(Stmnt.java:53)
        at javassist.compiler.CodeGen.atStmnt(CodeGen.java:381)
        at javassist.compiler.ast.Stmnt.accept(Stmnt.java:53)
        at javassist.compiler.CodeGen.atMethodBody(CodeGen.java:321)
        at javassist.compiler.Javac.compileBody(Javac.java:228)
        at javassist.CtBehavior.setBody(CtBehavior.java:466)
        ... 7 more
oxodao commented 4 years ago

This library is not JDK11 compliant.

The reason is that SystemTray uses some Java internal classes (Such as things in sun.*) which is no longer allowed with the new module system.

I don't know this could be updated except by re-creating what's missing (Thus probably a lot of C/C++ bindings). I had this issue when I tried to implement Windows' Vibrancy-like feature, getting HWND was possible through sun.* but we can no longer use it so we need to resort to JNI/JNA

dorkbox commented 4 years ago

Sadly, that's correct -- It doesn't work with JPMS yet. I'm working on a solution for it.

bdw429s commented 4 years ago

@dorkbox Thanks for the effort, this library is a big part of my CLI tool that thousands of people use every day and the tray integration is very nice. I appreciate the library and look forward to hopefully finding some workarounds on openjdk in the future :smiley:

dorkbox commented 4 years ago

You're v. welcome! I'm glad others find it useful.

I'll be making a JDK11+ version (and bump the major version, so if you use java 8, then you just use the old one) -- that has a lot less magic in it. It's.... tricky to get it working the way one expects in a cross-platform manner.

bdw429s commented 4 years ago

@dorkbox Sounds great. My users use all manner of JRE versions from 8 and up. Will the new version be compatible with 8 still? Just checking, since I only have one version of my Java-based CLI tool that simply supports 8+.

dorkbox commented 4 years ago

Hm. I might be able to just check for 9+, and disable things if so -- this way your library can stay 8+

bdw429s commented 4 years ago

That would be fantastic if you could get it to fall back nicely. Unfortunately, a lot of CFML developers have been slow to move off of JRE 8 or they are still using older versions of their app server that requires it. I'll probably have to keep supporting it for a few more years :/

NangiDev commented 4 years ago

What is the status on the JDK11 version?

I am getting This operation is permitted on the event thread only; currentThread = GTK Native Event Loop when calling Tornadofx from SystemTray.

When I try suggested solution it says Toolkit not initialized which, if I am understands correctly, are due to some mismatching in java versions

Edit: The suggested solution was to wrap in a runlater runLater { launch<TornadofxApp>() }

dorkbox commented 4 years ago

Just a heads up, I've started working on this project again.

NangiDev commented 4 years ago

I found this thread on forcing javafx/tornadofx into GTK 3

https://stackoverflow.com/a/22457177/3021593

Now I just need to figure out how to call the tornadofx launch method from systemtray thread or based on Not on FX application thread; currentThread = GTK Native Event Loop I guess I need to figure out how to switch to FX thread

dorkbox commented 3 years ago

Java11 + macos is now working.

Thanks for the bug report!

bdw429s commented 3 years ago

WUT? Awesome!!! Looking forward to the release

bdw429s commented 3 years ago

@dorkbox Is this available in a new release yet?

dorkbox commented 3 years ago

Sadly, not yet. I've been stuck in the middle of some 2 major back-to-back releases, and haven't had much time for, quite literally, anything.

This is still the top prio for fixes though, so a release will arrive as soon as the dust from everything else settles.

bdw429s commented 3 years ago

@dorkbox Thanks for the update and let us know if there is anything we can do to help you.

bdw429s commented 2 years ago

@dorkbox I see the 4,.0 milestone was marked complete last week, but I don't see a 4.0 tag. Is the release available anywhere yet or are you still cooking it?

dorkbox commented 2 years ago

Still working on it. (of note, I just fixed some JPMS (and build) dependency issues. so there is progress going forwards on this)

bdw429s commented 2 years ago

@dorkbox Is there any bleeding edge builds we can use of 4.0 to test this? I've been pushing back on my Mac users for a very long time now. Even if I can use a snapshot version with the fix, that would be great.

dorkbox commented 2 years ago

Sadly, no bleeding edge versions that work yet. I’ll see about getting a intermediate release done (still not fully supporting JPMS, but at least there will be fixes for these issues).

bdw429s commented 2 years ago

Thank you, I'm getting pressure to drop this lib due to this issue, so I would love an intermediate release I can test.

oxodao commented 2 years ago

Thank you, I'm getting pressure to drop this lib due to this issue, so I would love an intermediate release I can test.

Well to be honest, unless you are willing to build it yourself, that's pretty much the only lib that will do the job.

Not only in Java but pretty much in all languages (without going full C++ or something like that). There is the vanilla libappindicator but there is no documentation / example for python, and the systray library from getlantern in Golang but it misses some things (No way to remove an item from the menu ???) but that's pretty much it... Or at least that I could find.

Vanilla java systray could do the job but those are based on AWT so they are ugly as hell anyway

I'm on my way to build a systray-based app but it's on hold until I can use this lib properly or find something that would do the job...

lmajano commented 2 years ago

@dorkbox Can we get a fix on this please. I am willing to sponsor this feature and give you either a $250 Amazon gift card or direct cash transfer for your time on this. Will this be of interest to you.

bferdinandus commented 2 years ago

Can we get a fix on this please? My company uses commandbox which relies on this library. Now we get some failues on the new MacBooks with M1 processor.

dorkbox commented 2 years ago

Yes! I’m wokring on it directly! I just recently got an M1, so i’m able to do direct development on it.

dorkbox commented 2 years ago

@lmajano I appreciate the offer, and money is nice, but not necessasry :)

lmajano commented 2 years ago

That’s great 😀!! Anyways we know first hand how hard it is to do open source and most of the time our work is not seen. I just want to let you know that we appreciate your work on this library and we are willing to remunerate and recognize.

We value your work and dedication.

onlyleura commented 2 years ago

Three months later. Any update?

scottsteinbeck commented 2 years ago

@dorkbox We are super excited that this is so close to being resolved, do you have an idea when it will be ready to launch?

dorkbox commented 2 years ago

At the moment, I’m blocked by https://github.com/dorkbox/SystemTray/issues/172#issuecomment-1104865978

dorkbox commented 1 year ago

Sorry this took so long, but it was not easy. I have figured out what exactly is going on, and how to work-around it. macos11 (Big Sur) changed how to create UI elements.

scottsteinbeck commented 1 year ago

Thanks for your hard work!

lmajano commented 1 year ago

@bdw429s

Thanks so much @dorkbox .

onlyleura commented 1 year ago

Good news. Looking forward to seeing this fix in CommandBox.

@bdw429s @lmajano

dorkbox commented 1 year ago

Wrapping up regression testing on windows (macOS and ubuntu are done).