[gnome-software/uajain/set-launchable-as-id] appstream: Override <id> with <launchable type="desktop-id"> while parsing appdata files



commit 3eab01bfc538b88302a70bb9ec83e0606bb37adf
Author: Umang Jain <umang endlessm com>
Date:   Thu Oct 10 10:44:50 2019 +0530

    appstream: Override <id> with <launchable type="desktop-id"> while parsing appdata files
    
    Problem statement:
    This has been a recurring problem since a long time now, where
    apps have started to drop the ".desktop" suffix from their <id>
    tag present in their appdata. Reasoning for this change is given
    as the ".desktop" is not really a part of the app-id. Also,
    it's been seen as better aligning with flatpak ref-ids as
    dropping this suffix makes the app-id equivalent to the flatpak
    ref-id.
    
    However, this breaks the mapping between the app's appdata and
    it's desktop file. GNOME Software parses both of these, to merge
    the metadata (ideally) under one GsApp object during refines.
    The appdata supplies information like description and categories
    whereas desktop files supplies information like icon, NoDisplay
    and so on.
    
    So, things will break if metadata parsing of appdata and desktop
    file doesn't converge under one GsApp object. What happens here
    is gnome-software creates an app from a desktop file but could
    not relate to it's appdata file (because ".desktop" mismatch) and
    it ends up creating two GsApp objects, neither of which has full
    metadata from appdata and desktop file. Hence, anyone of these can
    bubble up in the UI with missing icons or info etc.
    
    Solution:
    Apps dropping .desktop suffix adds a <launchable type="desktop-id">
    tag to the appdata. Check for the presence of this tag and override
    the <id> tag, if it doesn't match the <launchable> tag. This makes
    sure that the appdata can still relate to it's desktop file component.
    
    https://phabricator.endlessm.com/T27779

 plugins/core/gs-plugin-appstream.c | 39 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
---
diff --git a/plugins/core/gs-plugin-appstream.c b/plugins/core/gs-plugin-appstream.c
index 1f18693b..20dc3992 100644
--- a/plugins/core/gs-plugin-appstream.c
+++ b/plugins/core/gs-plugin-appstream.c
@@ -66,6 +66,36 @@ gs_plugin_appstream_convert_component_kind (const gchar *kind)
        return kind;
 }
 
+static gboolean
+gs_plugin_appstream_override_app_id_cb (XbBuilderFixup *self,
+                                        XbBuilderNode *bn,
+                                        gpointer user_data,
+                                        GError **error)
+{
+       if (g_strcmp0 (xb_builder_node_get_element (bn), "component") == 0) {
+               g_autoptr(XbBuilderNode) id = xb_builder_node_get_child (bn, "id", NULL);
+               g_autoptr(XbBuilderNode) launchable = xb_builder_node_get_child (bn, "launchable", NULL);
+
+               if (launchable != NULL && id != NULL) {
+                       const gchar *type = xb_builder_node_get_attr (launchable, "type");
+
+                       if (g_strcmp0 (type, "desktop-id") == 0) {
+                               const gchar *app_id = xb_builder_node_get_text (id);
+                               const gchar *launchable_id = xb_builder_node_get_text (launchable);
+
+                               if (app_id != NULL &&
+                                   launchable_id != NULL &&
+                                   g_strcmp0 (app_id, launchable_id) != 0) {
+                                       g_debug ("Overriding appdata app-id %s with <launchable> desktop-id: 
%s",
+                                                app_id, launchable_id);
+                                       xb_builder_node_set_text (id, launchable_id, -1);
+                               }
+                       }
+               }
+       }
+       return TRUE;
+}
+
 static gboolean
 gs_plugin_appstream_upgrade_cb (XbBuilderFixup *self,
                                XbBuilderNode *bn,
@@ -137,6 +167,7 @@ gs_plugin_appstream_load_appdata_fn (GsPlugin *plugin,
 {
        g_autoptr(GFile) file = g_file_new_for_path (filename);
        g_autoptr(XbBuilderFixup) fixup = NULL;
+       g_autoptr(XbBuilderFixup) fixup1 = NULL;
        g_autoptr(XbBuilderNode) info = NULL;
        g_autoptr(XbBuilderSource) source = xb_builder_source_new ();
 
@@ -155,6 +186,14 @@ gs_plugin_appstream_load_appdata_fn (GsPlugin *plugin,
        xb_builder_fixup_set_max_depth (fixup, 3);
        xb_builder_source_add_fixup (source, fixup);
 
+       /* Override <id> with <launchable type="desktop-id"> to establish
+        * desktop file <> appdata mapping */
+       fixup1 = xb_builder_fixup_new ("OverrideAppId",
+                                      gs_plugin_appstream_override_app_id_cb,
+                                      plugin, NULL);
+       xb_builder_fixup_set_max_depth (fixup1, 2);
+       xb_builder_source_add_fixup (source, fixup1);
+
        /* add metadata */
        info = xb_builder_node_insert (NULL, "info", NULL);
        xb_builder_node_insert_text (info, "filename", filename, NULL);


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