Skip to content

Inconsistent Icon Name Handling Between Desktop Entry and Icon File Extraction #207

@PeterWang-dev

Description

@PeterWang-dev

Summary

There is an inconsistency in how icon names are handled during AppImage integration in libappimage. When the original icon name in the desktop file contains spaces, the desktop entry is updated with a sanitized version (spaces replaced with underscores), but the icon file extraction process may not correctly match the sanitized name, leading to missing icons in desktop environments like KDE Plasma.

Reproduction Scenario (MVP Demo)

  1. Create an AppImage with an icon file in usr/share/icons/ that has a space in its name (e.g., My App Icon.png).
  2. The corresponding desktop file inside the AppImage should have Icon=My App Icon (without file extension).
  3. Use libappimage to integrate this AppImage into the system (e.g., via AppImageLauncher).
  4. The integrated desktop file will have Icon=appimagekit_<uuid>_My_App_Icon (spaces replaced with underscores).
  5. However, the icon file extraction process may fail to find or correctly handle the original My App Icon.png file due to the mismatch between the sanitized name used for desktop entry and the original name used for file lookup.

Root Cause Analysis

The issue stems from inconsistent handling of icon names in two key locations:

  1. Desktop Entry Update (DesktopEntryEditor::setIcons):

    • Located in DesktopEntryEditor.cpp
    • Uses StringSanitizer(iconName).sanitizeForPath() to replace spaces with underscores when updating the desktop entry's Icon field.
    • Example: My App Icon becomes appimagekit_<uuid>_My_App_Icon
  2. Icon File Lookup (ResourcesExtractor::getIconFilePaths):

    • Located in ResourcesExtractor.cpp
    • Uses the original, unsanitized icon name from the desktop file to search for icon files in the AppImage.
    • Example: Searches for My App Icon in usr/share/icons/ paths

This mismatch means that if the icon file in the AppImage has spaces in its name, the lookup process may fail to find it, or the extracted file may not match the sanitized name expected by the desktop entry.

Steps to Reproduce

  1. Create an AppImage with an icon file in usr/share/icons/ that contains spaces in its name.
  2. Ensure the desktop file inside the AppImage references this icon with spaces in the Icon= field.
  3. Integrate the AppImage using libappimage (e.g., by running it with AppImageLauncher).
  4. Check the integrated desktop file in ~/.local/share/applications/ - it will have a sanitized Icon= field.
  5. Check the integrated icon files in ~/.local/share/icons/hicolor/*/apps/ - they may not match the sanitized name in the desktop file.
  6. The application icon may not appear correctly in desktop environments like KDE Plasma.

Expected Behavior

The icon file lookup and extraction process should use the same sanitized name as used in the desktop entry update, ensuring consistency between the desktop file's Icon field and the actual icon file name.

Actual Behavior

The desktop entry is updated with a sanitized icon name, but the icon file extraction process uses the original, unsanitized name, leading to a mismatch and potentially missing icons.

Proposed Fix

Modify the getIconFilePaths method in ResourcesExtractor to use a sanitized version of the icon name for matching, consistent with how the desktop entry is updated in DesktopEntryEditor::setIcons. This would ensure that both the lookup and the desktop entry reference use the same sanitized name.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions