appstream-generator default-generated "stock" icon results in non-available themed icons being selected
When finishing the last touches for GNOME Software in Alpine Linux / postmarketOS, I bumped into the issue that some high-resolution icons where being displayed as missing, for example like the top icon in this image:
At first, I thought that was because we are missing the highest resolution icons (128x128@2). However, I then installed on my phone, with a 300% resolution scale, and then suddenly all icons but those from installed apps where missing. I did some search, and found out that the reason is that on the lack of a big-enough icon, GS is using themed icons: https://gitlab.gnome.org/GNOME/gnome-software/-/blob/main/lib/gs-app.c#L1965 instead of lower resolution ones. This makes sense for installed apps, where that icon is available. But for non-installed apps, it has the consequence that the icon displayed is just a placeholder. This is partially due to the reason that in the AppStream Component metadata generated by appstream-generator
, every application has a stock icon as below
<icon type="remote" width="48" height="48">org/freac/freac/1bcf5780c9f24aa16006041940c20c79/icons/48x48/freac_org.freac.freac.png</icon>
<icon type="cached" width="64" height="64">freac_org.freac.freac.png</icon>
<icon type="remote" width="64" height="64">org/freac/freac/1bcf5780c9f24aa16006041940c20c79/icons/64x64/freac_org.freac.freac.png</icon>
<icon type="remote" width="128" height="128">org/freac/freac/1bcf5780c9f24aa16006041940c20c79/icons/128x128/freac_org.freac.freac.png</icon>
<icon type="stock">org.freac.freac</icon>
In consequence, due to this: https://gitlab.gnome.org/GNOME/gnome-software/-/blob/main/lib/gs-icon.c#L173 every app gets a themed icon associated and we end up with the wrong icon. I fixed that with the small patch below, but I am not totally sure if it makes sense, since it is something that spans both GS and AppStream
diff --git i/lib/gs-app.c w/lib/gs-app.c
index 51215c7e0..c14bf83e6 100644
--- i/lib/gs-app.c
+++ w/lib/gs-app.c
@@ -1962,7 +1962,9 @@ gs_app_get_icon_for_size (GsApp *app,
GIcon *icon = priv->icons->pdata[i];
guint icon_width = gs_icon_get_width (icon);
- if (icon_width == 0 && G_IS_THEMED_ICON (icon))
+ if (icon_width == 0 &&
+ G_IS_THEMED_ICON (icon) &&
+ gs_app_get_state (app) == GS_APP_STATE_INSTALLED)
return g_object_ref (icon);
}
@pwithnall and @mak since it might need some coordination.