[gnome-software/wip/kalev/distro-upgrade-fixes: 4/4] Sort distro upgrades in the plugin loader



commit 1d1c9552fa7e95f19a6dc2372aed78fdb1034a74
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 1c325ff2..77ed2547 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -1405,6 +1405,13 @@ gs_plugin_loader_app_sort_prio_cb (GsApp *app1, GsApp *app2, gpointer user_data)
        return gs_app_compare_priority (app1, app2);
 }
 
+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));
+}
+
 /******************************************************************************/
 
 /**
@@ -3577,6 +3584,12 @@ gs_plugin_loader_job_process_async (GsPluginLoader *plugin_loader,
                                                     gs_plugin_loader_app_sort_prio_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 8a128050..5703dd9c 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 33a645ba..7aa06bf8 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]