Invoking xdg-open from a non-Flatpak sandbox

Aziz Ben Ali ba.tahaaziz at gmail.com
Mon Jan 15 11:54:14 UTC 2024


Hello,

I was wondering what the best course of action is regarding providing a
portal-aware xdg-open implementation for non-Flatpak applications. I'm
using various systemd controls to sandbox GNU Emacs (in service form)
and bwrap for Qutebrowser.

After finding out that nested sandboxes are an exercise in futility, I
learned about xdg-desktop-portal and quickly wrote a function that takes
an input URI and passes it onto org.freedesktop.portal.OpenURI. Here's
the code should someone find it helpful:

    (defun browse-url-xdg-desktop-portal (url &rest args)
      "Open URL with the desktop's default portal backend."
      (dbus-call-method :session
                        "org.freedesktop.portal.Desktop"
                        "/org/freedesktop/portal/desktop"
                        "org.freedesktop.portal.OpenURI"
                        "OpenURI"
                        "" url '(:array :signature "{sv}")))

    (setopt browse-url-browser-function #'browse-url-xdg-desktop-portal)

That's worked sufficiently well for following links but I've configured
certain applications like the default viewer for .tex documents within
Emacs to utilize xdg-open instead of hard coding anything specific.

The question is, how should I go about launching potentially sandboxed
target applications through xdg-open in a non-Flatpak setting?

Best regards,
-- 
Aziz


More information about the Flatpak mailing list