Tray icon color on Linux

Contrary to Windows where the tray is typically the same color and MacOSX where the OS takes care of colorizing the tray icon itself, on Linux the tray background can be dark or light, and both choices are popular (i.e. ubuntu is dark, mint is light,…). As a consequence a static white or black color for the tray icon will be difficult to see on many desktops.

I have been trying to write some code to dynamically select black o white icons depending on the desktop dark or light mode, but with no luck. You can find my botched code in my Mailspring fork

I found online some documentation about the shouldUseDarkColor from the nativeTheme package, but I did not manage to make it work. Another possible candidate would be isDarkMode from systemPreferences, but also no luck for me.

Please note that I have no knowledge of electron, it is very possible that I did some silly mistake.

There are a few old discussions about this subject, but no real solution.