[gnome-software: 5/15] flatpak: Make listing popular/curated apps asynchronous




commit a5a68dfbb77846dee8a41fdc988758eace58ab22
Author: Philip Withnall <pwithnall endlessos org>
Date:   Wed May 4 11:49:06 2022 +0100

    flatpak: Make listing popular/curated apps asynchronous
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #1472

 plugins/flatpak/gs-plugin-flatpak.c | 38 +++++++++++++++++--------------------
 1 file changed, 17 insertions(+), 21 deletions(-)
---
diff --git a/plugins/flatpak/gs-plugin-flatpak.c b/plugins/flatpak/gs-plugin-flatpak.c
index c8c994b6c..90369d210 100644
--- a/plugins/flatpak/gs-plugin-flatpak.c
+++ b/plugins/flatpak/gs-plugin-flatpak.c
@@ -1861,23 +1861,6 @@ gs_plugin_add_category_apps (GsPlugin *plugin,
        return TRUE;
 }
 
-gboolean
-gs_plugin_add_popular (GsPlugin *plugin,
-                      GsAppList *list,
-                      GCancellable *cancellable,
-                      GError **error)
-{
-       GsPluginFlatpak *self = GS_PLUGIN_FLATPAK (plugin);
-       gboolean interactive = gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_INTERACTIVE);
-
-       for (guint i = 0; i < self->installations->len; i++) {
-               GsFlatpak *flatpak = g_ptr_array_index (self->installations, i);
-               if (!gs_flatpak_add_popular (flatpak, list, interactive, cancellable, error))
-                       return FALSE;
-       }
-       return TRUE;
-}
-
 gboolean
 gs_plugin_add_alternates (GsPlugin *plugin,
                          GsApp *app,
@@ -1952,20 +1935,26 @@ list_apps_thread_cb (GTask        *task,
        GsPluginListAppsData *data = task_data;
        gboolean interactive = (data->flags & GS_PLUGIN_LIST_APPS_FLAGS_INTERACTIVE);
        GDateTime *released_since = NULL;
+       GsAppQueryTristate is_curated = GS_APP_QUERY_TRISTATE_UNSET;
        guint64 age_secs = 0;
        g_autoptr(GError) local_error = NULL;
 
        assert_in_worker (self);
 
-       if (data->query != NULL)
+       if (data->query != NULL) {
                released_since = gs_app_query_get_released_since (data->query);
+               is_curated = gs_app_query_get_is_curated (data->query);
+       }
+
        if (released_since != NULL) {
                g_autoptr(GDateTime) now = g_date_time_new_now_local ();
                age_secs = g_date_time_difference (now, released_since) / G_TIME_SPAN_SECOND;
        }
 
-       /* Currently only support released-since queries. */
-       if (released_since == NULL) {
+       /* Currently only support released-since or is-curated queries (but not both).
+        * Also don’t currently support is-curated==GS_APP_QUERY_TRISTATE_FALSE. */
+       if ((released_since == NULL) == (is_curated == GS_APP_QUERY_TRISTATE_UNSET) ||
+           is_curated == GS_APP_QUERY_TRISTATE_FALSE) {
                g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
                                         "Unsupported query");
                return;
@@ -1974,7 +1963,14 @@ list_apps_thread_cb (GTask        *task,
        for (guint i = 0; i < self->installations->len; i++) {
                GsFlatpak *flatpak = g_ptr_array_index (self->installations, i);
 
-               if (!gs_flatpak_add_recent (flatpak, list, age_secs, interactive, cancellable, &local_error)) 
{
+               if (released_since != NULL &&
+                   !gs_flatpak_add_recent (flatpak, list, age_secs, interactive, cancellable, &local_error)) 
{
+                       g_task_return_error (task, g_steal_pointer (&local_error));
+                       return;
+               }
+
+               if (is_curated != GS_APP_QUERY_TRISTATE_UNSET &&
+                   !gs_flatpak_add_popular (flatpak, list, interactive, cancellable, &local_error)) {
                        g_task_return_error (task, g_steal_pointer (&local_error));
                        return;
                }


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