[gnome-software: 14/18] gs-flatpak: Export both sizes of icons from flatpak bundles




commit c58cd3afd05321f021327dba9e742150e6e7f948
Author: Philip Withnall <pwithnall endlessos org>
Date:   Fri Mar 5 12:09:49 2021 +0000

    gs-flatpak: Export both sizes of icons from flatpak bundles
    
    Flatpak currently supports exactly 64px and 128px icons in bundles, and
    no other sizes. Add both of them to the `GsApp` (if available), so that
    the icon choosing code in `GsApp` has more source material to choose
    from.
    
    This means that `GsApp` will more likely be able to choose an icon at a
    requested size without having to scale any pixbufs.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #1147

 plugins/flatpak/gs-flatpak.c | 36 +++++++++++++++++++++++-------------
 1 file changed, 23 insertions(+), 13 deletions(-)
---
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index 84752b78f..981030861 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -3077,14 +3077,12 @@ gs_flatpak_file_to_app_bundle (GsFlatpak *self,
                               GCancellable *cancellable,
                               GError **error)
 {
-       gint size;
        g_autoptr(GBytes) appstream_gz = NULL;
-       g_autoptr(GBytes) icon_data = NULL;
+       g_autoptr(GBytes) icon_data64 = NULL, icon_data128 = NULL;
        g_autoptr(GBytes) metadata = NULL;
        g_autoptr(GsApp) app = NULL;
        g_autoptr(FlatpakBundleRef) xref_bundle = NULL;
        g_autoptr(FlatpakInstalledRef) installed_ref = NULL;
-       g_autoptr(GIcon) icon = NULL;
        const char *origin = NULL;
 
        /* load bundle */
@@ -3140,17 +3138,29 @@ gs_flatpak_file_to_app_bundle (GsFlatpak *self,
                gs_app_set_description (app, GS_APP_QUALITY_LOWEST, "");
        }
 
-       /* load icon */
-       size = 64 * (gint) gs_plugin_get_scale (self->plugin);
-       icon_data = flatpak_bundle_ref_get_icon (xref_bundle, size);
-       if (icon_data == NULL)
-               icon_data = flatpak_bundle_ref_get_icon (xref_bundle, 64);
+       /* Load icons. Currently flatpak only supports exactly 64px or 128px
+        * icons in bundles. */
+       icon_data64 = flatpak_bundle_ref_get_icon (xref_bundle, 64);
+       if (icon_data64 != NULL) {
+               g_autoptr(GIcon) icon = g_bytes_icon_new (icon_data64);
+               gs_icon_set_width (icon, 64);
+               gs_icon_set_height (icon, 64);
+               gs_app_add_icon (app, icon);
+       }
 
-       if (icon_data != NULL)
-               icon = g_bytes_icon_new (icon_data);
-       else
-               icon = g_themed_icon_new ("application-x-executable");
-       gs_app_add_icon (app, icon);
+       icon_data128 = flatpak_bundle_ref_get_icon (xref_bundle, 128);
+       if (icon_data128 != NULL) {
+               g_autoptr(GIcon) icon = g_bytes_icon_new (icon_data128);
+               gs_icon_set_width (icon, 128);
+               gs_icon_set_height (icon, 128);
+               gs_app_add_icon (app, icon);
+       }
+
+       /* Fallback */
+       if (icon_data64 == NULL && icon_data128 == NULL) {
+               g_autoptr(GIcon) icon = g_themed_icon_new ("application-x-executable");
+               gs_app_add_icon (app, icon);
+       }
 
        /* not quite true: this just means we can update this specific app */
        if (flatpak_bundle_ref_get_origin (xref_bundle))


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