.desktop file not working

I’m trying to follow the documentation on adding .desktop files here: https://snapcraft.io/docs/desktop-menu-icon-support#heading–snap-gui. I put my .desktop file and icon in my snap/gui folder, and can see them being copied to /meta/gui in the resulting snap package. I’m unclear from reading the documentation if this alone should work but when I launch my app it still uses the system default icon and I cannot launch my application from the menu (Ubuntu 18.04/Gnome). I then try setting the apps.<app-name>.desktop variable to meta/gui/<app-name>.desktop. The documentation says:

A path relative to the prime directory pointing to a desktop file, commonly used to add an application to the launch menu. Snapcraft will take care of the rest.

However, when I do this I get this error:
Failed to generate desktop file: Invalid desktop file 'meta/gui/snapcraft-tkinter.desktop': does not exist (defined in the app 'snapcraft-tkinter').

Code example here: https://github.com/argosopentech/snapcraft-desktop-icon

Looking around online I haven’t been able to find any solutions, any help appreciated!

1 Like
  1. You should not use the desktop keyword and the snap/gui directory together. Remove the desktop keyword; putting the files in snap/gui will do what you want.
  2. The icon isn’t showing because the names are different. argos-translate.png vs snapcraft-tkinter.png.
  3. The reason why you can’t launch the application is because the exec field specifies the argos-translate command instead of snapcraft-tkinter.

That should solve your issues. I also have some more tips:

  • It’s better to use the gnome-3-28 extension instead of the older desktop-glib-only part from desktop-helpers. The gnome-3-28 extension has better desktop integration, boots quicker and snaps built with it are smaller.
  • In general, we try to avoid using snapcraft and snap in the name of the snap because it’s redundant. snap install <app> will always install the snap of the app.
2 Likes

Thanks for the response, I accidentally missed changing the name in two places when I stripped the unrelated code as an example. Also I left “snapcraft” in the name because this isn’t a real app just a demo. I did what you suggested: fixing the naming, and removing the desktop keyword but the icon still doesn’t show up and you can’t launch from the menu. I’ll also try the gnome-3-28 extension but it sounds like you don’t thing that’s the issue. I’ve updated the code in the repository linked in the original question.

The icon path had a typo and the desktop file requires some additional lines in order to be valid. This should do it:

[Desktop Entry]
Name=Snapcraft TkInter
Exec=snapcraft-tkinter
Icon=${SNAP}/meta/gui/snapcraft-tkinter.png
Type=Application

This fixed it thanks!

1 Like