Getting ready for stable

The only way I got the desktop icon to work was to manually copy the .desktop and .png files using the dump plugin.

  copy-desktop-icon-stuff:
    plugin: dump
    source: snap/gui
    organize:
      pynsource.png: usr/share/applications/pynsource.png
      pynsource.desktop: usr/share/applications/pynsource.desktop

I also had to “organize” the files, otherwise the two files end up in /prime not /prime/usr/share/applications/

I also had to rearrange my source code directory structure so that the snapcraft.yaml file was located in a directory snap and the .desktop and .png files were located in snap/gui. I had previously kept my snapcraft.yaml in the root of my project, and simply had a gui subdirectory containing the .desktop and .png files. This failed to create the entries

squashfs-root/meta/gui/pynsource.png
squashfs-root/meta/gui/pynsource.desktop
squashfs-root/snap/gui/pynsource.png
squashfs-root/snap/gui/pynsource.desktop

and as such, my app’s icon was blank. My .desktop file by the way looks like:

[Desktop Entry]
Name=Pynsource
GenericName=UML application
Comment=Pynsource UML reverse engineer Python source into diagrams
Exec=pynsource
Icon=${SNAP}/meta/gui/pynsource.png
Terminal=false
Type=Application
Categories=Development;
StartupNotify=true

I was also confused for many hours by the different and contradictory information found on the topic of creating desktop icons for a snapcraft app. This post is the closest it seems, to an official bit of documentation (albiet needing the extra steps I have outlined above). There are in the wilds of the internet:

  • posts that refer to icon files needing to be specified in the snapcraft.yaml - this doesn’t seem to be needed in order to define a desktop icon. The official doco says icon means an icon “Path to icon image that represents the snap.” which is quite a vague statement and could be improved.
  • a post by Michael that refer the desktop: share/applications/ rather than desktop: usr/share/applications/ location
  • posts about whether or not the desktop or desktop-legacy plugs are needed (I added them, to be safe)
  • multiple posts from Lin about additional patching being required to make the icon visible, with links to sed and bash scripts and associated entries to snapcraft.yaml - even an official proposal to enhance snapcraft. And even a snapcraft template that looks pretty impressive that adds good info, but also further confused me re how all this works.
  • numerous other posts trying to help with setting up snap desktop icons, with different and contradictory information - some of which preceded 2018. The above items are all 2018 and later, however

In summary:

  • following the instructions in this post do not work unless you add a dump plugin part - otherwise you get Failed to generate snap metadata: The path '/root/prime/usr/share/applications/pynsource.desktop' set for 'desktop' in 'pynsource' does not exist. Make sure that the files are in the prime directory.
  • you must follow the snap/gui directory structure, (not just a gui subdirectory underneath the snapcraft.yaml file location) or else .../meta/gui/ and .../snap/gui/ files are not created.
2 Likes