[gnome-software/wip/jrocha/fix_popular_override: 4/4] Fix popular-overrides



commit bab12d3f008d9bfa8c95b6f3d5254451bcd193b7
Author: Joaquim Rocha <jrocha endlessm com>
Date:   Fri Mar 31 21:41:32 2017 +0200

    Fix popular-overrides
    
    When the popular overrides setting is set, we need to add that app to
    the global cache and refine the apps in order for them to be considered.
    
    With this fix now the popular-overrides setting can also receive unique
    ids to fine tune which apps should be visible.

 lib/gs-plugin-loader.c |   51 ++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 47 insertions(+), 4 deletions(-)
---
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index 5f6f5f3..f1266ba 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -1696,6 +1696,24 @@ gs_plugin_loader_get_installed_finish (GsPluginLoader *plugin_loader,
 
 /******************************************************************************/
 
+static GsApp *
+gs_plugin_loader_get_app_by_id (GsPluginLoader *plugin_loader,
+                               const gchar *id)
+{
+       g_autofree gchar *unique_id = NULL;
+
+       if (!as_utils_unique_id_valid (id)) {
+               unique_id = as_utils_unique_id_build (AS_APP_SCOPE_UNKNOWN,
+                                                     AS_BUNDLE_KIND_UNKNOWN,
+                                                     NULL,
+                                                     AS_APP_KIND_UNKNOWN,
+                                                     id,
+                                                     NULL);
+               id = unique_id;
+       }
+       return gs_plugin_loader_app_create (plugin_loader, id);
+}
+
 static void
 gs_plugin_loader_get_popular_thread_cb (GTask *task,
                                        gpointer object,
@@ -1717,12 +1735,37 @@ gs_plugin_loader_get_popular_thread_cb (GTask *task,
                apps = g_settings_get_strv (priv->settings, "popular-overrides");
        if (apps != NULL && g_strv_length (apps) > 0) {
                guint i;
-               job->list = gs_app_list_new ();
+               GsAppList *list = gs_app_list_new ();
+               job->action = GS_PLUGIN_ACTION_REFINE;
+
                for (i = 0; apps[i] != NULL; i++) {
-                       g_autoptr(GsApp) app = gs_app_new (apps[i]);
-                       gs_app_add_quirk (app, AS_APP_QUIRK_MATCH_ANY_PREFIX);
-                       gs_app_list_add (job->list, app);
+                       const gchar *app_id = apps[i];
+                       gboolean match_any_prefix = TRUE;
+                       g_autoptr(GsApp) app =
+                               gs_plugin_loader_get_app_by_id (plugin_loader, apps[i]);
+
+                       if (!app) {
+                               g_warning ("Failed to create popular app from id '%s'",
+                                          apps[i]);
+                               continue;
+                       }
+
+                       if (as_utils_unique_id_valid (app_id)) {
+                               g_auto(GStrv) id_split = g_strsplit (app_id, "/", -1);
+                               match_any_prefix = g_strv_contains (id_split, "*");
+                       }
+                       if (match_any_prefix)
+                               gs_app_add_quirk (app, AS_APP_QUIRK_MATCH_ANY_PREFIX);
+
+                       gs_app_list_add (list, app);
+               }
+               if (!gs_plugin_loader_run_refine (job, list, cancellable, &error)) {
+                       g_warning ("Failed to refine list of popular-overrides: %s; "
+                                  "continuing nonetheless...",
+                                  error->message);
+                       g_clear_error (&error);
                }
+               job->list = list;
        } else {
                /* do things that would block */
                job->function_name = "gs_plugin_add_popular";


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