sshtools / two-slices

Simple library for desktop notifications from Java on Windows, Mac OS X and Linux.
Apache License 2.0
37 stars 2 forks source link

Some Issues #2

Open Kotlin-GDE opened 1 year ago

Kotlin-GDE commented 1 year ago

hi

i using java 21, ubuntu 23.10

1.

ScriptEngineManager providers.next(): javax.script.ScriptEngineFactory: Provider apple.applescript.AppleScriptEngineFactory not found
ScriptEngineManager providers.next(): javax.script.ScriptEngineFactory: Provider apple.applescript.AppleScriptEngineFactory not found

why this error and why show twice ?

  1. timeout not work (toast close after default timeout even i specify large amount of seconds)
  2. listeners not triggered (clicked, closed)
  3. customize position of toast
  4. to set icons path, the only way i found is to set an absolute path, so why not allow to use relative path, also how change icons size
  5. more documentation for how to customize toasts
brett-smith commented 4 months ago
  1. This error happens because two-slices is searching for the best provider for the operating system, and Java seems to output this message (with no way to stop it) when you search for script engines that might not exist. The particular implementation doing this (Growl for Mac OS) was long ago deprecated, so should probably be completely removed anyway. For now though, I have made it so it won't even attempt to look unless on Mac OS. That should stop the error for you.

2,3 and 4 will depend on exactly what toaster implementation is being chosen. It's hard to answer exactly without knowing this.

Being as you you state you are on Ubuntu, DBUSNotifyToaster is the most integrated choice. This will require trhat you have dbus-java-transport-native-unixsocket (https://mvnrepository.com/artifact/com.github.hypfvieh/dbus-java-core) included in your project. If you do not have these DBUS libraries, it will then depend on what GUI toolkit your application is using. You'll either end up with the JavaFXToaster, AWTToaster or SWTToaster (if you have the additional library added). If none of these are available, the fallback NotifyToaster uses the notify-send command if it's available.

Timeouts work on all Linux implementations, so I am going to guess you are using the DBUSNotifyToaster or NotifyToaster because there is a known issue on Ubuntu that I sadly cannot do anything about. https://bugs.launchpad.net/ubuntu/+source/notify-osd/+bug/390508

Listeners not being triggered suggests though that you are using NotifyToaster, as this one does not support any kind of events.

The position of the popups can't really changed for any implementation except the two that two-slices fully implements itself, i.e. JavaFXToaster and SWTToaster. For all other types, the position is dictated by the notification backend. If you use either of these two, then the position can be set thusly ..

ToasterSettings settings = new ToasterSettings();
settings.setPosition(Position.TL); // e.g. top left
ToasterFactory.setSettings(settings);

For you final point 5, unfortunately no, you cannot use relative paths. This is because of the question "relative to what?". The icon might be being actually rendered by a totally different process running in a different location.

From the Javadoc ...

All notification systems support absolute path names to file resources, as well as string representations of URLs. Some may support logical names, such as Freedesktop Icon Names like dialog-info.

Note, it should also support resource URLs fine, so you can used icons bundled in jars as resources. Internally though, these are extract to local absolute file paths as that is the lowest common denominator across all implementations,

The size can currently only be set by the SWTToaster. It is unlikely other toasters will ever get support for this.

ToasterSettings settings = new ToasterSettings();
settings.getHints().put(BasicToastHint.ICON_SIZE, 64);
ToasterFactory.setSettings(settings);