dorkbox / SystemTray

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

SystemTray 4.2 won't load on Windows 10 #184

Open bdw429s opened 1 year ago

bdw429s commented 1 year ago

The SystemTray.get() method is returning null. I'm not sure what you need to know, but here is the full output from the logger.

[DEBUG] dorkbox.systemTray.SystemTray: Version 4.2
[DEBUG] dorkbox.systemTray.SystemTray: OS: Windows 10
[DEBUG] dorkbox.systemTray.SystemTray: Arch: amd64
[DEBUG] dorkbox.systemTray.SystemTray: Oracle Corporation OpenJDK 64-Bit Server VM 11.0.17
[DEBUG] dorkbox.systemTray.SystemTray: JPMS enabled: true
[DEBUG] dorkbox.systemTray.SystemTray: Is Auto sizing tray/menu? true
[DEBUG] dorkbox.systemTray.SystemTray: Is JavaFX detected? false
[DEBUG] dorkbox.systemTray.SystemTray: Is SWT detected? false
[DEBUG] dorkbox.systemTray.SystemTray: Java Swing L&F: Metal
[DEBUG] dorkbox.systemTray.SystemTray: Auto-detecting tray type
[DEBUG] dorkbox.systemTray.SystemTray: Tray indicator image size: 16
[DEBUG] dorkbox.systemTray.SystemTray: Tray menu image size: 14
[ERROR] dorkbox.systemTray.SystemTray: Unable to create tray type: '_WindowsNativeTray'
java.lang.reflect.InvocationTargetException: null
        at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?]
        at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:?]
        at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:?]
        at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:?]
        at dorkbox.systemTray.SystemTray.get(SystemTray.java:799) ~[runwar-4.7.20-SNAPSHOT.jar:4.7.20-SNAPSHOT]
        at dorkbox.systemTray.SystemTray.get(SystemTray.java:171) ~[runwar-4.7.20-SNAPSHOT.jar:4.7.20-SNAPSHOT]
        at runwar.tray.Tray.hookTray(Tray.java:96) ~[runwar-4.7.20-SNAPSHOT.jar:4.7.20-SNAPSHOT]
        at runwar.Server.startServer(Server.java:789) ~[runwar-4.7.20-SNAPSHOT.jar:4.7.20-SNAPSHOT]
        at runwar.Start.main(Start.java:51) ~[runwar-4.7.20-SNAPSHOT.jar:4.7.20-SNAPSHOT]
Caused by: java.lang.NoSuchFieldError: INSTANCE
        at dorkbox.util.CacheUtil.makeCacheFile(CacheUtil.java:395) ~[runwar-4.7.20-SNAPSHOT.jar:4.7.20-SNAPSHOT]
        at dorkbox.util.CacheUtil.create(CacheUtil.java:379) ~[runwar-4.7.20-SNAPSHOT.jar:4.7.20-SNAPSHOT]
        at dorkbox.systemTray.util.ImageResizeUtil.getTransparentImage(ImageResizeUtil.java:63) ~[runwar-4.7.20-SNAPSHOT.jar:4.7.20-SNAPSHOT]
        at dorkbox.systemTray.ui.swing.SwingMenuItem.createTransparentIcon(SwingMenuItem.java:54) ~[runwar-4.7.20-SNAPSHOT.jar:4.7.20-SNAPSHOT]
        at dorkbox.systemTray.ui.swing._WindowsNativeTray.<init>(_WindowsNativeTray.java:87) ~[runwar-4.7.20-SNAPSHOT.jar:4.7.20-SNAPSHOT]
        ... 9 more

Looking at the CacheUtil, it's referencing FileUtil.INSTANCE on that line. The file util class appears to be Kotlin, not Java, but I don't see any references at all to an INSTANCE property. Please advise.

dorkbox commented 1 year ago

Are you excluding dependencies?

bdw429s commented 1 year ago

To be honest, I'm not sure. I'm doing whatever the build did for version 3.17. I know just enough about Gradle to generally feel stupid and this build was setup by another developer who's no longer around :)

Here are the Gradle dependencies:

https://github.com/Ortus-Solutions/runwar/blob/systemtray-4.2/dependencies.gradle

bdw429s commented 1 year ago

If you want to inspect the jar produced by my build, you can see it here.

https://s3.amazonaws.com/downloads.ortussolutions.com/cfmlprojects/runwar/4.8.00-SNAPSHOT/runwar-4.8.00-SNAPSHOT.jar

