[gnome-software/wip/hughsie/search-launchable: 2/2] Use the launchable when processing 'details-activated' from the shell



commit 13c341493920de0b86ec95b48020f1d4c342d420
Author: Richard Hughes <richard hughsie com>
Date:   Tue Jul 16 11:40:42 2019 +0100

    Use the launchable when processing 'details-activated' from the shell
    
    If the app-id in AppStream is different to the launchable then this is never
    going to match. Fixes https://gitlab.gnome.org/GNOME/gnome-software/issues/577

 plugins/core/gs-appstream.c |  1 +
 src/gs-application.c        | 52 +++++++++++++++++++++++++++++++++++++++------
 src/gs-shell.c              |  6 ++++++
 src/gs-shell.h              |  2 ++
 4 files changed, 54 insertions(+), 7 deletions(-)
---
diff --git a/plugins/core/gs-appstream.c b/plugins/core/gs-appstream.c
index 2999ab44..d582cbef 100644
--- a/plugins/core/gs-appstream.c
+++ b/plugins/core/gs-appstream.c
@@ -1074,6 +1074,7 @@ gs_appstream_search (GsPlugin *plugin,
                { AS_APP_SEARCH_MATCH_NAME,     "name[text()~=stem(?)]" },
                { AS_APP_SEARCH_MATCH_KEYWORD,  "keywords/keyword[text()~=stem(?)]" },
                { AS_APP_SEARCH_MATCH_ID,       "id[text()~=stem(?)]" },
+               { AS_APP_SEARCH_MATCH_ID,       "launchable[text()~=stem(?)]" },
                { AS_APP_SEARCH_MATCH_ORIGIN,   "../components[@origin~=stem(?)]" },
                { AS_APP_SEARCH_MATCH_NONE,     NULL }
        };
diff --git a/src/gs-application.c b/src/gs-application.c
index c1d359ae..05a06603 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -547,6 +547,31 @@ search_activated (GSimpleAction *action,
        gs_shell_show_search (app->shell, search);
 }
 
+static void
+_search_launchable_details_cb (GObject *source, GAsyncResult *res, gpointer user_data)
+{
+       GsApp *a;
+       GsApplication *app = GS_APPLICATION (user_data);
+       g_autoptr(GError) error = NULL;
+       g_autoptr(GsAppList) list = NULL;
+
+       list = gs_plugin_loader_job_process_finish (app->plugin_loader, res, &error);
+       if (list == NULL) {
+               g_warning ("failed to find application: %s", error->message);
+               return;
+       }
+       if (gs_app_list_length (list) == 0) {
+               gs_shell_set_mode (app->shell, GS_SHELL_MODE_OVERVIEW);
+               gs_shell_show_notification (app->shell,
+                                           /* TRANSLATORS: we tried to show an app that did not exist */
+                                           _("Sorry! There are no details for that application."));
+               return;
+       }
+       a = gs_app_list_index (list, 0);
+       gs_shell_reset_state (app->shell);
+       gs_shell_show_app (app->shell, a);
+}
+
 static void
 details_activated (GSimpleAction *action,
                   GVariant      *parameter,
@@ -559,17 +584,30 @@ details_activated (GSimpleAction *action,
        gs_application_present_window (app, NULL);
 
        g_variant_get (parameter, "(&s&s)", &id, &search);
+       g_debug ("trying to activate %s:%s for details", id, search);
        if (search != NULL && search[0] != '\0') {
                gs_shell_reset_state (app->shell);
                gs_shell_show_search_result (app->shell, id, search);
        } else {
-               g_autoptr (GsApp) a = NULL;
-               if (as_utils_unique_id_valid (id))
-                       a = gs_plugin_loader_app_create (app->plugin_loader, id);
-               else
-                       a = gs_app_new (id);
-               gs_shell_reset_state (app->shell);
-               gs_shell_show_app (app->shell, a);
+               g_autoptr(GsPluginJob) plugin_job = NULL;
+               if (as_utils_unique_id_valid (id)) {
+                       g_autoptr(GsApp) a = gs_plugin_loader_app_create (app->plugin_loader, id);
+                       gs_shell_reset_state (app->shell);
+                       gs_shell_show_app (app->shell, a);
+                       return;
+               }
+
+               /* find by launchable */
+               plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_SEARCH,
+                                                "search", id,
+                                                "refine-flags", GS_PLUGIN_REFINE_FLAGS_REQUIRE_ICON,
+                                                "dedupe-flags", GS_APP_LIST_FILTER_FLAG_PREFER_INSTALLED |
+                                                                GS_APP_LIST_FILTER_FLAG_KEY_ID_PROVIDES,
+                                                NULL);
+               gs_plugin_loader_job_process_async (app->plugin_loader, plugin_job,
+                                                   app->cancellable,
+                                                   _search_launchable_details_cb,
+                                                   app);
        }
 }
 
diff --git a/src/gs-shell.c b/src/gs-shell.c
index 631c8938..d12e79f0 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -830,6 +830,12 @@ gs_shell_show_event_app_notify (GsShell *shell,
        gtk_widget_set_visible (widget, title != NULL);
 }
 
+void
+gs_shell_show_notification (GsShell *shell, const gchar *title)
+{
+       gs_shell_show_event_app_notify (shell, title, GS_SHELL_EVENT_BUTTON_NONE);
+}
+
 static gchar *
 gs_shell_get_title_from_origin (GsApp *app)
 {
diff --git a/src/gs-shell.h b/src/gs-shell.h
index 984e7b42..24b56f5c 100644
--- a/src/gs-shell.h
+++ b/src/gs-shell.h
@@ -88,5 +88,7 @@ void           gs_shell_setup                 (GsShell        *shell,
                                                 GCancellable   *cancellable);
 gboolean        gs_shell_is_active             (GsShell        *shell);
 GtkWindow      *gs_shell_get_window            (GsShell        *shell);
+void            gs_shell_show_notification     (GsShell        *shell,
+                                                const gchar    *title);
 
 G_END_DECLS


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