Desktop files and the Exec line

Mar 12, 2022
R

Originally, I am following some documentation that I found here:

https://docs.flatpak.org/en/latest/freedesktop-quick-reference.html#desktop-files

I am finishing off a flatpak app and I’m working on the ‘.desktop’ file. I have managed to write lines in my flatpak yaml file that install the desktop and the img files on my system. Right now the desktop file looks like this:

    [Desktop Entry]
    Name=Gpt Etc.
    Comment=A client for Gpt servers.
    #Exec=/bin/bash -c "flatpak run org.theguy.GptEtc"
    Exec=org.theguy.GptEtc
    Type=Application
    Icon=org.theguy.GptEtc
    Terminal=false

The app works and I can type ‘flatpak run org.theguy.GptEtc’ and it launches. If I use the run-launcher on my system, I can see the entry for ‘GptEtc’ and I can select it. No app opens up at that time.

I can, from the command line, type ‘gtk-launch org.theguy.GptEtc.desktop’ and I get the message below:

    bwrap: execvp org.theguy.GptEtc: No such file or directory

If I switch the commenting on the Exec line, so that the ‘bash’ command is run, I get a message that flatpak cannot be found.

    /bin/bash: line 1: flatpak: command not found 

I can run ‘which flatpak’ and I see it on /usr/bin/flatpak.

How do I write the Exec line so that my flatpak app is run? Thanks for your time.

C

You put the binary you want to execute into Exec (I guess in your case Exec=run.sh). Flatpak will update the desktop file when the application is installed to run through flatpak.

I don’t know why the documentation uses the app-id. Either there is some app-id magic which doesn’t work, the Exec-line is simply wrong or just confusing (maybe there is an org.gnome.Dictionary binary?).

R

Thank you. sorry I’m getting back late. I’m guessing this still works for both system and user installs?

D

I’m facing exactly the same issue. I initially used the app-id, as documented in the docs, but that doesn’t work.

After looking at the files generated when installing the app, I realized that from a desktop file with an exec line like this:

Exec=my-app

…Flatpak will generate a Desktop entry at /var/lib/flatpak/exports/share/applications/org.example.myapp.desktop. This file does not contain Exec=my-app, but this instead:

Exec=/usr/bin/flatpak run --branch=master --arch=x86_64 --command=my-app org.example.myapp

This means that the Exec line of the desktop file provided to flatpak-builder will be run inside the app container, i.e. it must match the command: line in your Flatpak source YAML file.

I wish there was an option to completely ignore the original Exec line in the provided desktop file, and to generate an Exec line without the --command part.

D

Hah, I dug through the Flatpak source, and found the logic where the desktop file is generated/transformed:

The old_exec part is guarded by an if. We cannot omit the Exec from the original desktop file entry (otherwise flatpak-builder complains), but if it’s empty (i.e. Exec=) then the generated desktop file does not contain a --command argument and simply delegates to the default command of the Flatpak.

D

Since this is an open source project, I thought fixing docs is better than just complaining about them:

@radiodee1 would the proposed text have helped you? I would certainly have helped me understanding how things work (at least from my understanding of it).

R

Your addition is good and it would have helped me at the time. Thanks for the extra work figuring the Exec line out. It may help in the future.