Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run on ubuntu 22.04 and get error: Unable to create tray type: '_AppIndicatorNativeTray' #206

Open
RichardFans opened this issue Jan 12, 2024 · 2 comments

Comments

@RichardFans
Copy link

my code is:

package com.richard.ReaderFEP;

import com.richard.ReaderFEP.config.App;
import com.richard.ReaderFEP.trayIcon.JavaFxProvider;
import dorkbox.jna.rendering.RenderProvider;
import dorkbox.systemTray.MenuItem;
import dorkbox.systemTray.SystemTray;
import dorkbox.util.CacheUtil;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;

import java.io.IOException;
import java.util.Objects;

public class RFEPApplication extends Application {

    private SystemTray systemTray;

    @Override
    public void start(Stage stage) throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader(RFEPApplication.class.getResource("main-view.fxml"));
        Scene scene = new Scene(fxmlLoader.load(), 800, 600);
        stage.setOnCloseRequest(event -> {
            hideToTray(stage);
            event.consume();
        });
        stage.setTitle(App.cfg.name + " - " + App.cfg.version);
        stage.setScene(scene);
        Image icon = new Image(Objects.requireNonNull(getClass().getResourceAsStream("/icon.png")));
        stage.getIcons().add(icon);
        setSysTray(stage);  // remove this can run successfully
        stage.show();
    }

    private void setSysTray(Stage stage) {
        RenderProvider.set(new JavaFxProvider());
        SystemTray.DEBUG = true; // for test apps, we always want to run in debug mode


        this.systemTray = SystemTray.get("ReaderFEPSysTray");
        systemTray.setTooltip(App.cfg.name);
        systemTray.setImage(Objects.requireNonNull(getClass().getResourceAsStream("/icon.png")));
        systemTray.getMenu().add(new MenuItem("打开", e -> Platform.runLater(() -> showFromTray(stage))))
                .setShortcut('o');
        systemTray.getMenu().add(new MenuItem("退出", e -> {
            systemTray.shutdown();

            Runnable runnable = () -> {
                stage.hide();
                Platform.exit();
            };

            if (!RenderProvider.isEventThread()) {
                RenderProvider.dispatch(runnable);
            } else {
                runnable.run();
            }
            // System.exit(0);
        })).setShortcut('q');
        ;

    }

    @Override
    public void init() throws Exception {
        super.init();
        App.load();
    }

    private void hideToTray(Stage stage) {
        stage.hide();
    }

    private void showFromTray(Stage stage) {
        stage.setIconified(false);
        stage.show();
        stage.toFront();
    }

    public static void main(String[] args) {
        System.setProperty("logback.configurationFile", "./logback.xml");
        launch();
    }
}

run by:

export GDMSESSION=ubuntu
./gradlew run

output message:

> Configure project :
Project : => 'com.richard.ReaderFEP' Java module

> Task :run FAILED
19:20:39.493 [JavaFX Application Thread] DEBUG dorkbox.systemTray.SystemTray:504 - Version 4.4
19:20:39.495 [JavaFX Application Thread] DEBUG dorkbox.systemTray.SystemTray:505 - OS: Linux
19:20:39.495 [JavaFX Application Thread] DEBUG dorkbox.systemTray.SystemTray:506 - Arch: amd64
19:20:39.495 [JavaFX Application Thread] DEBUG dorkbox.systemTray.SystemTray:511 - Oracle Corporation OpenJDK 64-Bit Server VM 17.0.9
19:20:39.495 [JavaFX Application Thread] DEBUG dorkbox.systemTray.SystemTray:512 - JPMS enabled: true
19:20:39.495 [JavaFX Application Thread] DEBUG dorkbox.systemTray.SystemTray:515 - Is Auto sizing tray/menu? true
19:20:39.495 [JavaFX Application Thread] DEBUG dorkbox.systemTray.SystemTray:516 - Is JavaFX detected? true
19:20:39.495 [JavaFX Application Thread] DEBUG dorkbox.systemTray.SystemTray:517 - Is SWT detected? false
19:20:39.534 [JavaFX Application Thread] DEBUG dorkbox.systemTray.SystemTray:519 - Java Swing L&F: Metal
19:20:39.534 [JavaFX Application Thread] DEBUG dorkbox.systemTray.SystemTray:521 - Auto-detecting tray type
19:20:39.534 [JavaFX Application Thread] DEBUG dorkbox.systemTray.SystemTray:528 - Force GTK2: false
19:20:39.534 [JavaFX Application Thread] DEBUG dorkbox.systemTray.SystemTray:529 - Prefer GTK3: true
19:20:39.554 [JavaFX Application Thread] DEBUG dorkbox.systemTray.SystemTray:136 - Currently using the 'Gnome' desktop environment
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.3 LTS"
PRETTY_NAME="Ubuntu 22.04.3 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.3 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

19:20:39.555 [JavaFX Application Thread] DEBUG dorkbox.systemTray.SystemTray:161 - Currently using the 'ubuntu' session type
19:20:39.562 [OkHttp http://after.test:8080/...] INFO  c.richard.ReaderFEP.MainController:210 - 读卡器和事件请求失败
19:20:39.576 [JavaFX Application Thread] DEBUG dorkbox.jna.linux.GtkLoader:170 - GTK: libgtk-3.so.0
19:20:39.576 [JavaFX Application Thread] DEBUG dorkbox.systemTray.SystemTray:656 - GTK Version: 3.24.33
19:20:39.576 [JavaFX Application Thread] DEBUG dorkbox.systemTray.SystemTray:657 - Is the system already running GTK? true
19:20:39.581 [JavaFX Application Thread] DEBUG dorkbox.jna.linux.AppIndicator:100 - Loaded GTK3 library name 'appindicator3'.
19:20:39.598 [JavaFX Application Thread] DEBUG dorkbox.systemTray.SystemTray:711 - Tray indicator image size: 24
19:20:39.598 [JavaFX Application Thread] DEBUG dorkbox.systemTray.SystemTray:712 - Tray menu image size: 16
19:20:39.602 [JavaFX Application Thread] ERROR dorkbox.systemTray.SystemTray:825 - Unable to create tray type: '_AppIndicatorNativeTray'
java.lang.reflect.InvocationTargetException: null
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
        at dorkbox.systemtray/dorkbox.systemTray.SystemTray.get(SystemTray.java:799)
Exception in Application start method
        at [email protected]/com.richard.ReaderFEP.RFEPApplication.setSysTray(RFEPApplication.java:44)
        at [email protected]/com.richard.ReaderFEP.RFEPApplication.start(RFEPApplication.java:35)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
        at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
        at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
        at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:290)
        at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: java.lang.IllegalAccessError: superclass access check failed: class dorkbox.util.ImageUtil$1 (in module dorkbox.utilities) cannot access class java.awt.Component (in module java.desktop) because module dorkbox.utilities does not read module java.desktop
        at java.base/java.lang.ClassLoader.defineClass1(Native Method)
        at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017)
        at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1095)
        at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:182)
        at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:821)
        at java.base/jdk.internal.loader.BuiltinClassLoader.findClassInModuleOrNull(BuiltinClassLoader.java:741)
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:665)
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
        at dorkbox.systemtray/dorkbox.systemTray.util.ImageResizeUtil.getTransparentImage(ImageResizeUtil.java:64)
        at dorkbox.systemtray/dorkbox.systemTray.util.ImageResizeUtil.getTransparentImage(ImageResizeUtil.java:56)
        at dorkbox.systemtray/dorkbox.systemTray.ui.gtk._AppIndicatorNativeTray.<init>(_AppIndicatorNativeTray.java:106)
        ... 17 common frames omitted

(java:206182): Gdk-WARNING **: 19:20:39.620: XSetErrorHandler() called with a GDK error trap pushed. Don't do that.
java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:465)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:364)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1085)
Caused by: java.lang.RuntimeException: Exception in Application start method
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:901)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
        at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: java.lang.NullPointerException: Cannot invoke "dorkbox.systemTray.SystemTray.setTooltip(String)" because "this.systemTray" is null
        at [email protected]/com.richard.ReaderFEP.RFEPApplication.setSysTray(RFEPApplication.java:45)
        at [email protected]/com.richard.ReaderFEP.RFEPApplication.start(RFEPApplication.java:35)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
        at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
        at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
        at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:290)
        ... 1 more
