Closed James-Pickett closed 2 years ago
Blocking the main thread is not a runloop - no events can run or be handled etc.
The RunWithExternalLoop
is for toolkits that need to control the main thread - if you are not using one then it will have to be simulated somehow.
This is not trivial as a graphical app (as all systray apps are) must handle the OS event etc.
You can see how Fyne does it at https://github.com/fyne-io/fyne/blob/638ae24e4bebfc0b6dbaabf8db5807eeabfafc61/internal/driver/glfw/driver_desktop.go#L32 - notice how the start and stop variables are stored to be called when the GUI app is ready, and when it will exit.
Thanks for the response @andydotxyz! So if I am understanding correctly, RunWithExternalLoop
should only be used when I have something else running on the main thread that handle the UI loop?
Yes, that is a good way of putting it. Something has to run the mainloop.
@James-Pickett GIOUI might work. Am going to try.
i made a issue here: https://github.com/fyne-io/systray/issues/32
It is unavoidable that some GUI toolkit must own/block the main loop. Fyne, Gio, Qt are all the same in this regard - it is simply required by most operating systems that GUI apps function this way.
Previous versions of systray
only provided Run
which meant that it would block. RunWithExternalLoop
allows you to integrate with another toolkit. The reason there is not an example of using this with Fyne is because we encapsulate it - the whole project is hidden behind myApp.(desktop.App).SetSystemTrayMenu()
- a much cleaner API than the complexity of managing a system tray menu directly :).
Hello,
I'm trying to understand how RunWithExternalLoop works. Calling Run works as expected, but I was trying to see if I can not block the main thread using RunWithExternalLoop, but nothing seems to happen. What am I missing here?
Running on: macOS Montery 12.5 Apple M1 Pro
Thank you for your help!