Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions plugins/Trayicon/TrayiconPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ def _get_startup_folder():
class ActionsPlugin(object):

def main(self):
# On Linux/BSD pystray's _xorg backend opens an X11 connection at
# import time, which raises Xlib.error.DisplayNameError("") on
# headless boxes (SSH without forwarding, servers, containers, CI).
# Skip the tray icon up-front instead of crashing startup.
if sys.platform not in ("win32", "darwin"):
if not os.environ.get("DISPLAY") and not os.environ.get("WAYLAND_DISPLAY"):
print("Trayicon plugin: no display detected (DISPLAY/WAYLAND_DISPLAY unset), skipping tray icon.")
super(ActionsPlugin, self).main()
return

try:
import pystray
import pystray._base
Expand All @@ -70,6 +80,15 @@ def main(self):
print("Trayicon plugin: pystray or Pillow not installed (%s), skipping tray icon." % err)
super(ActionsPlugin, self).main()
return
except Exception as err:
# pystray's backend selection runs at import time and can raise
# backend-specific errors (e.g. Xlib.error.DisplayNameError on
# X11 systems, AppKit errors on broken macOS installs). Treat
# any import-time failure as "tray unavailable" rather than
# crashing the whole daemon.
print("Trayicon plugin: failed to initialize tray backend (%s), skipping tray icon." % err)
super(ActionsPlugin, self).main()
return

# pystray runs on a real OS thread and uses queue.Queue for signaling.
# gevent.monkey.patch_all() replaces queue.Queue with a cooperative
Expand Down
Loading