[gnome-software/mwleeds/hardcoded-pwa-list: 15/18] make things better




commit 0bbbadbee34d0e98db008420fb73f85b681fe1ef
Author: Phaedrus Leeds <mwleeds protonmail com>
Date:   Wed Mar 23 19:28:13 2022 -0700

    make things better

 plugins/epiphany/gs-plugin-epiphany.c | 32 +++++++++++++++++++++++++++-----
 1 file changed, 27 insertions(+), 5 deletions(-)
---
diff --git a/plugins/epiphany/gs-plugin-epiphany.c b/plugins/epiphany/gs-plugin-epiphany.c
index be7978ece..e155dcb21 100644
--- a/plugins/epiphany/gs-plugin-epiphany.c
+++ b/plugins/epiphany/gs-plugin-epiphany.c
@@ -538,6 +538,8 @@ list_installed_apps_thread_cb (GTask        *task,
                const gchar *name;
                const gchar *url = NULL;
                g_autofree char *icon_path = NULL;
+               g_autofree char *url_hash = NULL;
+               g_autofree char *metainfo_app_id = NULL;
                const gchar *exec;
                int argc;
                g_auto(GStrv) argv = NULL;
@@ -592,9 +594,18 @@ list_installed_apps_thread_cb (GTask        *task,
                g_hash_table_insert (self->url_id_map, g_strdup (url),
                                     g_strdup (desktop_file_id));
 
-               g_debug ("Creating GsApp for webapp with URL %s using app ID from Epiphany: %s",
-                        url, desktop_file_id);
-               app = gs_epiphany_create_app (self, desktop_file_id);
+               /* Generate the app ID used in the AppStream data using the
+                * same method as pwa-metainfo-generator.py in
+                * https://gitlab.gnome.org/mwleeds/gnome-pwa-list
+                * Using this app ID rather than the one provided by Epiphany
+                * makes it possible for the appstream plugin to refine the
+                * GsApp we create.
+                */
+               url_hash = g_compute_checksum_for_string (G_CHECKSUM_SHA1, url, -1);
+               metainfo_app_id = g_strconcat ("org.gnome.Software.WebApp_", url_hash, ".desktop", NULL);
+               g_debug ("Creating GsApp for webapp with URL %s using app ID %s (desktop file id: %s)",
+                        url, metainfo_app_id, desktop_file_id);
+               app = gs_epiphany_create_app (self, metainfo_app_id);
 
                gs_app_set_state (app, GS_APP_STATE_INSTALLED);
                gs_app_set_name (app, GS_APP_QUALITY_NORMAL, name);
@@ -651,6 +662,7 @@ list_installed_apps_thread_cb (GTask        *task,
        for (guint i = 0; i < gs_app_list_length (installed_cache); i++) {
                GsApp *app = gs_app_list_index (installed_cache, i);
                const char *installed_app_id;
+               const char *appstream_source;
 
                installed_app_id = gs_app_get_launchable (app, AS_LAUNCHABLE_KIND_DESKTOP_ID);
                if (installed_app_id == NULL) {
@@ -662,7 +674,12 @@ list_installed_apps_thread_cb (GTask        *task,
                        continue;
 
                /* The app may not be available if it was installed via Epiphany */
-               gs_app_set_state (app, GS_APP_STATE_UNKNOWN);
+               appstream_source = gs_app_get_metadata_item (app, "appstream::source-file");
+               if (appstream_source)
+                       gs_app_set_state (app, GS_APP_STATE_AVAILABLE);
+               else
+                       gs_app_set_state (app, GS_APP_STATE_UNKNOWN);
+
                gs_plugin_cache_remove (GS_PLUGIN (self), gs_app_get_id (app));
        }
 
@@ -927,6 +944,7 @@ gs_plugin_app_remove (GsPlugin      *plugin,
        GsPluginEpiphany *self = GS_PLUGIN_EPIPHANY (plugin);
        const char *installed_app_id;
        const char *url;
+       const char *appstream_source;
 
        if (!gs_app_has_management_plugin (app, plugin))
                return TRUE;
@@ -956,7 +974,11 @@ gs_plugin_app_remove (GsPlugin      *plugin,
                g_hash_table_remove (self->url_id_map, url);
 
        /* The app may not be available if it was installed via Epiphany */
-       gs_app_set_state (app, GS_APP_STATE_UNKNOWN);
+       appstream_source = gs_app_get_metadata_item (app, "appstream::source-file");
+       if (appstream_source)
+               gs_app_set_state (app, GS_APP_STATE_AVAILABLE);
+       else
+               gs_app_set_state (app, GS_APP_STATE_UNKNOWN);
 
        return TRUE;
 }


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