Desktop entry files are used to add an application to the desktop menu. These files specify the name and icon of your application, the categories it belongs to, related search keywords and more. These files have the extension
.desktop and follow the XDG Desktop Entry Specification version 1.1.
ⓘ Note: The application icon specified in the desktop entry will be used in the desktop menu and the dock, but not in the snap store and other graphical store frontends. The snap store uses the icon specified in the
This documentation explains how to add these desktop files to your snap so that your application is automatically added to the desktop menu during installation.
There are three methods to tell snapcraft which desktop entry files to use.
- Put the desktop entry file in the
desktopkey in the app definition to point to a desktop file in the prime directory.
- Use the desktop entry file from the AppStream metadata of your application.
Desktop entry files in the `snap/gui` directory⚓
The desktop file and icon should be in the folder
snap/gui/ in the source folder for your snap. They should be named
snap-name matches the
name: entry in the
ⓘ Note: When you run
snapcraft, the entire contents of
snap/guiwill be copied into the
meta/gui/folder of the resulting snap.
Exec= line is used to specify which application to run when the user clicks on this desktop entry. It should point to the application in the
apps: section of
app-name matches the name of the program in the
apps: section of
snapcraft.yaml or an approved alias. Note that this is the same (case sensitive) name used to run the snapped application from the commandline.
Icon= line specifies the absolute path of the icon of the application. This icon will represent the application in the desktop menu and the dock. This path should point to the location of the icon after the snap is installed.
snapcraft copies all the contents of the
snap/gui/ folder to
meta/gui, the absolute path of the icon in the installed snap will be
Use the `desktop` key to point to the entry file⚓
Some applications already generate
desktop files as part of the build process. In that case, it might be easier to use the
desktop key of the application because this takes a path relative to the
prime directory, so you can insert a path to the generated desktop entry file.
Using this method, the desktop entry file can have any name. During a build,
snapcraft will properly rename the desktop launcher, based on which app definition the
desktop key is part of.
In this example, the desktop file is generated by the build system and placed in the folder
usr/share/applications/, relative from the root of the resulting snap. Since the
prime folder is what eventually becomes the snap, we specify
usr/share/applications/com.github.johnfactotum.Foliate.desktop as the path to the desktop file.
command: desktop-launch $SNAP/usr/bin/com.github.johnfactotum.Foliate
During a build, snapcraft will also try to change the
Icon= path in the desktop entry file. However, you need to make sure that the
Icon= path is accessible from the
prime folder. This example replaces the icon path after pulling the source.
# Point icon to the correct location
sed -i.bak -e 's|Icon=com.github.johnfactotum.Foliate|Icon=/usr/share/icons/hicolor/scalable/apps/com.github.johnfactotum.Foliate.svg|g' data/com.github.johnfactotum.Foliate.desktop.in
What happens during installation of your snap
During installation, snapd copies the desktop files of the snap to
/var/lib/snapd/desktop/applications/. The keys
Implements are currently not supported and will be silently removed from the desktop file on install. Lines with unknown keys will also be silently removed.