xdg-desktop-portal-gnome may be dbus-activated before $DISPLAY is set
I'm not sure if this is the right place to report this, but let me give it a try.
I have a service that starts when GNOME is started and may try to access org.freedesktop.portal.Desktop
before /etc/X11/xinit/xinitrc.d/50-systemd-user.sh
has written DISPLAY
and XAUTHORITY
to systemd's user environment. Then xdg-desktop-portal-gnome fails cannot open display:
, and then I need to wait until the dbus timeout before I can start any apps. (It just looks like the desktop is entirely broken, but then the problem disappears after ~25 seconds.)
I'm on Arch Linux, but NixOS users have similar problems:
- https://github.com/nix-community/home-manager/issues/3628
- https://github.com/NixOS/nixpkgs/issues/206630
Now you could claim my service should have:
Wants=gnome-session-x11-services-ready.target
After=gnome-session-x11-services-ready.target
(Is this the right target to depend on?)
But that doesn't seem to be a solution that is portable to other desktops...
Taking a step away from GNOME, there doesn't seem to be a reliable way to depend on the 50-systemd-user.sh
...
Mar 01 10:14:54 dbus-daemon[40603]: [session uid=1000 pid=40603] Activating via systemd: service name='org.freedesktop.portal.Desktop' unit='xdg-desktop-portal.service' requested by ':1.2' (uid=1000 pid=40597 comm="/usr/bin/emacs --fg-daemon")
Mar 01 10:14:54 systemd[1420]: Starting Portal service...
Mar 01 10:14:54 dbus-daemon[40603]: [session uid=1000 pid=40603] Activating via systemd: service name='org.freedesktop.portal.Documents' unit='xdg-document-portal.service' requested by ':1.3' (uid=1000 pid=40734 comm="/usr/lib/xdg-desktop-portal")
Mar 01 10:14:54 systemd[1420]: Starting flatpak document portal service...
Mar 01 10:14:54 dbus-daemon[40603]: [session uid=1000 pid=40603] Activating via systemd: service name='org.freedesktop.impl.portal.PermissionStore' unit='xdg-permission-store.service' requested by ':1.4' (uid=1000 pid=40738 comm="/usr/lib/xdg-document-portal")
Mar 01 10:14:54 systemd[1420]: Starting sandboxed app permission store...
Mar 01 10:14:54 dbus-daemon[40603]: [session uid=1000 pid=40603] Successfully activated service 'org.freedesktop.impl.portal.PermissionStore'
Mar 01 10:14:54 systemd[1420]: Started sandboxed app permission store.
Mar 01 10:14:54 dbus-daemon[40603]: [session uid=1000 pid=40603] Successfully activated service 'org.freedesktop.portal.Documents'
Mar 01 10:14:54 systemd[1420]: Started flatpak document portal service.
Mar 01 10:14:54 xdg-document-portal[40738]: Ignoring invalid max threads value 4294967295 > max (100000).
Mar 01 10:14:54 dbus-daemon[40603]: [session uid=1000 pid=40603] Activating via systemd: service name='org.freedesktop.impl.portal.desktop.gnome' unit='xdg-desktop-portal-gnome.service' requested by ':1.3' (uid=1000 pid=40734 comm="/usr/lib/xdg-desktop-portal")
Mar 01 10:14:54 systemd[1420]: Starting Portal service (GNOME implementation)...
Mar 01 10:14:54 xdg-desktop-por[40750]: cannot open display:
Mar 01 10:14:54 systemd[1420]: xdg-desktop-portal-gnome.service: Main process exited, code=exited, status=1/FAILURE