Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xdg-desktop-portal is like half broken #509

Open
fyrk opened this issue Sep 17, 2024 · 4 comments
Open

xdg-desktop-portal is like half broken #509

fyrk opened this issue Sep 17, 2024 · 4 comments

Comments

@fyrk
Copy link

fyrk commented Sep 17, 2024

The fix for #348 in fd00de2 seems to break XDG Portals from within Flatpak on my machine. For example, clicking on a link inside a Flatpak app or opening an attachment in Evolution installed as Flatpak no longer works.

This can be reproduced by running xdg-open from within a Flatpak sandox:

➜ flatpak run --command=sh org.signal.Signal # any flatpak id
[📦 org.signal.Signal ~]$ xdg-open https://example.com/

which will produce the following Journal:

Sep 17 15:46:55 unicornix systemd[3344]: Started app-flatpak-org.mozilla.firefox-169217.scope.
Sep 17 15:46:55 unicornix org.mozilla.firefox.desktop[169228]: Error: no DISPLAY environment variable specified

It works if I re-add

systemd.user.services.niri-flake-polkit = {
  after = [ "graphical-session.target" ];
};

to my config.

@sodiboo
Copy link
Owner

sodiboo commented Sep 17, 2024

I kind of experienced weirdness with xdg-desktop-portal as well, but it was very inconsistent and nonreproducible, and seemed to still manifest when i reverted the changes; which was very weird, why would this break now? as such, i naively assumed that this regression on my system was unrelated to the changes to niri-flake...


I've tested with flatpak like you showed, and the change you made does indeed seem to fix the issue. I've added it in a new commit 318b1ef. In general, my system works fine now, but one very peculiar oddity remains:

xdg-desktop-portal consistently starts about 2 seconds before graphical-session.target. It is also PartOf=graphical-session.target but not After=, and in my mind, this should make sense, because theoretically both niri-flake-polkit and xdg-desktop-portal (and, of course, niri itself) contributes to the graphical session environment. This target is meant to be Before any graphical applications like waybar and swaybg,.. and they work fine... except my waybar now waits for xdg-desktop-portal, which fails to start. eventually, it will restart after total failure, at which point WAYLAND_DISPLAY is available to the graphical-session.target and xdg-desktop-portal will start without issue within <1s... but this in itself takes like 1 minute before it restarts...

so... uh... in theory i'd want xdg-desktop-portal to start After=graphical-session.target, just like niri-flake-polkit? but i can't really touch the xdg-desktop-portal and the flatpak people who designed it are probably way more knowledgeable of how this should work than me and this leads me to believe what niri-flake-polkit was doing is "supposed" to be the correct way... but obviously that doesn't work as-is.

systemd is giving me massive headaches. god this sucks. cc @YaLTeR do you have any idea what do? this shouldn't be nixos-specific and honestly at this point given the interaction i described with xdg-desktop-portal, i give it 50/50 odds that this might actually be a problem with niri's session handling? probably not, since it seems to work just fine on every other distro, but like,,, what else could it be? do you know why xdg-desktop-portal starts 2 seconds before graphical-session.target? (also, niri.service status logs are timestamped to the same as graphical-session.target, including the one logging the Wayland socket name; so xdg-desktop-portal is trying to start before niri started)

@sodiboo sodiboo changed the title niri-flake-polkit fix breaks XDG Portal access from Flatpak xdg-desktop-portal is like half broken Sep 17, 2024
@sodiboo
Copy link
Owner

sodiboo commented Sep 17, 2024

ok systemd is definitely playing a sick fucking joke on me because i set up a BEAUTIFUL little watch window that starts with niri so i could record this to show it happening and OF COURSE now when i wanted to show it off, the xdg-desktop-portal behaves just fine

anywhow, TLDR, current symptoms: everything Works Technically, it just sometimes takes about 2 minutes to start xdg-desktop-portal (but there is no delay when i wanted to record it)

@YaLTeR
Copy link

YaLTeR commented Sep 17, 2024

I think systemd-analyze should have some dependency analysis tools, maybe those can help?

sodiboo added a commit to sodiboo/system that referenced this issue Sep 17, 2024
this is the beautiful little watch window i mentioned in
sodiboo/niri-flake#509
@fyrk
Copy link
Author

fyrk commented Sep 17, 2024

anywhow, TLDR, current symptoms: everything Works Technically, it just sometimes takes about 2 minutes to start xdg-desktop-portal (but there is no delay when i wanted to record it)

Sounds like what I'm experiencing; xdg-portal accesses will just time out after some logins, causing waybar to start delayed, apps to look weird because of missing settings, etc.

One wild guess: During some logouts, xdg-desktop-portal will first stop, and then immediately start during that same second. It's weird, why would it start again during logout? If I then log in quickly (not sure if "quickly" is actually required...), Portals won't work properly.
Does that happen for you, too?

Log excerpt during logout:
Sep 17 22:11:07 unicornix niri[2982]: 2024-09-17T20:11:07.942565Z  INFO niri::input: quitting after confirming exit dialog
[...]
Sep 17 22:11:08 unicornix systemd[2791]: Stopping Portal service...
Sep 17 22:11:08 unicornix systemd[2791]: Stopping flatpak document portal service...
Sep 17 22:11:08 unicornix systemd[2791]: Stopping sandboxed app permission store...
Sep 17 22:11:08 unicornix systemd[2791]: waybar.service: Main process exited, code=exited, status=1/FAILURE
Sep 17 22:11:08 unicornix systemd[2791]: waybar.service: Failed with result 'exit-code'.
Sep 17 22:11:08 unicornix systemd[2791]: Stopped Highly customizable Wayland bar for Sway and Wlroots based compositors..
Sep 17 22:11:08 unicornix systemd[2791]: waybar.service: Consumed 5.045s CPU time, 310.9M memory peak.
Sep 17 22:11:08 unicornix systemd[2791]: Stopped flatpak session helper.
Sep 17 22:11:08 unicornix systemd[2791]: Stopped flatpak portal.
Sep 17 22:11:08 unicornix systemd[2791]: flatpak-portal.service: Consumed 355ms CPU time, 211.2M memory peak.
Sep 17 22:11:08 unicornix systemd[2791]: Stopped sandboxed app permission store.
Sep 17 22:11:08 unicornix systemd[2791]: Stopped Portal service.
Sep 17 22:11:08 unicornix systemd[2791]: Stopped target Current graphical user session.
Sep 17 22:11:08 unicornix systemd[2791]: Reached target Shutdown running niri session.
Sep 17 22:11:08 unicornix dbus-daemon[2817]: [session uid=1000 pid=2817] Activating via systemd: service name='org.freedesktop.portal.Desktop' unit='xdg-desktop-portal.service' requested by ':1.36' (uid=1000 pid=3165 comm="/nix/store/8wz4wrpj5i30h27v2dqbjdkq2lq0r73q-xdg-db" label="kernel")
Sep 17 22:11:08 unicornix systemd[2791]: Stopped flatpak document portal service.
Sep 17 22:11:08 unicornix systemd[2791]: Stopped target Shutdown running niri session.
Sep 17 22:11:08 unicornix systemd[2791]: Starting Portal service...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants