[gnome-software] flatpak: Use new unknown progress reporting API



commit fb3b8358b1db934735e67a434fe485c7f6af3c18
Author: Philip Withnall <withnall endlessm com>
Date:   Tue Apr 28 18:26:46 2020 +0100

    flatpak: Use new unknown progress reporting API
    
    Port this plugin to use the new unknown progress API; see the previous few
    commits.
    
    Signed-off-by: Philip Withnall <withnall endlessm com>
    Helps: #276

 plugins/flatpak/gs-flatpak-transaction.c | 15 +++++++--------
 plugins/flatpak/gs-flatpak.c             |  5 ++++-
 plugins/flatpak/gs-self-test.c           | 14 +++++++-------
 3 files changed, 18 insertions(+), 16 deletions(-)
---
diff --git a/plugins/flatpak/gs-flatpak-transaction.c b/plugins/flatpak/gs-flatpak-transaction.c
index 336ce92c..16cdc498 100644
--- a/plugins/flatpak/gs-flatpak-transaction.c
+++ b/plugins/flatpak/gs-flatpak-transaction.c
@@ -315,6 +315,7 @@ update_progress_for_op (GsFlatpakTransaction        *self,
                percent = 0;
 
        if (gs_app_get_progress (root_app) == 100 ||
+           gs_app_get_progress (root_app) == GS_APP_PROGRESS_UNKNOWN ||
            gs_app_get_progress (root_app) <= percent) {
                gs_app_set_progress (root_app, percent);
        } else {
@@ -361,14 +362,10 @@ _transaction_progress_changed_cb (FlatpakTransactionProgress *progress,
        if (flatpak_transaction_progress_get_is_estimating (progress)) {
                /* "Estimating" happens while fetching the metadata, which
                 * flatpak arbitrarily decides happens during the first 5% of
-                * each operation. Often there are two install operations,
-                * for the flatpak and its locale data.
-                * However, "estimating" may also mean bogus values. We have to
-                * arbitrarily decide whether to show this value to the user. */
-               if (percent > 10) {
-                       g_debug ("Ignoring estimated progress of %u%%", percent);
-                       return;
-               }
+                * each operation. At this point, no more detailed progress
+                * information is available. */
+               gs_app_set_progress (app, GS_APP_PROGRESS_UNKNOWN);
+               return;
        }
 
 #if FLATPAK_CHECK_VERSION(1, 7, 3)
@@ -401,11 +398,13 @@ _transaction_progress_changed_cb (FlatpakTransactionProgress *progress,
        percent = flatpak_transaction_progress_get_progress (progress);
 
        if (gs_app_get_progress (app) != 100 &&
+           gs_app_get_progress (app) != GS_APP_PROGRESS_UNKNOWN &&
            gs_app_get_progress (app) > percent) {
                g_warning ("ignoring percentage %u%% -> %u%% as going down...",
                           gs_app_get_progress (app), percent);
                return;
        }
+
        gs_app_set_progress (app, percent);
 #endif  /* !flatpak 1.7.3 */
 }
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index a98ca934..394ae72f 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -822,7 +822,10 @@ gs_flatpak_progress_cb (const gchar *status,
        GsPluginStatus plugin_status = GS_PLUGIN_STATUS_DOWNLOADING;
 
        if (phelper->app != NULL) {
-               gs_app_set_progress (phelper->app, progress);
+               if (estimating)
+                       gs_app_set_progress (phelper->app, GS_APP_PROGRESS_UNKNOWN);
+               else
+                       gs_app_set_progress (phelper->app, progress);
 
                switch (gs_app_get_state (phelper->app)) {
                case AS_APP_STATE_INSTALLING:
diff --git a/plugins/flatpak/gs-self-test.c b/plugins/flatpak/gs-self-test.c
index 6a1aa74f..e4c1b18b 100644
--- a/plugins/flatpak/gs-self-test.c
+++ b/plugins/flatpak/gs-self-test.c
@@ -188,7 +188,7 @@ gs_plugins_flatpak_repo_func (GsPluginLoader *plugin_loader)
        g_assert_no_error (error);
        g_assert (ret);
        g_assert_cmpint (gs_app_get_state (app), ==, AS_APP_STATE_AVAILABLE);
-       g_assert_cmpint (gs_app_get_progress (app), ==, 0);
+       g_assert_cmpint (gs_app_get_progress (app), ==, GS_APP_PROGRESS_UNKNOWN);
 }
 
 static void
@@ -356,7 +356,7 @@ gs_plugins_flatpak_app_with_runtime_func (GsPluginLoader *plugin_loader)
        g_assert (ret);
        g_assert_cmpint (gs_app_get_state (app), ==, AS_APP_STATE_INSTALLED);
        g_assert_cmpstr (gs_app_get_version (app), ==, "1.2.3");
-       g_assert_cmpint (gs_app_get_progress (app), ==, 0);
+       g_assert_cmpint (gs_app_get_progress (app), ==, GS_APP_PROGRESS_UNKNOWN);
        g_assert_cmpint (gs_app_get_state (runtime), ==, AS_APP_STATE_INSTALLED);
 
        /* check the application exists in the right places */
@@ -417,14 +417,14 @@ gs_plugins_flatpak_app_with_runtime_func (GsPluginLoader *plugin_loader)
                                         NULL);
        ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
 
-       /* progress should be set to zero right before installing */
+       /* progress should be set to unknown right before installing */
        gs_test_flush_main_context ();
-       g_assert_cmpint (gs_app_get_progress (app), ==, 0);
+       g_assert_cmpint (gs_app_get_progress (app), ==, GS_APP_PROGRESS_UNKNOWN);
        g_assert_no_error (error);
        g_assert (ret);
        g_assert_cmpint (gs_app_get_state (app), ==, AS_APP_STATE_INSTALLED);
        g_assert_cmpstr (gs_app_get_version (app), ==, "1.2.3");
-       g_assert_cmpint (gs_app_get_progress (app), ==, 0);
+       g_assert_cmpint (gs_app_get_progress (app), ==, GS_APP_PROGRESS_UNKNOWN);
 
        /* remove the application */
        g_object_unref (plugin_job);
@@ -558,7 +558,7 @@ gs_plugins_flatpak_app_missing_runtime_func (GsPluginLoader *plugin_loader)
        g_assert (!ret);
        g_clear_error (&error);
        g_assert_cmpint (gs_app_get_state (app), ==, AS_APP_STATE_AVAILABLE);
-       g_assert_cmpint (gs_app_get_progress (app), ==, 0);
+       g_assert_cmpint (gs_app_get_progress (app), ==, GS_APP_PROGRESS_UNKNOWN);
 
        /* remove the remote */
        g_object_unref (plugin_job);
@@ -1413,7 +1413,7 @@ gs_plugins_flatpak_app_update_func (GsPluginLoader *plugin_loader)
        g_assert_cmpstr (gs_app_get_version (app), ==, "1.2.4");
        g_assert_cmpstr (gs_app_get_update_version (app), ==, NULL);
        g_assert_cmpstr (gs_app_get_update_details (app), ==, NULL);
-       g_assert_cmpint (gs_app_get_progress (app), ==, 0);
+       g_assert_cmpint (gs_app_get_progress (app), ==, GS_APP_PROGRESS_UNKNOWN);
        g_assert (got_progress_installing);
        //g_assert_cmpint (progress_cnt, >, 20); //FIXME: bug in OSTree
        g_assert_cmpint (pending_app_changed_cnt, ==, 0);


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