Starting in the background using Portals

David Strauss david at davidstrauss.net
Wed Jul 3 21:38:36 UTC 2019


On Thu, Jun 13, 2019 at 12:43 AM Alexander Larsson <alexl at redhat.com> wrote:

> Yeah, the thing to use here is the background portal (which is kinda
> new, so beware it may not be everywhere yet).
> "org.freedesktop.impl.portal.Background" is actually the backend (thus
> the ".impl"), so what you want to use is
> org.freedesktop.portal.Background.
>
> The docs for that are here:
>
> https://github.com/flatpak/xdg-desktop-portal/blob/master/data/org.freedesktop.portal.Background.xml


While attempting this approach, I'm having issues seeing the interface I
need over D-Bus.

I'm running Fedora 30 Silverblue and Flatpak 1.4.2. Based on the Flatpak
git history and the existence of
/usr/share/dbus-1/interfaces/org.freedesktop.portal.Background.xml on my
system, I'd expect to be able to invoke the interface from my machine.
However, I don't see the Background interface alongside other portals when
I run this command:

busctl --user introspect org.freedesktop.portal.Desktop
/org/freedesktop/portal/desktop

When I attempt to access the interface from Python (within the sandbox), I
get this error:

gi.repository.GLib.Error: g-dbus-error-quark:
GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: No such interface
“org.freedesktop.portal.Background” on object at path
/org/freedesktop/portal/desktop (19)

If I switch the code to using org.freedesktop.portal.Screenshot and the
D-Bus method Screenshot, it works properly, including the method handling
the response signal.



Here is my current code, with self.receive_request_background_signal()
 omitted:

session_bus = Gio.bus_get_sync(Gio.BusType.SESSION, None)
session_proxy = Gio.DBusProxy.new_sync(session_bus,
    Gio.DBusProxyFlags.NONE,
    None,
    "org.freedesktop.portal.Desktop",
    '',
    "org.freedesktop.portal.Request",
    None)

args = GLib.Variant('(sa{sv})', ('', {}))  # @TODO: Add commandline,
autostart, dbus-activatable
result = session_proxy.call_sync('RequestBackground',
    args,
    Gio.DBusCallFlags.NONE,
    -1,
    None)
request_handle = result.unpack()[0]
session_bus.signal_subscribe("org.freedesktop.portal.Desktop",
    "org.freedesktop.portal.Request",
    "Response",
    request_handle,
    None,
    Gio.DBusSignalFlags.NO_MATCH_RULE,
    self.receive_request_background_signal)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/flatpak/attachments/20190703/feceb5ff/attachment.html>


More information about the Flatpak mailing list