getlantern / systray

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

systray.Register doesn't work #209

Closed vladimirschuka closed 1 year ago

vladimirschuka commented 3 years ago

Hi, I'm really interested in that project but for some reason it does not work as expected. What I mean: I have done such an example:

var c = make(chan struct{}, 10)

func main() {

    systray.Register(onReady, nil)

mainloop:
    for {
        select {
        case <-c:
            fmt.Println("Quit")
            break mainloop
        }
    }
}

func onReady() {
    systray.SetIcon(icon.Data)
    systray.SetTitle("Awesome App")
    systray.SetTooltip("Pretty awesome超级棒")
    mQuit := systray.AddMenuItem("Quit", "Quit the whole app")
    // Sets the icon of a menu item. Only available on Mac and Windows.
    mQuit.SetIcon(icon.Data)
    mQuit.ClickedCh = c
}

but systray never show up. I found out that onReady() never executed.

I have tried go systray.Run(onReady, nil) but it also doesn't work because of

func init() {
    runtime.LockOSThread()
}

What do I wrong? or it is already known problem.

vivekvardha commented 3 years ago

I am facing same issue.

This is happening when I try to launch the systray in a seperate goroutine. If it is launched in main goroutine, OnReady is getting executed.

I am facing this issue on MAC. However on window it works fine.

xeijin commented 3 years ago

I am facing same issue.

This is happening when I try to launch the systray in a seperate goroutine. If it is launched in main goroutine, OnReady is getting executed.

I am facing this issue on MAC. However on window it works fine.

Running GUI on the main thread is a macos requirement I believe.

Maybe this could help: https://github.com/golang-design/mainthread

anacrolix commented 1 year ago

It must be run on the mainthread on macOS. This has been added to the documentation, thanks!