Autostart flatpak application?

I’ve tried using the RequestBackground method to start an app automatically at login, but it isn’t working for me - even though the response was success, with both background & autostart now being true.

If I pass a normal app as the commandline argument like gedit that works and autostarts. However trying to give it the flatpak app id or the full command of flatpak run <id>, or even /usr/bin/flatpak run <id> doesn’t seem to work. Is there something special I have to do when it is a flatpak app?

I think you might be better off asking this in a portal place/channel or even flatpak :slight_smile:

Anyway, they might need to know, which portal backend your running, to be able to tell you if it’s a bug or not.

Thanks, I will try other channels as well to see if someone knows.

I am using xdg_desktop_portal.

Additional info from troubleshooting…


Using dbus-monitor I can capture the interaction.

Method call

method call time=1690393997.911834 sender=:1.74 -> destination=:1.115 serial=2703 path=/org/freedesktop/portal/desktop; interface=org.freedesktop.impl.portal.Background; member=EnableAutostart
   string ""
   boolean true
   array [
      string "/usr/bin/flatpak"
      string "run"
      string "codes.merritt.Nyrna"
   uint32 0

method return time=1690393997.912268 sender=:1.115 -> destination=:1.74 serial=1674 reply_serial=2703
   boolean true


signal time=1690393997.912469 sender=:1.74 -> destination=:1.751 serial=2704 path=/org/freedesktop/portal/desktop/request/1_751/dart1647111112; interface=org.freedesktop.portal.Request; member=Response
   uint32 0
   array [
      dict entry(
         string "background"
         variant             boolean true
      dict entry(
         string "autostart"
         variant             boolean true

Startup log

Checking logs after signing in for information on attempted launch.

journalctl -xe | grep Nyrna
Jul 24 13:38:03 shodan systemd[17012]: Started app-flatpak-codes.merritt.Nyrna-250100.scope.
Jul 24 13:38:03 shodan systemd[17012]: Started app-gnome-codes.merritt.Nyrna-250100.scope - Application launched by gnome-session-binary.
Jul 24 13:38:03 shodan codes.merritt.Nyrna.desktop[250440]: bwrap: execvp /usr/bin/flatpak: No such file or directory

This error here (bwrap: execvp /usr/bin/flatpak: No such file or directory) seems pertinent, however I am not sure what to do with the information.

The autostart applications should be .desktop-files in ~/.config/autostart/ (or to where $XDG_CONFIG_HOME points). There you can take a look into the file to see what gets executed.

If I read the code & error message correctly: The Portal will add flatpak run, you’re supposed to only provide the name of the executable in the Flatpak sandbox.

The No such file or directory error occurs because there is no flatpak in the sandbox, it’s part of the host.

You can omit the commandline if you just want to run your application’s desktop file:

Commandline to use add when autostarting at login. If this is not specified, the Exec line from the desktop file will be used.

Nice catch! I missed that.

Exactly right. I feel like this could be much better documented… crucially, the portal seems to have different behaviour if it is accessed from within a Flatpaked app vs not - if it is called from within a Flatpak it automatically adds the flatpak run part.

This is really important to note, because it means we can’t test the implementation from a debug environment; it needs to be packaged up into Flatpak to test - this explains the strange behaviour I was seeing.

I tried this and it didn’t work, though that might be a bug with the portal library I am using because it gave a mangled exec line.

TL;DR: setting the commandline to my app’s normal executable, and testing by running from within the Flatpak package resolved the issue for me.

Thank you for your insight, much appreciated! :tada: :blue_heart:

Is this something we should document somehow?

It would be helpful. Important points I can think of:

  • Many of the portal methods are very useful to non-sandboxed apps, but this one seems to be geared very specifically towards Flatpak only.
  • Needs to be run from within a Flatpak sandboxed application, and the commandline argument should likely be the executable name (without path) of the packaged app, same as the Exec line from the app’s .desktop file. (For example, if the sandboxed app was the gnome text editor, it would be commandline: gnome-text-editor).