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