[gnome-software: 3/4] gs-icon: Work around invalid icon names from some appstream files




commit 3e86354cc5ccffc5ef27fa9e5ce2e99e3e60bc8c
Author: Philip Withnall <pwithnall endlessos org>
Date:   Tue Mar 16 13:36:23 2021 +0000

    gs-icon: Work around invalid icon names from some appstream files
    
    Cached icons are supposed to provide a name (like `krita.png`), `width`
    and `height` attributes, and then gnome-software can build the path to
    the cached icon file according to
    https://www.freedesktop.org/software/appstream/docs/sect-AppStream-IconCache.html#spec-iconcache-location.
    
    Due to a bug in appstream-builder in appstream-glib
    (https://github.com/hughsie/appstream-glib/pull/390), some appstream
    files – for example, rpmfusion-free-33 – had invalid cached icon names,
    which resulted in those icons not being loadable, and not appearing for
    their applications.
    
    As it may take a while for the fix in appstream-builder to be merged and
    be used to regenerate all the appstream files for different app
    repositories, add a workaround in gnome-software.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #1171

 lib/gs-icon.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
---
diff --git a/lib/gs-icon.c b/lib/gs-icon.c
index a88e62d34..955ab0217 100644
--- a/lib/gs-icon.c
+++ b/lib/gs-icon.c
@@ -200,12 +200,22 @@ gs_icon_load_cached (AsIcon *icon)
 {
        const gchar *filename = as_icon_get_filename (icon);
        const gchar *name = as_icon_get_name (icon);
+       g_autofree gchar *name_allocated = NULL;
        g_autofree gchar *full_filename = NULL;
        g_autoptr(GFile) file = NULL;
 
        if (filename == NULL || name == NULL)
                return NULL;
 
+       /* FIXME: Work around https://github.com/hughsie/appstream-glib/pull/390
+        * where appstream files generated with appstream-builder from
+        * appstream-glib, with its hidpi option enabled, will contain an
+        * unnecessary size subdirectory in the icon name. */
+       if (g_str_has_prefix (name, "64x64/"))
+               name = name_allocated = g_strdup (name + strlen ("64x64/"));
+       else if (g_str_has_prefix (name, "128x128/"))
+               name = name_allocated = g_strdup (name + strlen ("128x128/"));
+
        if (!g_str_has_suffix (filename, name)) {
                /* Spec: 
https://www.freedesktop.org/software/appstream/docs/sect-AppStream-IconCache.html#spec-iconcache-location */
                if (as_icon_get_scale (icon) <= 1) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]