JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.9k stars 1.16k forks source link

System tray icon not showing (correctly) with Gnome (Xorg/Wayland) #1847

Open Jeansen opened 2 years ago

Jeansen commented 2 years ago

Currently I am on Debian with Gnome 41.3.

When I run the https://github.com/JetBrains/compose-jb/tree/master/tutorials/Tray_Notifications_MenuBar_new I get two things:

Context menu works in both scenarios.

Note: Tray only works when this extension is installed: https://extensions.gnome.org/extension/615/appindicator-support/ .

On Windows, it works fine. On both systems I can invoke the tray menu, increase the counter and close the application. It's simply that the tray icon itself has issues with Gnome.

Jeansen commented 2 years ago

One addition: dorkbox.systemTray.SystemTray works perfectly fine with an older app I'd like to transition from JavaFX + Kotlin to Compose. That is, I have an tray icon with transparent background, the right icon size in Windows and Gnome (either Xorg or Wayland).

ChrisAJS commented 2 years ago

Fwiw: When using the Tray functionality, I get a JavaEmbeddedFrame task in my task switcher, which does display the requested tray icon.

Also when using multiple monitors, the resultant menu that opens when tapping on the tray icon, may appear on the incorrect display.

(On Gnome 40.4.0 and using X11 windowing system)

Jeansen commented 2 years ago

I tried again with OpenJDK 17, Compose 1.0.1 and Kotlin 1.6.10. Same issues. 1.2.0-alpha01-dev620 does not reveal any changes, either

ChrisAJS commented 1 year ago

I ended up using Dorkbox as @Jeansen recommended. Here's a little snippet on how to get up and running with it:

h3. Gradle dependency

implementation("com.dorkbox:SystemTray:4.1")

h3. Sample use

@Composable
fun DorkTray() {
    val tray by remember { mutableStateOf(SystemTray.get()!!) }

    LaunchedEffect(true) {
        tray.installShutdownHook() // Auto-remove icon when application is killed
        tray.setImage(javaClass.getResourceAsStream("/icon.png")) // Use icon in src/main/resources/icon.png
        tray.menu.add(MenuItem("Click me!").apply {
            setCallback { println("Handled click!") }
        })
    }
}

This should be enough to get someone going if they find themselves here.

Giuliopime commented 11 months ago

Didn't you get this error @ChrisAJS loader 'bootstrap' attempted duplicate class definition for java.awt.TrayIcon. (java.awt.TrayIcon is in module java.desktop of loader 'bootstrap')

Nohus commented 9 months ago

Didn't you get this error @ChrisAJS loader 'bootstrap' attempted duplicate class definition for java.awt.TrayIcon. (java.awt.TrayIcon is in module java.desktop of loader 'bootstrap')

Did you solve this? Getting the same issue. : )

realrubbish commented 1 month ago

Didn't you get this error @ChrisAJS loader 'bootstrap' attempted duplicate class definition for java.awt.TrayIcon. (java.awt.TrayIcon is in module java.desktop of loader 'bootstrap')

Just managed to run the cod of ChrisAJS by setting SystemTray.FORCE_TRAY_TYPE manually before the SystemTray.get() call to Swing on macOS (14.5):

fun DorkTray() {
    SystemTray.FORCE_TRAY_TYPE = SystemTray.TrayType.Swing
    val tray by remember { mutableStateOf(SystemTray.get()!!) }
...
okushnikov commented 2 weeks ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.