The system tray lib is being "shaded" into an uber-jar along with other libraries. Let me know if anything in particular is missing. One thing that I'm a little unsure of is I have some direct dependencies on JNA and I see the latest SystemTray lib now has a jna folder.

dorkbox commented 1 year ago

I've uploaded an example of using the system tray + gradle: https://git.dorkbox.com/dorkbox/SystemTray_Test

dorkbox commented 1 year ago

Additionally, if you clone the system tray git repo, you can run the "jarExample" task, and it will create a fatjar of all dependencies + the example code (which is easy enough to just remove from the jar file)

dorkbox commented 1 year ago

looking at your uber-jar, you can remove all of the JNA targets that you don't care about.

Screenshot 2023-01-19 at 00 29 13

dorkbox commented 1 year ago

I can think of a few other things:

bdw429s commented 1 year ago

@dorkbox Thanks for the ideas on reducing jar size. Do you have any help on the error though

java.lang.NoSuchFieldError: INSTANCE
        at dorkbox.util.CacheUtil.makeCacheFile(CacheUtil.java:395) 

While the Gradle examples are cool, I generally would rather gouge my eyes out with dull spoons than make major changes to this Gradle build. Every time I've needed to do anything to it, 3 unrelated things break downstream. It's enough to drive me to violence :) If there's a specific dependency I'm missing or excluding, let me know. The main part my build that uses SystemTray (and worked for years with the 3.x versions) is

    dorkboxDependency("com.dorkbox:SystemTray:${systemTrayVersion}") {
        exclude group: 'ch.qos.logback', module: 'logback-core'
        exclude group: 'ch.qos.logback', module: 'logback-classic'
    }

So unless the logback stuff is now a requirement in 4.x, I'll need some help understanding the error.

bdw429s commented 1 year ago

Just to respond categorically to a few of your size related points (I'm not sure why you merged that discussion here since it really was unrelated entirely to the error on this ticket!)

you can remove all of the JNA targets that you don't care about.

I need all of them :) This project is bundled in a CLI tool that supports all OSs (windows, linux and friends, Mac) all architectures (intel, ARM, etc). all versions of java back to 8 and needs to be to a point where it can be dropped in and "just work". I don't have the liberty of knowing where on God's green earth my users will install my tool, from Alpine docker images to Raspberry Pis.

Log4J is really horrible (yet insanely popular)

Yeah, sounds about right, but that ship is sort of sailed and I'm married to Log4j for now. My tool is used to start java servlets with JBoss Undertow primarily for running any of dozens of versions of Adobe ColdFusion or Lucee Server (A JVM Scripting language/application platform), each of which are a massive collection of Apache Commons libraries, and more OSGI bundles than you can shake a stick at. I'm capture log messages from libs using Log4j, SLF4J, JBoss Logging, you name it. Right now, Log4j is the tool we gather all those into to deal with and that's not changing any time soon.

Bouncycastle isn't particularly needed with java11 now

I still need to support Java 8.

use jlink to create an optimized JVM

Oh, wouldn't it be nice to live in a world where I had the liberty of choosing that JVM my users had installed, lol. The upstream tool for all of this (CommandBox CLI) is a stand alone binary that you can drop onto any machine that has Java and it will use the Windows registry, env vars, folder conventions, and the PATH to rustle up any java binary it can find to use. Not only do I have little to no control over the JRE, the very nature of the CFML app servers is a highly dynamic JIT compiled JVM language which could classload any conceivable java library out there that's bundled with the end users web app, and that essentially makes it impossible to ever know ahead of time what classes may or may not be class loaded at runtime. So yeah, the jlink stuff is really cool, but I doubt I'll ever be able to use it for my tool which promises a swiss army knife servlet server that can run any app. And even if I could, I'm not sure I'd want to. Outside of pre-compiled Java apps in a Docker container, I've never cared for the idea of a tool bundling its own JRE. I don't want to have 50 JREs on my hard drive if I have 50 tools that require Java.

dorkbox commented 1 year ago

RE: the error. I think I know what's going on.

From looking at the uberjar, you're also using Notify.... and there might be jar version conflicts. I'll go through and update notify + tweenengine (and whatever other deps you've included in the uber-jar) this weekend.

bdw429s commented 1 year ago

you're also using Notify.... and there might be jar version conflicts.

Ahh, that would make sense. I did check ensure there were no updates to the Notify library, but it didn't occur to me you may not have tested them together. We use both the system tray and the notify library at the same time and it's so seamless, I sometimes forget they are actually separate libs. I'm so used to immediately seeing the toaster popup confirming my action when I click an item in the system tray menu.

I'll look forward to testing the updated Notify lib alongside system tray.

dorkbox commented 1 year ago

Still working on updating all the projects. There is... a lot.

dorkbox commented 1 year ago

Done with the updates -- fixing an issue where shake can prevent notifications from moving.

bdw429s commented 1 year ago

Excellent, I'll grab the latest Notify and give it a shot once I see it pop into Maven (3.7 is still the latest at the time I write this) https://central.sonatype.com/artifact/com.dorkbox/Notify/3.7

dorkbox commented 1 year ago

I've finished updating libraries. The API for Notify has changed slightly. Can I send you the jars for notify + systemtray (the dependencies are on maven) to make sure it's working as expected for you?

bdw429s commented 1 year ago

Sure. You can reach me at brad at bradwood.com

dorkbox commented 1 year ago

notify-systemtray-alpha.zip

bdw429s commented 1 year ago

Hi @dorkbox and thanks for all the work! It took me some time to figure out the new API changes, but I have my project compiling on the latest versions with the following changes.

Changed the imports

import dorkbox.notify.Pos;
import dorkbox.util.OS;

to

import dorkbox.notify.Position;
import dorkbox.os.OS;

I had to remove the import and usage of dorkbox.util.ActionHandler as I'm not sure where it's gone or what's replaced it. (Maybe you can help there)

I changed calls like

OS.isMacOsX()

to

OS.INSTANCE.isMacOsX()

Is that correct?

And calls like

Notify.create()

to

Notify.Companion.create()

Is that correct?

I had to remove calls to

.darkStyle()

in the Notify builder as I'm not sure what the replacement is for that. Maybe you can help there.

Doing all of that allowed my code to compile, however I'm not getting good results when I start up the process which creates the tray menu. These are used in the context of starting up a server where

For reference, in the PREVIOUS version of Notify and SystemTray, this is what those looked like: image

image

And, here is the console output on the old WORKING versions

[TRACE] Runwar: SystemTray Version: 3.17
[DEBUG] dorkbox.systemTray.SystemTray: OS: Windows 10
[DEBUG] dorkbox.systemTray.SystemTray: Arch: amd64
[DEBUG] dorkbox.systemTray.SystemTray: Oracle Corporation OpenJDK 64-Bit Server VM 11.0.18
[DEBUG] dorkbox.systemTray.SystemTray: Is Auto sizing tray/menu? true
[DEBUG] dorkbox.systemTray.SystemTray: Is JavaFX detected? false
[DEBUG] dorkbox.systemTray.SystemTray: Is SWT detected? false
[DEBUG] dorkbox.systemTray.SystemTray: Java Swing L&F: Metal
[DEBUG] dorkbox.systemTray.SystemTray: Auto-detecting tray type
[DEBUG] dorkbox.systemTray.SystemTray: Tray indicator image size: 16
[DEBUG] dorkbox.systemTray.SystemTray: Tray menu image size: 14
[INFO ] dorkbox.systemTray.SystemTray: Successfully loaded type: _WindowsNativeTray
[WARN ] dorkbox.systemTray.SystemTray: Please disable tooltips, as they are not consistent across all platforms and tray types.

On the new versions of Notify and SytemTray, the Notify popup simply doesn't appear at all. The tray icon and menu are present, but the menu items have no text or images, the submenus don't work, and clicking the menu items does nothing. Also, there are errors in the console about loading image files.

Here is what the new non-functional tray looks like:

image

And here is the console output:

[DEBUG] dorkbox.systemTray.SystemTray: Version 4.2.2
[DEBUG] dorkbox.systemTray.SystemTray: OS: Windows 10
[DEBUG] dorkbox.systemTray.SystemTray: Arch: amd64
[DEBUG] dorkbox.systemTray.SystemTray: Oracle Corporation OpenJDK 64-Bit Server VM 11.0.18
[DEBUG] dorkbox.systemTray.SystemTray: JPMS enabled: true
[DEBUG] dorkbox.systemTray.SystemTray: Is Auto sizing tray/menu? true
[DEBUG] dorkbox.systemTray.SystemTray: Is JavaFX detected? false
[DEBUG] dorkbox.systemTray.SystemTray: Is SWT detected? false
[DEBUG] dorkbox.systemTray.SystemTray: Java Swing L&F: Metal
[DEBUG] dorkbox.systemTray.SystemTray: Auto-detecting tray type
[DEBUG] dorkbox.systemTray.SystemTray: Tray indicator image size: 16
[DEBUG] dorkbox.systemTray.SystemTray: Tray menu image size: 14
[INFO ] dorkbox.systemTray.SystemTray: Successfully loaded type: _WindowsNativeTray
[WARN ] dorkbox.systemTray.SystemTray: Please disable tooltips, as they are not consistent across all platforms and tray types.
[DEBUG] dorkbox.systemTray.SystemTray: Resizing image to 16 : C:\Users\Brad\.CommandBox\cfml\system\config\server-icons\trayicon-lucee-32px.png
[DEBUG] dorkbox.systemTray.SystemTray: Resizing image to 16 : C:\Users\Brad\.CommandBox\cfml\system\config\server-icons\trayicon-lucee-32px.png
[DEBUG] dorkbox.systemTray.SystemTray: Resizing image-stream to 14
[ERROR] dorkbox.systemTray.SystemTray: Error getting image size. Using error icon instead
java.io.IOException: Stream Closed
        at java.io.FileInputStream.readBytes(Native Method) ~[?:?]
        at java.io.FileInputStream.read(Unknown Source) ~[?:?]
        at dorkbox.util.IO.copyStream(IO.java:118) ~[runwar-4.8.2-SNAPSHOT.jar:4.8.2-SNAPSHOT]
        at dorkbox.systemTray.util.ImageResizeUtil.makeByteArrayInputStream(ImageResizeUtil.java:234) ~[runwar-4.8.2-SNAPSHOT.jar:4.8.2-SNAPSHOT]
        at dorkbox.systemTray.util.ImageResizeUtil.resizeAndCache(ImageResizeUtil.java:165) ~[runwar-4.8.2-SNAPSHOT.jar:4.8.2-SNAPSHOT]
        at dorkbox.systemTray.util.ImageResizeUtil.shouldResizeOrCache(ImageResizeUtil.java:362) ~[runwar-4.8.2-SNAPSHOT.jar:4.8.2-SNAPSHOT]
        at dorkbox.systemTray.MenuItem.realizeImageFile(MenuItem.java:176) ~[runwar-4.8.2-SNAPSHOT.jar:4.8.2-SNAPSHOT]
        at dorkbox.systemTray.MenuItem.bind(MenuItem.java:196) ~[runwar-4.8.2-SNAPSHOT.jar:4.8.2-SNAPSHOT]
        at dorkbox.systemTray.ui.swing.SwingMenu.lambda$add$0(SwingMenu.java:103) ~[runwar-4.8.2-SNAPSHOT.jar:4.8.2-SNAPSHOT]
        at java.awt.event.InvocationEvent.dispatch(Unknown Source) ~[?:?]
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source) ~[?:?]
        at java.awt.EventQueue$4.run(Unknown Source) ~[?:?]
        at java.awt.EventQueue$4.run(Unknown Source) ~[?:?]
        at java.security.AccessController.doPrivileged(Native Method) ~[?:?]
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) ~[?:?]
        at java.awt.EventQueue.dispatchEvent(Unknown Source) ~[?:?]
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) ~[?:?]
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) ~[?:?]
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) ~[?:?]
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source) ~[?:?]
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source) ~[?:?]
        at java.awt.EventDispatchThread.run(Unknown Source) ~[?:?]