Exception in thread "JavaFX Application Thread" Exception running application com.richard.ReaderFEP.RFEPApplication
java.lang.IllegalStateException: This operation is permitted on the event thread only; currentThread = JavaFX Application Thread
        at javafx.graphics/com.sun.glass.ui.Application.checkEventThread(Application.java:447)
        at javafx.graphics/com.sun.glass.ui.Application.isNestedLoopRunning(Application.java:548)
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.isNestedLoopRunning(QuantumToolkit.java:1214)
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.enterNestedEventLoop(QuantumToolkit.java:649)
        at javafx.graphics/javafx.stage.Stage.showAndWait(Stage.java:465)
        at javafx.controls/javafx.scene.control.HeavyweightDialog.showAndWait(HeavyweightDialog.java:162)
        at javafx.controls/javafx.scene.control.Dialog.showAndWait(Dialog.java:346)
        at [email protected]/com.richard.ReaderFEP.Dlg.lambda$show$0(Dlg.java:24)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
        at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
        at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
        at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:290)
        at java.base/java.lang.Thread.run(Thread.java:840)

FAILURE: Build failed with an exception.

if I remove setSysTray(stage);,it can run successfully.

@RichardFans
Copy link
Author

RichardFans commented Jan 12, 2024

my build.gradle script:

dependencies {
    ...
    implementation("com.dorkbox:SystemTray:4.4")
   
}

my module-info.java:

module com.richard.ReaderFEP {
    requires javafx.controls;
    requires javafx.fxml;

    requires okhttp3;
    requires retrofit2;
    requires retrofit2.converter.gson;

    requires com.github.benmanes.caffeine;
    requires com.google.gson;
    requires org.controlsfx.controls;
    requires com.dlsc.formsfx;
    requires net.synedra.validatorfx;
    requires org.kordamp.ikonli.javafx;
    requires org.kordamp.ikonli.core;
    requires org.kordamp.ikonli.fontawesome5;
    requires org.kordamp.bootstrapfx.core;
    requires org.yaml.snakeyaml;
    requires java.desktop;
    requires jdk.crypto.ec;

    requires org.slf4j;
    requires ch.qos.logback.classic;
    // requires ch.qos.logback.core;
    requires java.naming;
    requires javafx.swing;
    requires ch.qos.logback.core;
    requires dorkbox.jna;
    requires dorkbox.systemtray;


    opens com.richard.ReaderFEP to javafx.fxml;
    exports com.richard.ReaderFEP;
    exports com.richard.ReaderFEP.config;
    exports com.richard.ReaderFEP.server;
    exports com.richard.ReaderFEP.api.type;
    opens com.richard.ReaderFEP.server to javafx.fxml;
    opens com.richard.ReaderFEP.api.type;
    exports com.richard.ReaderFEP.trayIcon;
    opens com.richard.ReaderFEP.trayIcon to javafx.fxml;
}

other info maybe helpful:
Listing Installed Packages with "appindicator" Keyword:

$ sudo apt list --installed | grep appindicator

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

gnome-shell-extension-appindicator/jammy,jammy,now 42-2~fakesync1 all [installed, automatic]
libayatana-appindicator3-1/jammy,now 0.5.90-7ubuntu2 amd64 [installed]

Installing libappindicator3-dev:

$ sudo apt-get install libappindicator3-dev

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done                 
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 libayatana-appindicator3-1 : Conflicts: libappindicator3-1

Installing libappindicator1 is not working either.
my jdk version is 17(liberica-17)
my javafx version is :

javafx {
    version = '17.0.2'
    modules = ['javafx.controls', 'javafx.fxml', 'javafx.swing']
}

@dorkbox
Copy link
Owner

dorkbox commented Feb 14, 2024

Thank you for the detailed writeup!

It might be related to JavaFX (which is finicky). I’ll look into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants