Search code examples
qtqt5desktop-applicationsnapcraft

Application icon doesn't work with Snap packaging


My desktop file is:

[Desktop Entry]
Name=Heimer
GenericName=Mind map application
Comment=Mind map application
Exec=heimer
Icon=heimer
Type=Application
Categories=Education;
StartupNotify=true

My snapcraft.yaml is:

name: heimer
version: '1.1.0'
summary: Heimer is a simple cross-platform mind map tool.
description: |
  Heimer is a simple cross-platform mind map creation tool.
  Emphasis on easy diagram creation, simplicity, and speed.
grade: stable
confinement: strict
icon: ../../../data/icons/heimer.png

apps:
  heimer:
    command: desktop-launch heimer
    desktop: usr/share/applications/heimer.desktop
    plugs: [home, x11, wayland]

parts:
  gnu-heimer:
    source: ../../../
    plugin: cmake
    configflags:
      - -DCMAKE_BUILD_TYPE=Release
      - -DCMAKE_INSTALL_PREFIX=/usr
    build-packages:
      - qtbase5-dev
      - qttools5-dev
      - qttools5-dev-tools
    stage-packages:
      - libqt5xml5
    after: [desktop-qt5]

CMake installs the application icon to:

# Install icons
install(FILES data/icons/heimer.png DESTINATION share/pixmaps)
install(FILES data/icons/heimer.png DESTINATION share/icons/hicolor/64x64/apps)

Desktop file is installed to:

# Install .desktop files
install(FILES ${CMAKE_BINARY_DIR}/heimer.desktop DESTINATION share/applications)

I don't understand what the problem is. After installing the snap my application always shows the default system icon in the launcher (Ubuntu 18.04). No warning or anything when creating the package or when running it.

Note: This same setup works for Debian packaging. My Debian package uses exactly the same install locations and the icon works just fine in that case.


Solution

  • Currently, Snapcraft does no processing regarding the desktop entries' icons (thus the system can't find the icons as the icons specified in the desktop entries aren't in the icon search directories) and the packager have to manually patch the Icon value to $SNAP/path/to/the/icon.{png,svg} to the .desktop files specified by the apps._app_name_.desktop keys.

    Here’s the

    I've filed a proposal to improve this situation at: Proposal: The apps.<app-name>.icon Key - snapcraft - snapcraft.io