[DEBUG] dorkbox.systemTray.SystemTray: Resizing image-stream to 14
[ERROR] dorkbox.systemTray.SystemTray: Error getting image size. Using error icon instead

The stack trace and error is repeated 5 times-- probably for each icon used.

The icons being used can be found here: https://github.com/Ortus-Solutions/commandbox/tree/development/src/cfml/system/config/server-icons

I can't find any errors in the logs that seem related to the Notify not working. It just seems to be failing silently.

Please let me know if there's more information I can help provide or maybe some steps I've missed to use the new version of the library correctly.

As a reference, here is the basic code using Notify https://github.com/Ortus-Solutions/runwar/blob/develop/src/main/java/runwar/LaunchUtil.java#L385-L425 And here is where we use SystemTray-- note the menus are completely dynamic in this app and configurable by the user, so this code is pretty generic and spread out: https://github.com/Ortus-Solutions/runwar/blob/develop/src/main/java/runwar/tray/Tray.java#L96

dorkbox commented 1 year ago

I'll take a look!

dorkbox commented 1 year ago

For the most part, it's right.

.theme(Theme.defaultDark)

is what you're looking for.

I'm looking at the rest.

bdw429s commented 1 year ago

This code does not compile (cannot find symbol) :

.theme(Theme.defaultDark)

