Application icon not showing in desktop launcher

My application includes a .desktop file and a .png file in snap/gui, which snapcraft correctly includes in the snap.

However, when I install the snap, the icon is not shown in the launcher. I’m testing on Ubuntu 20.

I see both files in /snap/leibnitz/current/meta/gui, /var/lib/snapd/desktop is included in XDG_DATA_DIRS, and the .desktop file in in /var/lib/snapd/desktop/applications, but /var/lib/snapd/desktop/icons is empty.

If I manually copy my .png to /var/lib/snapd/desktop/icons, then it is shown correctly in the launcher.

Is this a snap bug, or do I need to add something to my snapcraft.yaml?

The source for the app is: https://github.com/jafl/leibnitz

In the snap store, it is: https://snapcraft.io/leibnitz

i dont think that dir is used at all (not sure why snapd crates it, since nothing gets ever copied into it)

see

for proper integration of .desktop and icon files …

It actually does work, it’s just massively undocumented. You can make snaps that place their icon into that folder instead of keeping them embedded internally in the squashfs system. One of the big issues of this approach though is that the icon file would be namespaced, and I don’t think there’s a mechanism by which you can alias the icon file. This then means that it doesn’t really integrate with theming unless handled as a special case, which kind of defeats the point for the time being.

well, so i have to patch the .desktop file anyway to make it use the namespaced icon name … if you have to do this anyway, you can as well just make it point to $SNAP/meta/gui (or $SNAP/usr/share/pixmaps/… ) …

Sure, I don’t actually recommend using the undocumented approach because it confers no benefits (and actually has a disadvantage in that it needs a newish version of snapd, ~2.38?). But I thought I’d just say the folder does actually work and in the future would have a use in enabling icon themes.

OP is definitely better served with the methods in the link :slight_smile:

1 Like

Thanks for the suggestion. I updated my desktop file, but now the version in /var/lib/snapd/desktop is missing the Icon field:

$ cat /snap/nps-svn-client/current/meta/gui/nps-svn-client.desktop 
[Desktop Entry]
Categories=Development;RevisionControl;X-Red-Hat-Base;
Name=NPS Subversion Client
Comment=NPS Subversion Client
Icon=/snap/nps-svn-client/current/meta/gui/nps-svn-client.png
Exec=nps-svn-client
Type=Application
$ cat /var/lib/snapd/desktop/applications/nps-svn-client_nps-svn-client.desktop 
[Desktop Entry]
X-SnapInstanceName=nps-svn-client
Categories=Development;RevisionControl;X-Red-Hat-Base;
Name=NPS Subversion Client
Comment=NPS Subversion Client
Exec=env BAMF_DESKTOP_FILE_HINT=/var/lib/snapd/desktop/applications/nps-svn-client_nps-svn-client.desktop /snap/bin/nps-svn-client
Type=Application

I checked that /snap/nps-svn-client/current/meta/gui/nps-svn-client.png does exist.

You don’t hardcode the path in the desktop file in your snap itself. It’s probably

Icon=${SNAP}/meta/gui/nps-svn-client.png

From the perspective of the host environment, /snap isn’t guaranteed to exist (e.g, some systems prefer to follow the FHS and not include /snap by default, Fedora is one example) and the folder its mounted in might actually be different too (e.g, parallel installation)

Snapd doesn’t actually use the .desktop file as is, it runs some checks on it first for security and consistency, so the internal version is more a template than the actual file.

My main question was why the Icon entry disappeared. The documentation that was referenced above showed putting in a hard coded path.

Desktop entry files in the snap/gui directory

The 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.

Icon=${SNAP}/meta/gui/snapname.png

There is a $SNAP variable at runtime and it does generally resolve how it appears in your example above, but for the purposes here, it does need to be the literal string ${SNAP} and not the substituted form. If you used desktop-file-validate it’d actually complain about this being incorrect, but it isn’t in this case because as you with it not working, it gets rewritten for the host rather than used as-is.

E.G

grep Icon /snap/pinta/current/meta/gui/pinta.desktop 
> Icon=${SNAP}/meta/gui/pinta.png
grep Icon /var/lib/snapd/desktop/applications/pinta_pinta.desktop
> Icon=/snap/pinta/17/meta/gui/pinta.png

This is based on both the .desktop file and the Icon file being in snap/gui in your source repository though, I wouldn’t assume there’d be a difference in how you’ve done it, but it might be worth moving them over to snap/gui in the source repository but still refering to $SNAP/meta/gui in the icon field itself. The latest commit on your master branch has a slightly different setup in snap/gui that I’ve unfortunately no experience with so I can’t 100% say how it’s meant to work.

I needed to log out and than back in again for the icon to show up. I switched to using ${SNAP}, and it works, too. Thank you for your help!

1 Like