[gnome-software/gnome-3-30] Sort distro upgrades in the plugin loader



commit b4a215656fe1a2028cf8c75ba0f4a3f65856cdb4
Author: Kalev Lember <klember redhat com>
Date:   Mon Oct 8 11:34:15 2018 +0200

    Sort distro upgrades in the plugin loader
    
    ... so that we can rely on the order in UI code.

 lib/gs-plugin-loader.c  | 13 +++++++++++++
 src/gs-update-monitor.c |  5 +++--
 src/gs-updates-page.c   |  3 ++-
 3 files changed, 18 insertions(+), 3 deletions(-)
---
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index ca327cdb..3003ad91 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -1393,6 +1393,13 @@ gs_plugin_loader_app_sort_match_value_cb (GsApp *app1, GsApp *app2, gpointer use
        return 0;
 }
 
+static gint
+gs_plugin_loader_app_sort_version_cb (GsApp *app1, GsApp *app2, gpointer user_data)
+{
+       return as_utils_vercmp (gs_app_get_version (app1),
+                               gs_app_get_version (app2));
+}
+
 /******************************************************************************/
 
 static gboolean
@@ -3609,6 +3616,12 @@ gs_plugin_loader_job_process_async (GsPluginLoader *plugin_loader,
                                                     gs_plugin_loader_app_sort_name_cb);
                }
                break;
+       case GS_PLUGIN_ACTION_GET_DISTRO_UPDATES:
+               if (gs_plugin_job_get_sort_func (plugin_job) == NULL) {
+                       gs_plugin_job_set_sort_func (plugin_job,
+                                                    gs_plugin_loader_app_sort_version_cb);
+               }
+               break;
        default:
                break;
        }
diff --git a/src/gs-update-monitor.c b/src/gs-update-monitor.c
index a6c03502..de6f29dc 100644
--- a/src/gs-update-monitor.c
+++ b/src/gs-update-monitor.c
@@ -534,8 +534,9 @@ get_upgrades_finished_cb (GObject *object,
        g_settings_set (monitor->settings, "upgrade-notification-timestamp", "x",
                        g_date_time_to_unix (now));
 
-       /* just get the first result : FIXME, do we sort these by date? */
-       app = gs_app_list_index (apps, 0);
+       /* rely on the app list already being sorted with the
+        * chronologically newest release last */
+       app = gs_app_list_index (apps, gs_app_list_length (apps) - 1);
 
        /* TRANSLATORS: this is a distro upgrade, the replacement would be the
         * distro name, e.g. 'Fedora' */
diff --git a/src/gs-updates-page.c b/src/gs-updates-page.c
index 7db22f07..e8b44230 100644
--- a/src/gs-updates-page.c
+++ b/src/gs-updates-page.c
@@ -587,7 +587,8 @@ gs_updates_page_get_upgrades_cb (GObject *source_object,
                gs_updates_page_clear_flag (self, GS_UPDATES_PAGE_FLAG_HAS_UPGRADES);
                gtk_widget_set_visible (self->upgrade_banner, FALSE);
        } else {
-               /* rely on the app list already being sorted */
+               /* rely on the app list already being sorted with the
+                * chronologically newest release last */
                GsApp *app = gs_app_list_index (list, gs_app_list_length (list) - 1);
                g_debug ("got upgrade %s", gs_app_get_id (app));
                gs_upgrade_banner_set_app (GS_UPGRADE_BANNER (self->upgrade_banner), app);


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