[gnome-software/1688-reloading-view-upon-install] gs-category-page: Refresh content from scratch only when the content is invalid



commit 53a21d0ebc39c02e72805055907fce590565e12d
Author: Milan Crha <mcrha redhat com>
Date:   Mon Aug 22 16:59:18 2022 +0200

    gs-category-page: Refresh content from scratch only when the content is invalid
    
    Track when the content is valid and when not and refresh the content
    with complete removal of the previous data only if the content is invalid.
    It helps to not lost scroll position when any of the plugins request
    the page reload.
    
    Closes https://gitlab.gnome.org/GNOME/gnome-software/-/issues/1688

 src/gs-category-page.c | 60 ++++++++++++++++++++++++++++++--------------------
 1 file changed, 36 insertions(+), 24 deletions(-)
---
diff --git a/src/gs-category-page.c b/src/gs-category-page.c
index 0df2efcef..c0f79b30d 100644
--- a/src/gs-category-page.c
+++ b/src/gs-category-page.c
@@ -28,6 +28,7 @@ struct _GsCategoryPage
        GCancellable    *cancellable;
        GsCategory      *category;
        GsCategory      *subcategory;
+       gboolean         valid;
 
        GtkWidget       *top_carousel;
        GtkWidget       *category_detail_box;
@@ -371,6 +372,8 @@ load_category_finish (LoadCategoryData *data)
        gtk_widget_set_visible (self->web_apps_flow_box, gtk_flow_box_get_child_at_index (GTK_FLOW_BOX 
(self->web_apps_flow_box), 0) != NULL);
        gtk_widget_set_visible (self->category_detail_box, gtk_flow_box_get_child_at_index (GTK_FLOW_BOX 
(self->category_detail_box), 0) != NULL);
 
+       self->valid = data->apps != NULL;
+
        load_category_data_free (data);
 }
 
@@ -378,7 +381,6 @@ static void
 gs_category_page_load_category (GsCategoryPage *self)
 {
        GsCategory *featured_subcat = NULL;
-       GtkAdjustment *adj = NULL;
        g_autoptr(GsPluginJob) featured_plugin_job = NULL;
        g_autoptr(GsAppQuery) main_query = NULL;
        g_autoptr(GsPluginJob) main_plugin_job = NULL;
@@ -399,24 +401,29 @@ gs_category_page_load_category (GsCategoryPage *self)
                 gs_category_get_id (self->category),
                 gs_category_get_id (self->subcategory));
 
-       gs_featured_carousel_set_apps (GS_FEATURED_CAROUSEL (self->top_carousel), NULL);
-       gtk_widget_show (self->top_carousel);
-       gs_category_page_add_placeholders (self, GTK_FLOW_BOX (self->category_detail_box),
-                                          MIN (30, gs_category_get_size (self->subcategory)));
-       gs_category_page_add_placeholders (self, GTK_FLOW_BOX (self->recently_updated_flow_box), 
MAX_RECENTLY_UPDATED_APPS);
-
-       if (gs_plugin_loader_get_enabled (self->plugin_loader, "epiphany"))
-               gs_category_page_add_placeholders (self, GTK_FLOW_BOX (self->web_apps_flow_box), 12);
-
-       if (featured_subcat != NULL) {
-               /* set up the placeholders as having the featured category is a good
-                * indicator that there will be featured apps */
-               gs_category_page_add_placeholders (self, GTK_FLOW_BOX (self->featured_flow_box), 6);
+       /* Add placeholders only when the content is not valid */
+       if (!self->valid) {
+               gs_featured_carousel_set_apps (GS_FEATURED_CAROUSEL (self->top_carousel), NULL);
+               gs_category_page_add_placeholders (self, GTK_FLOW_BOX (self->category_detail_box),
+                                                  MIN (30, gs_category_get_size (self->subcategory)));
+               gs_category_page_add_placeholders (self, GTK_FLOW_BOX (self->recently_updated_flow_box), 
MAX_RECENTLY_UPDATED_APPS);
                gtk_widget_show (self->top_carousel);
-       } else {
-               gs_widget_remove_all (self->featured_flow_box, (GsRemoveFunc) gtk_flow_box_remove);
-               gtk_widget_hide (self->featured_flow_box);
-               gtk_widget_hide (self->top_carousel);
+               gtk_widget_show (self->category_detail_box);
+               gtk_widget_show (self->recently_updated_flow_box);
+
+               if (gs_plugin_loader_get_enabled (self->plugin_loader, "epiphany"))
+                       gs_category_page_add_placeholders (self, GTK_FLOW_BOX (self->web_apps_flow_box), 12);
+
+               if (featured_subcat != NULL) {
+                       /* set up the placeholders as having the featured category is a good
+                        * indicator that there will be featured apps */
+                       gs_category_page_add_placeholders (self, GTK_FLOW_BOX (self->featured_flow_box), 6);
+                       gtk_widget_show (self->featured_flow_box);
+               } else {
+                       gs_widget_remove_all (self->featured_flow_box, (GsRemoveFunc) gtk_flow_box_remove);
+                       gtk_widget_hide (self->featured_flow_box);
+                       gtk_widget_hide (self->top_carousel);
+               }
        }
 
        /* Load the list of apps in the category, and also the list of all
@@ -475,11 +482,6 @@ gs_category_page_load_category (GsCategoryPage *self)
                                            self->cancellable,
                                            gs_category_page_get_apps_cb,
                                            load_data);
-
-       /* scroll the list of apps to the beginning, otherwise it will show
-        * with the previous scroll value */
-       adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (self->scrolledwindow_category));
-       gtk_adjustment_set_value (adj, gtk_adjustment_get_lower (adj));
 }
 
 static void
@@ -509,8 +511,18 @@ gs_category_page_set_category (GsCategoryPage *self, GsCategory *category)
        g_set_object (&self->subcategory, all_subcat);
 
        /* load the apps from it */
-       if (all_subcat != NULL)
+       if (all_subcat != NULL) {
+               GtkAdjustment *adj = NULL;
+
+               /* scroll the list of apps to the beginning, otherwise it will show
+                * with the previous scroll value, for the previous category */
+               adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW 
(self->scrolledwindow_category));
+               gtk_adjustment_set_value (adj, gtk_adjustment_get_lower (adj));
+
+               self->valid = FALSE;
+
                gs_category_page_load_category (self);
+       }
 
        /* notify of the updates — the category’s title will have changed too */
        g_object_notify (G_OBJECT (self), "category");


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