Did you perhaps mean this?

.theme(Theme.Companion.getDefaultDark())
dorkbox commented 1 year ago

Yup, sorry -- that was kotlin notation! Yours is correct for Java notation.

dorkbox commented 1 year ago

do you have a branch I can check out and build? I'm not sure why it's not working properly for you.

bdw429s commented 1 year ago

Hmm, I can commit it to a branch, but I'm not sure how to have you test it. SystemTray and Notify are embedded in a Java library that's embedded in a CFML-based CLI tool. And while it's incredibly easy to just grab the CLI and run

> server start

that's several layers removed from where the Dorkbox libs are plugged in.

Ok, I've committed the changes to this branch https://github.com/Ortus-Solutions/runwar/tree/systemtray-4.2 You can build the jar with gradlew in the root. The way runwar is called is with a huge list of JVM args and it actually reads the tray menu details from a file. The easiest way to run it in its natural habitat is probably to grab the latest CommandBox CLI (native binary for Mac, Linux, Win) and fire up a server which uses both Notify and System Tray.

https://www.ortussolutions.com/products/commandbox#download

It may be useful to know what OS you're on (for instance, the latest version of CommandBox disables the Dorkbox libs by default on MacOS due to all the issues we've had). I've only tried it on Windows thus far. If all this is a little too much to follow, I'd happily jump on a Zoom call or something just to show you how it works. I really appreciate you taking the time to help debug this and I'm very excited to get this new version up and running.

dorkbox commented 1 year ago

I'll give that a go soonish. I'm currently working on some network issues, and can swap over once it's sorted.

I really appreciate you taking the time to help debug this and I'm very excited to get this new version up and running.

You're welcome. My users have such different use-cases, and I just want something that works, and works well across a wide variety of systems. :)

szempy commented 1 year ago

I am having a similar problem but only with openjdk with all versions from 9-19 if i start my program in oracle jdk it is running correctly.

11:27:46.500 [AWT-EventQueue-0] DEBUG dorkbox.systemTray.SystemTray - Version 4.2.1
11:27:46.502 [AWT-EventQueue-0] DEBUG dorkbox.systemTray.SystemTray - OS: Windows 10
11:27:46.502 [AWT-EventQueue-0] DEBUG dorkbox.systemTray.SystemTray - Arch: amd64
11:27:46.508 [AWT-EventQueue-0] DEBUG dorkbox.systemTray.SystemTray - Oracle Corporation OpenJDK 64-Bit Server VM 15.0.2
11:27:46.509 [AWT-EventQueue-0] DEBUG dorkbox.systemTray.SystemTray - JPMS enabled: true
11:27:46.509 [AWT-EventQueue-0] DEBUG dorkbox.systemTray.SystemTray - Is Auto sizing tray/menu? true
11:27:46.510 [AWT-EventQueue-0] DEBUG dorkbox.systemTray.SystemTray - Is JavaFX detected? false
11:27:46.511 [AWT-EventQueue-0] DEBUG dorkbox.systemTray.SystemTray - Is SWT detected? false
11:27:46.511 [AWT-EventQueue-0] DEBUG dorkbox.systemTray.SystemTray - Java Swing L&F: Metal
11:27:46.512 [AWT-EventQueue-0] DEBUG dorkbox.systemTray.SystemTray - Auto-detecting tray type
java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
        at com.sun.jna.Structure.newInstance(Structure.java:1782)
        at com.sun.jna.Structure$FFIType.get(Structure.java:2007)
        at com.sun.jna.Structure$FFIType.get(Structure.java:1981)
        at com.sun.jna.Native.register(Native.java:1750)
        at dorkbox.jna.JNA.register(JNA.java:66)
        at dorkbox.jna.windows.User32_64.<clinit>(User32_64.java:47)
        at dorkbox.jna.windows.User32.<clinit>(User32.java:40)
        at dorkbox.systemTray.util.SizeAndScalingWindows.getTrayImageSize(SizeAndScalingWindows.java:89)
        at dorkbox.systemTray.util.SizeAndScaling.getTrayImageSize(SizeAndScaling.java:56)
        at dorkbox.systemTray.SystemTray.get(SystemTray.java:707)
        at dorkbox.systemTray.SystemTray.get(SystemTray.java:171)
        at TachosafeRDU.Main.CreateAndShowTray(Main.java:1347)
        at TachosafeRDU.Main.access$000(Main.java:64)
        at TachosafeRDU.Main$1.run(Main.java:241)
        at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:316)
        at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
        at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
        at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
        at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
        at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
        at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
        at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
        at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
        at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
        at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
        at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Caused by: java.lang.AbstractMethodError: Receiver class com.sun.jna.platform.win32.WinDef$POINT$ByValue does not define or inherit an implementation of the resolved method 'abstract java.util.List getFieldOrder()' of abstract class com.sun.jna.Structure.
        at com.sun.jna.Structure.fieldOrder(Structure.java:952)
        at com.sun.jna.Structure.getFields(Structure.java:1006)
        at com.sun.jna.Structure.deriveLayout(Structure.java:1172)
        at com.sun.jna.Structure.calculateSize(Structure.java:1097)
        at com.sun.jna.Structure.calculateSize(Structure.java:1049)
        at com.sun.jna.Structure.useMemory(Structure.java:339)
        at com.sun.jna.Structure.<init>(Structure.java:191)
        at com.sun.jna.Structure.<init>(Structure.java:182)
        at com.sun.jna.Structure.<init>(Structure.java:178)
        at com.sun.jna.platform.win32.WinDef$POINT.<init>(WinDef.java:1159)
        at com.sun.jna.platform.win32.WinDef$POINT$ByValue.<init>(WinDef.java:1132)
        ... 32 more
