[gnome-software/1927-web-apps-can-t-be-opened-via-show-details-in-the-app-grid] webapps: Search for apps by app id



commit 6f5e3f79ae8fda4508261a00a6663b1bd9429dd6
Author: Milan Crha <mcrha redhat com>
Date:   Tue Sep 27 16:56:58 2022 +0200

    webapps: Search for apps by app id
    
    The `keywords` list is used to search for an (installed) app, to show
    its details, like from the Activities and the app context menu in the Shell.
    No other plugin knows about installed web apps, thus search for them by
    the app id.
    
    Closes https://gitlab.gnome.org/GNOME/gnome-software/-/issues/1927

 plugins/epiphany/gs-plugin-epiphany.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)
---
diff --git a/plugins/epiphany/gs-plugin-epiphany.c b/plugins/epiphany/gs-plugin-epiphany.c
index f0ebec804..cdc8d7b87 100644
--- a/plugins/epiphany/gs-plugin-epiphany.c
+++ b/plugins/epiphany/gs-plugin-epiphany.c
@@ -779,17 +779,20 @@ list_apps_thread_cb (GTask        *task,
        g_autoptr(GsAppList) list = gs_app_list_new ();
        GsPluginListAppsData *data = task_data;
        GsAppQueryTristate is_installed = GS_APP_QUERY_TRISTATE_UNSET;
+       const gchar * const *keywords = NULL;
        g_autoptr(GError) local_error = NULL;
 
        assert_in_worker (self);
 
        if (data->query != NULL) {
                is_installed = gs_app_query_get_is_installed (data->query);
+               keywords = gs_app_query_get_keywords (data->query);
        }
 
        /* Currently only support a subset of query properties, and only one set at once.
         * Also don’t currently support GS_APP_QUERY_TRISTATE_FALSE. */
-       if (is_installed == GS_APP_QUERY_TRISTATE_UNSET ||
+       if ((is_installed == GS_APP_QUERY_TRISTATE_UNSET &&
+            keywords == NULL) ||
            is_installed == GS_APP_QUERY_TRISTATE_FALSE ||
            gs_app_query_get_n_properties_set (data->query) != 1) {
                g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
@@ -805,6 +808,28 @@ list_apps_thread_cb (GTask        *task,
 
        if (is_installed == GS_APP_QUERY_TRISTATE_TRUE)
                gs_plugin_cache_lookup_by_state (GS_PLUGIN (self), list, GS_APP_STATE_INSTALLED);
+       else if (keywords != NULL) {
+               for (guint i = 0; keywords[i]; i++) {
+                       GHashTableIter iter;
+                       gpointer key, value;
+                       g_hash_table_iter_init (&iter, self->url_id_map);
+                       while (g_hash_table_iter_next (&iter, &key, &value)) {
+                               const gchar *url = key;
+                               const gchar *app_id = value;
+                               if (g_strcmp0 (app_id, keywords[i]) == 0) {
+                                       g_autoptr(GsApp) app = NULL;
+                                       g_autofree gchar *url_hash = NULL;
+                                       g_autofree gchar *metainfo_app_id = NULL;
+                                       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);
+                                       app = gs_plugin_cache_lookup (GS_PLUGIN (self), metainfo_app_id);
+                                       if (app != NULL)
+                                               gs_app_list_add (list, app);
+                                       break;
+                               }
+                       }
+               }
+       }
 
        g_task_return_pointer (task, g_steal_pointer (&list), g_object_unref);
 }


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