When starting sway, it takes a while until waybar has fully started. A possible speed up trick has been documented in sway GitHub, but it’s still delayed from time to time.
The problem is though, that some applications that embed into the system tray which is provided by waybar cannot register themselves in such a case. One part of apps managed to ’late register’ once waybar’s systray then becomes available, but others do not. Examples for the latter are KeepassXC and OnedriveGUI.
In order to work around the issue, I now use this script:
#!/bin/sh
set -u
EXITCODE=1
while [ $EXITCODE -ne 0 ]; do
dbus-send \
--session \
--dest=org.kde.StatusNotifierWatcher \
--type=method_call \
--print-reply "/" org.freedesktop.DBus.Introspectable.Introspect \
>/dev/null
EXITCODE=$?
if [ $EXITCODE -ne 0 ]; then
sleep 1
fi
done
exec "$@"
This queries the DBUS service repeatedly for an interface named org.kde.StatusNotifierWatcher, which seems to be the interface name for systrays (not entirely sure though), waits and repeats until this query gets answered positibely. Once that happens, it will just start the given commandline.
Not perfect, but it does the job for me.
(Update 2023-10-27: this post contains information on the next iteration on the topic)