Exception in thread "AWT-EventQueue-0" java.lang.ExceptionInInitializerError
        at dorkbox.jna.windows.User32.<clinit>(User32.java:40)
        at dorkbox.systemTray.util.SizeAndScalingWindows.getTrayImageSize(SizeAndScalingWindows.java:89)
        at dorkbox.systemTray.util.SizeAndScaling.getTrayImageSize(SizeAndScaling.java:56)
        at dorkbox.systemTray.SystemTray.get(SystemTray.java:707)
        at dorkbox.systemTray.SystemTray.get(SystemTray.java:171)
        at TachosafeRDU.Main.CreateAndShowTray(Main.java:1347)
        at TachosafeRDU.Main.access$000(Main.java:64)
        at TachosafeRDU.Main$1.run(Main.java:241)
        at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:316)
        at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
        at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
        at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
        at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
        at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
        at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
        at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
        at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
        at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
        at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
        at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Caused by: java.lang.IllegalArgumentException: Exception thrown while instantiating an instance of class com.sun.jna.platform.win32.WinDef$POINT$ByValue
        at com.sun.jna.Structure.newInstance(Structure.java:1801)
        at com.sun.jna.Structure$FFIType.get(Structure.java:2007)
        at com.sun.jna.Structure$FFIType.get(Structure.java:1981)
        at com.sun.jna.Native.register(Native.java:1750)
        at dorkbox.jna.JNA.register(JNA.java:66)
        at dorkbox.jna.windows.User32_64.<clinit>(User32_64.java:47)
        ... 21 more
Caused by: java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
        at com.sun.jna.Structure.newInstance(Structure.java:1782)
        ... 26 more
Caused by: java.lang.AbstractMethodError: Receiver class com.sun.jna.platform.win32.WinDef$POINT$ByValue does not define or inherit an implementation of the resolved method 'abstract java.util.List getFieldOrder()' of abstract class com.sun.jna.Structure.
        at com.sun.jna.Structure.fieldOrder(Structure.java:952)
        at com.sun.jna.Structure.getFields(Structure.java:1006)
        at com.sun.jna.Structure.deriveLayout(Structure.java:1172)
        at com.sun.jna.Structure.calculateSize(Structure.java:1097)
        at com.sun.jna.Structure.calculateSize(Structure.java:1049)
        at com.sun.jna.Structure.useMemory(Structure.java:339)
        at com.sun.jna.Structure.<init>(Structure.java:191)
        at com.sun.jna.Structure.<init>(Structure.java:182)
        at com.sun.jna.Structure.<init>(Structure.java:178)
        at com.sun.jna.platform.win32.WinDef$POINT.<init>(WinDef.java:1159)
        at com.sun.jna.platform.win32.WinDef$POINT$ByValue.<init>(WinDef.java:1132)
        ... 32 more
