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?
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.
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.
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).