DEV Community

Building a simple system tray app with Go

Oscar Mendoza on October 29, 2017

Hands on: Let's build a system tray application that shows us the current local time, with the possibility to choose some other countries. We are ...
Collapse
 
bgadrian profile image
Adrian B.G.

I'm learning Go now and I haven't done a .exe since ages, now it would be a good time to make some developer tools.
:( Tons of ideas - shortage of time.

Collapse
 
kataras profile image
Gerasimos (Makis) Maropoulos • Edited

Good article Oscar, I was implementing a sys tray icon for Iris using this library some months ago but it's not really cross-platform by-default, it requires from user to install some dependencies, i.e some linux packages (on windows systems it works out-of-the-box), so be careful when using this library, your users will not be able to run your package with just go get!

proof-of-concept: github.com/kataras/iris/tree/witht...

Collapse
 
osuka42 profile image
Oscar Mendoza

Thank you @kataras ! I will run this on different OS and update the requirements :)

Collapse
 
barben360 profile image
Barben360

Hi, I think your program may eventually crash if you are unlucky.

Indeed, you have 2 concurrent processes that try to read/write timezone variable. You should have a lock on this variable.

More generally, your algorithm could be more efficient I think, by calling systray.SetTooltip(timezone + " timezone") only when timezone is changed (directly after your switch-case) and calling systray.SetTitle(getClockTime(timezone)) right at the same moment to avoid having a possible 1 second delay between your click and time being changed.

Collapse
 
gelembjuk profile image
Roman Gelembjuk

Did you ever try to use this systray package together with some GUI golang package?
I tried to use GTK gotk3 to build some windows and run it together with github.com/getlantern/systray/ and i was not success.
This systray package blocks access to xwindows system from GTK package.
Do you have such experience?

Collapse
 
romanesko profile image
Roman Bykovskiy

Had the same issue with webview. Found this fork where the problem is solved, take a look: github.com/ghostiam/systray

Collapse
 
foresthoffman profile image
Forest Hoffman

Huh, that's really cool. I didn't know that library existed. Thanks for sharing Oscar!

Collapse
 
ehsun7b profile image
Ehsun Behravesh

Has anyone tried it on Windows 11? It won't work for me.