szempy commented 1 year ago

I think i found out the problem cause. I was using the jna dependency in some library and it was not the same what dorkbox used. I have set it to the same as the latest version build uses and now it is working :)

        <dependency>
            <groupId>net.java.dev.jna</groupId>
            <artifactId>jna</artifactId>
            <version>5.12.1</version>
        </dependency>
bdw429s commented 1 year ago

@dorkbox Any luck yet with my instructions above on reproducing the issues? How can I help move this along? I'm working on a new major release of my tool and it would be great to have the systemtray and notify bits updated and working.

bdw429s commented 11 months ago

@dorkbox Any new findings?

dorkbox commented 10 months ago

I don’t know what happened to my GitHub notifications — but they were getting sent to my spam folder.

I’m looking at this right now, and will have it sorted in the 4.5 release.

dorkbox commented 9 months ago

Can you give this a test. I’ve updated a few pieces.

bdw429s commented 9 months ago

Thanks for the ping. Just to confirm, this is the 4.5 release and it's already out on Maven?

dorkbox commented 9 months ago

4.5 is waiting to make sure you don’t have any issues. I can always release it, then as necessary fix+release again (but I prefer not to)

dorkbox commented 9 months ago

I can also just upload the current artifacts in this thread

scottsteinbeck commented 8 months ago

Hey @dorkbox, thank you for working on a fix for this issue.

I have tested the latest version on CommandBox on macOS 14.2.
Unfortunately, we are still experiencing issues.

On my machine the tray menu never shows up, and the console shows an error with the dpi and image size. Here is a stack trace

