fyne-io / systray

a cross platfrom Go library to place an icon and menu in the notification area
Apache License 2.0
227 stars 42 forks source link

No systray menu showing on Linux #4

Closed precisionpete closed 2 years ago

precisionpete commented 2 years ago

I have a Go app which needs to run on Linux, Windows, macOS. Getlantern has been a bit flakey for me and I am looking for something better. WebView falls a little short too. But one thing at a time.

I've tried the fyne systray and it works for me on Windows and Mac but not on Linux. Using the example code, I get the Icon but nothing more. Linux is my main development environment. Then I compile it again on Windows and macOS. Not cross-compiled.

I've tested on Linux Mint 20.3 Cinnamon with go 1.18.1. I get the icon and nothing else. It also did the same nothing on Ubuntu 20.04 and nothing at all on Fedora 35. Seems fine on Windows 10 and macOS.

And yes. The getlantern version works fine on the same systems. Except when they release new bugs.

Nothing other than vanilla installs here. In the debug testing, I created clean VMs (VMware 16) using Mint 20.3 (Cinnamon) and Ubuntu 20.04. Nothing special was installed other than the recommended OS updates. The behaviour matched my Development PC's Mint 20.3.

On Fedora 35 I did not get an icon either. But I'm hoping it's part of the same issue.

Using only the example code... And go 1.18.1 on Mint 20.3 Cinnamon. Not a VM but an Intel PC. Also using VScode.

The icon shows up. Hovering over the icon says "Awesome App". Right-click the icon and a tall skinny blank rectangle sometimes pops up (.5" w x 2" h). No text.

Looking forward to getting this going so I can stop using getlantern.

Thanks

go.mod:

module fsystray

go 1.18

require fyne.io/systray v1.9.0

require (
    github.com/godbus/dbus/v5 v5.0.4 // indirect
    golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9 // indirect
)

main.go:

package main

import (
    "fmt"
    "io/ioutil"
    "time"

    "fyne.io/systray"
    "fyne.io/systray/example/icon"
)

func main() {
    onExit := func() {
        now := time.Now()
        ioutil.WriteFile(fmt.Sprintf(`on_exit_%d.txt`, now.UnixNano()), []byte(now.String()), 0644)
    }

    systray.Run(onReady, onExit)
}

func onReady() {
    systray.SetTemplateIcon(icon.Data, icon.Data)
    systray.SetTitle("Awesome App")
    systray.SetTooltip("Lantern")
    mQuit := systray.AddMenuItem("Quit", "Quit the whole app")
    go func() {
        <-mQuit.ClickedCh
        fmt.Println("Requesting quit")
        systray.Quit()
        fmt.Println("Finished quitting")
    }()

    // We can manipulate the systray in other goroutines
    go func() {
        systray.SetTemplateIcon(icon.Data, icon.Data)
        systray.SetTitle("Awesome App")
        systray.SetTooltip("Pretty awesome棒棒嗒")
        mChange := systray.AddMenuItem("Change Me", "Change Me")
        mChecked := systray.AddMenuItemCheckbox("Checked", "Check Me", true)
        mEnabled := systray.AddMenuItem("Enabled", "Enabled")
        // Sets the icon of a menu item. Only available on Mac.
        mEnabled.SetTemplateIcon(icon.Data, icon.Data)

        systray.AddMenuItem("Ignored", "Ignored")

        subMenuTop := systray.AddMenuItem("SubMenuTop", "SubMenu Test (top)")
        subMenuMiddle := subMenuTop.AddSubMenuItem("SubMenuMiddle", "SubMenu Test (middle)")
        subMenuBottom := subMenuMiddle.AddSubMenuItemCheckbox("SubMenuBottom - Toggle Panic!", "SubMenu Test (bottom) - Hide/Show Panic!", false)
        subMenuBottom2 := subMenuMiddle.AddSubMenuItem("SubMenuBottom - Panic!", "SubMenu Test (bottom)")

        systray.AddSeparator()
        mToggle := systray.AddMenuItem("Toggle", "Toggle some menu items")
        shown := true
        toggle := func() {
            if shown {
                subMenuBottom.Check()
                subMenuBottom2.Hide()
                mEnabled.Hide()
                shown = false
            } else {
                subMenuBottom.Uncheck()
                subMenuBottom2.Show()
                mEnabled.Show()
                shown = true
            }
        }

        for {
            select {
            case <-mChange.ClickedCh:
                mChange.SetTitle("I've Changed")
            case <-mChecked.ClickedCh:
                if mChecked.Checked() {
                    mChecked.Uncheck()
                    mChecked.SetTitle("Unchecked")
                } else {
                    mChecked.Check()
                    mChecked.SetTitle("Checked")
                }
            case <-mEnabled.ClickedCh:
                mEnabled.SetTitle("Disabled")
                mEnabled.Disable()
            case <-subMenuBottom2.ClickedCh:
                panic("panic button pressed")
            case <-subMenuBottom.ClickedCh:
                toggle()
            case <-mToggle.ClickedCh:
                toggle()
            case <-mQuit.ClickedCh:
                systray.Quit()
                fmt.Println("Quit2 now...")
                return
            }
        }
    }()
}
andydotxyz commented 2 years ago

For Gnome based desktops you need to install and enable the gnome-shell-extension-appindicator, which we should add to the documentation. With that enabled the icon will certainly appear and the menu should as well.

For the empty menu I appreciate you have tested many different distros, but were they all running the same (cinnamon?) desktop/window manager? I can replicate the empty menu on Cinnamon but wondering if we can narrow it down to just that one software...

precisionpete commented 2 years ago

Mint says:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Linuxmint
Description:    Linux Mint 20.3
Release:    20.3
Codename:   una

$ wmctrl -m
Name: Mutter (Muffin)
Class: N/A
PID: N/A
Window manager's "showing the desktop" mode: N/A

$ cat /etc/X11/default-display-manager
/usr/sbin/lightdm

Ubuntu says:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.4 LTS
Release:    20.04
Codename:   focal

$ wmctrl -m
Name: GNOME Shell
Class: N/A
PID: N/A
Window manager's "showing the desktop" mode: OFF

$ cat /etc/X11/default-display-manager
/usr/sbin/gdm3

Fedora says:

$ lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch
Distributor ID: Fedora
Description:    Fedora release 35 (Thirty Five)
Release:    35
Codename:   ThirtyFive

$ wmctrl -m
Name: GNOME Shell
Class: N/A
PID: N/A
Window manager's "showing the desktop" mode: OFF

Fedora was the worst. I got no icon or anything else. Though, I've not used Fedora in many many years. Is Fedora supposed to work?

rkakrik commented 2 years ago

@precisionpete try to use fyne.io/systray@master (v1.9.1-0.20220331100914-9177bf851614)

andydotxyz commented 2 years ago

Fedora was the worst. I got no icon or anything else. Though, I've not used Fedora in many many years. Is Fedora supposed to work?

Distros that use modern Gnome will need to install an appindicator/systray plugin as they have removed support by default.

andydotxyz commented 2 years ago

OK I think I cracked it, let me know if this PR fixes things please @precisionpete

andydotxyz commented 2 years ago

Going to assume this is resolved as that is what my testing indicates.

mikob commented 2 years ago

@andydotxyz I'm not able to get the current master working on Linux Mint 20.3

2022/05/27 19:29:08 Failed to register our icon with the notifier watcher, maybe no tray running?

andydotxyz commented 2 years ago

@andydotxyz I'm not able to get the current master working on Linux Mint 20.3

Can you be more specific please? Mint ships in 4 variants with different desktop environments. My guess is that the configuration you are using does not have a appindicator compliant system tray (either none at all, or a legacy one?)

mikob commented 2 years ago

Sorry. On the cinnamon default. Here's more:

$ wmctrl -m                                                                                                  
Name: Mutter (Muffin)                                                                                                     
Class: N/A                                                                                                                 
PID: N/A                                                                                                                  
Window manager's "showing the desktop" mode: N/A                                                                           

$ cat /etc/X11/default-display-manager                                                                
/usr/sbin/lightdm   
andydotxyz commented 2 years ago

It looks like "Mutter" means that Gnome is loaded, which means the previous comment applies:

For Gnome based desktops you need to install and enable the gnome-shell-extension-appindicator, which we should add to the documentation. With that enabled the icon will certainly appear and the menu should as well.

Did you try that, and/or does it help?

mikob commented 2 years ago

added that package, not sure how to "enable" it. Doesn't show up in tweaks and there is no ~/.local/share/gnome-extensions Same issue.

andydotxyz commented 2 years ago

Sorry I am no expert and it varies from distro to distro. Or there is the source docs instead https://github.com/ubuntu/gnome-shell-extension-appindicator