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.
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.
desktopkey in the app definition to point to a desktop file in the prime directory.
The desktop file and logo 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
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 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
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.
apps: foliate: command: desktop-launch $SNAP/usr/bin/com.github.johnfactotum.Foliate desktop: usr/share/applications/com.github.johnfactotum.Foliate.desktop plugs: - desktop - desktop-legacy ...
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.
parts: foliate: plugin: meson meson-parameters: [--prefix=/snap/foliate/current/usr] override-pull: | snapcraftctl pull # 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 ...
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.
Last updated 1 year, 1 day ago. Help improve this document in the forum.