[TRACE] Runwar: SystemTray Version: 4.5
[TRACE] Runwar: Settting SystemTray.DEBUG = true
[TRACE] Runwar: Initializing tray
[DEBUG] dorkbox.systemTray.SystemTray: Version 4.5
[DEBUG] dorkbox.systemTray.SystemTray: OS: Mac OS X
[DEBUG] dorkbox.systemTray.SystemTray: Arch: aarch64
[DEBUG] dorkbox.systemTray.SystemTray: Oracle Corporation OpenJDK 64-Bit Server VM 11.0.21
[DEBUG] dorkbox.systemTray.SystemTray: JPMS enabled: true
[DEBUG] dorkbox.systemTray.SystemTray: Is Auto sizing tray/menu? true
[DEBUG] dorkbox.systemTray.SystemTray: Is JavaFX detected? false
[DEBUG] dorkbox.systemTray.SystemTray: Is SWT detected? false
[DEBUG] dorkbox.systemTray.SystemTray: Auto-detecting tray type
[DEBUG] dorkbox.systemTray.SystemTray: Successfully added getLocation() to macOS AWT tray menus
[DEBUG] dorkbox.systemTray.SystemTray: Successfully added images/tooltips to macOS AWT tray menus
[ERROR] Getting DPI!94
[DEBUG] dorkbox.systemTray.SystemTray: Tray image size: 20
[DEBUG] dorkbox.systemTray.SystemTray: Tray menu image size: 16
[DEBUG] dorkbox.systemTray.SystemTray: SystemDPI: 94
[DEBUG] dorkbox.systemTray.SystemTray: System Scale: 1.0
[INFO ] dorkbox.systemTray.SystemTray: Successfully loaded type: Osx
[TRACE] Runwar: Initialized
[WARN ] dorkbox.systemTray.SystemTray: Please disable tooltips, as they are not consistent across all platforms and tray types.
[TRACE] Runwar: trying to load icon: /Users/userfolder/.CommandBox/cfml/system/config/server-icons/trayicon-lucee.png
[DEBUG] dorkbox.systemTray.SystemTray: Resizing image to 20 : /Users/userfolder/.CommandBox/cfml/system/config/server-icons/trayicon-lucee.png
[DEBUG] dorkbox.systemTray.SystemTray: Resizing image to 20 : /Users/userfolder/.CommandBox/cfml/system/config/server-icons/trayicon-lucee.png
[TRACE] Runwar: trying to load icon: /Users/userfolder/.CommandBox/cfml/system/config/server-icons/stop.png
[TRACE] Runwar: trying to load icon: /Users/userfolder/.CommandBox/cfml/system/config/server-icons/restart.png
[TRACE] Runwar: trying to load icon: /Users/userfolder/.CommandBox/cfml/system/config/server-icons/open.png
[TRACE] Runwar: trying to load icon: /Users/userfolder/.CommandBox/cfml/system/config/server-icons/folder.png
[TRACE] Runwar: trying to load icon: /Users/userfolder/.CommandBox/cfml/system/config/server-icons/folder.png
[TRACE] Runwar: trying to load icon: /Users/userfolder/.CommandBox/cfml/system/config/server-icons/home.png
[TRACE] Runwar: trying to load icon: /Users/userfolder/.CommandBox/cfml/system/config/server-icons/server_settings.png
[TRACE] Runwar: trying to load icon: /Users/userfolder/.CommandBox/cfml/system/config/server-icons/web_settings.png
[TRACE] Runwar: trying to load icon: /Users/userfolder/.CommandBox/cfml/system/config/server-icons/info.png
[TRACE] Runwar: trying to load icon: /Users/userfolder/.CommandBox/cfml/system/config/server-icons/folder.png
[TRACE] Runwar: trying to load icon: /Users/userfolder/.CommandBox/cfml/system/config/server-icons/home.png
[TRACE] Runwar: trying to load icon: /Users/userfolder/.CommandBox/cfml/system/config/server-icons/runAsync.png
[TRACE] Runwar: trying to load icon: /Users/userfolder/.CommandBox/cfml/modules/commandbox-fusionreactor/fusion_reactor.png
[DEBUG] Runwar: hooked system tray
[DEBUG] Runwar: Starting open browser action
[INFO ] Runwar: Server is up - http-port:8083 stop-port:50722 PID:69827 version 4.8.3-SNAPSHOT
[DEBUG] dorkbox.systemTray.SystemTray: Auto-fixing right-click for macOS system tray
[DEBUG] dorkbox.systemTray.SystemTray: Resizing image-stream to 16
[ERROR] dorkbox.systemTray.SystemTray: Error getting image size. Using error icon instead
java.io.IOException: Stream Closed
        at java.io.FileInputStream.readBytes(Native Method) ~[?:?]
        at java.io.FileInputStream.read(Unknown Source) ~[?:?]
        at dorkbox.util.IO.copyStream(IO.java:123) ~[runwar-4.8.6-SNAPSHOT.jar:4.8.3-SNAPSHOT]
        at dorkbox.systemTray.util.ImageResizeUtil.makeByteArrayInputStream(ImageResizeUtil.java:234) ~[runwar-4.8.6-SNAPSHOT.jar:4.8.3-SNAPSHOT]
        at dorkbox.systemTray.util.ImageResizeUtil.resizeAndCache(ImageResizeUtil.java:165) ~[runwar-4.8.6-SNAPSHOT.jar:4.8.3-SNAPSHOT]
        at dorkbox.systemTray.util.ImageResizeUtil.shouldResizeOrCache(ImageResizeUtil.java:362) ~[runwar-4.8.6-SNAPSHOT.jar:4.8.3-SNAPSHOT]
        at dorkbox.systemTray.MenuItem.realizeImageFile(MenuItem.java:176) ~[runwar-4.8.6-SNAPSHOT.jar:4.8.3-SNAPSHOT]
        at dorkbox.systemTray.MenuItem.bind(MenuItem.java:196) ~[runwar-4.8.6-SNAPSHOT.jar:4.8.3-SNAPSHOT]
        at dorkbox.systemTray.ui.osx.AwtOsxMenu.lambda$add$0(AwtOsxMenu.java:88) ~[runwar-4.8.6-SNAPSHOT.jar:4.8.3-SNAPSHOT]
        at java.awt.event.InvocationEvent.dispatch(Unknown Source) ~[?:?]
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source) ~[?:?]
        at java.awt.EventQueue$4.run(Unknown Source) ~[?:?]
        at java.awt.EventQueue$4.run(Unknown Source) ~[?:?]
        at java.security.AccessController.doPrivileged(Native Method) ~[?:?]
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) ~[?:?]
        at java.awt.EventQueue.dispatchEvent(Unknown Source) ~[?:?]
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) ~[?:?]
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) ~[?:?]
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) ~[?:?]
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source) ~[?:?]
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source) ~[?:?]
        at java.awt.EventDispatchThread.run(Unknown Source) ~[?:?]