repo-pull: add option to set the async update frequency

When using Flatpak with GNOME Software, it is important to
show the progress of the download and install as close as
possible to the real progress.

However, OSTree forces the frequency to call the async
progress callback to 1 second, which causes an unpleasant
effect on the UI, specially when the download size is so
small that everything happens in less than 1 second.

Fix that by adding making OSTree read a custom 'update-frequency'
option and set the timeout source timeout to that. If
no custom frequency is passed, we assume the default 1
second timeout, maintaining the current behavior.

Closes: #725
Approved by: jlebon
This commit is contained in:
Georges Basile Stavracas Neto 2017-03-08 14:14:15 -03:00 committed by Atomic Bot
parent 031d7898cc
commit d8ac9f75cd
1 changed files with 9 additions and 1 deletions

View File

@ -2589,6 +2589,7 @@ reinitialize_fetcher (OtPullData *pull_data, const char *remote_name, GError **e
* * override-url (s): Fetch objects from this URL if remote specifies no metalink in options * * override-url (s): Fetch objects from this URL if remote specifies no metalink in options
* * inherit-transaction (b): Don't initiate, finish or abort a transaction, usefult to do mutliple pulls in one transaction. * * inherit-transaction (b): Don't initiate, finish or abort a transaction, usefult to do mutliple pulls in one transaction.
* * http-headers (a(ss)): Additional headers to add to all HTTP requests * * http-headers (a(ss)): Additional headers to add to all HTTP requests
* * update-frequency (u): Frequency to call the async progress callback in milliseconds, if any; only values higher than 0 are valid
*/ */
gboolean gboolean
ostree_repo_pull_with_options (OstreeRepo *self, ostree_repo_pull_with_options (OstreeRepo *self,
@ -2613,6 +2614,7 @@ ostree_repo_pull_with_options (OstreeRepo *self,
char **configured_branches = NULL; char **configured_branches = NULL;
guint64 bytes_transferred; guint64 bytes_transferred;
guint64 end_time; guint64 end_time;
guint update_frequency = 0;
OstreeRepoPullFlags flags = 0; OstreeRepoPullFlags flags = 0;
const char *dir_to_pull = NULL; const char *dir_to_pull = NULL;
g_autofree char **dirs_to_pull = NULL; g_autofree char **dirs_to_pull = NULL;
@ -2648,6 +2650,7 @@ ostree_repo_pull_with_options (OstreeRepo *self,
(void) g_variant_lookup (options, "override-url", "&s", &url_override); (void) g_variant_lookup (options, "override-url", "&s", &url_override);
(void) g_variant_lookup (options, "inherit-transaction", "b", &inherit_transaction); (void) g_variant_lookup (options, "inherit-transaction", "b", &inherit_transaction);
(void) g_variant_lookup (options, "http-headers", "@a(ss)", &pull_data->extra_headers); (void) g_variant_lookup (options, "http-headers", "@a(ss)", &pull_data->extra_headers);
(void) g_variant_lookup (options, "update-frequency", "u", &update_frequency);
} }
g_return_val_if_fail (pull_data->maxdepth >= -1, FALSE); g_return_val_if_fail (pull_data->maxdepth >= -1, FALSE);
@ -3283,7 +3286,12 @@ ostree_repo_pull_with_options (OstreeRepo *self,
if (pull_data->progress) if (pull_data->progress)
{ {
update_timeout = g_timeout_source_new_seconds (pull_data->dry_run ? 0 : 1); /* Setup a custom frequency if set */
if (update_frequency > 0)
update_timeout = g_timeout_source_new (pull_data->dry_run ? 0 : update_frequency);
else
update_timeout = g_timeout_source_new_seconds (pull_data->dry_run ? 0 : 1);
g_source_set_priority (update_timeout, G_PRIORITY_HIGH); g_source_set_priority (update_timeout, G_PRIORITY_HIGH);
g_source_set_callback (update_timeout, update_progress, pull_data, NULL); g_source_set_callback (update_timeout, update_progress, pull_data, NULL);
g_source_attach (update_timeout, pull_data->main_context); g_source_attach (update_timeout, pull_data->main_context);