summaryrefslogtreecommitdiff
path: root/portal
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2019-12-19 23:13:45 -0500
committerAlexander Larsson <alexander.larsson@gmail.com>2019-12-20 11:32:40 +0100
commit6e45ff6d0ff18a80a184eac2a9d9982b0ae8fbc2 (patch)
treee404cc7ffa16a1a5f196b9aa82883f99c96c8278 /portal
parent6179620de523909cc8ed276b666742b29777af79 (diff)
downloadflatpak-6e45ff6d0ff18a80a184eac2a9d9982b0ae8fbc2.tar.gz
portal: Don't poll for updates on metered networks
Stop polling for updates on metered networks. Allow overriding this with the new --poll-when-metered option. Fixes: https://github.com/flatpak/flatpak/issues/3286
Diffstat (limited to 'portal')
-rw-r--r--portal/flatpak-portal.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/portal/flatpak-portal.c b/portal/flatpak-portal.c
index ddf9606e..5114bfd2 100644
--- a/portal/flatpak-portal.c
+++ b/portal/flatpak-portal.c
@@ -54,12 +54,14 @@
static GHashTable *client_pid_data_hash = NULL;
static GDBusConnection *session_bus = NULL;
+static GNetworkMonitor *network_monitor = NULL;
static gboolean no_idle_exit = FALSE;
static guint name_owner_id = 0;
static GMainLoop *main_loop;
static PortalFlatpak *portal;
static gboolean opt_verbose;
static int opt_poll_timeout;
+static gboolean opt_poll_when_metered;
static FlatpakSpawnSupportFlags supports = 0;
G_LOCK_DEFINE (update_monitors); /* This protects the three variables below */
@@ -1463,6 +1465,14 @@ check_all_for_updates_cb (void *data)
{
g_autoptr(GTask) task = g_task_new (NULL, NULL, NULL, NULL);
+ if (!opt_poll_when_metered &&
+ g_network_monitor_get_network_metered (network_monitor))
+ {
+ g_debug ("Skipping update check on metered network");
+
+ return G_SOURCE_CONTINUE;
+ }
+
g_debug ("Checking all update monitors");
G_LOCK (update_monitors);
@@ -2442,6 +2452,7 @@ main (int argc,
{ "version", 0, 0, G_OPTION_ARG_NONE, &show_version, "Show program version.", NULL},
{ "no-idle-exit", 0, 0, G_OPTION_ARG_NONE, &no_idle_exit, "Don't exit when idle.", NULL },
{ "poll-timeout", 0, 0, G_OPTION_ARG_INT, &opt_poll_timeout, "Delay in seconds between polls for updates.", NULL },
+ { "poll-when-metered", 0, 0, G_OPTION_ARG_NONE, &opt_poll_when_metered, "Whether to check for updates on metered networks", NULL },
{ NULL }
};
@@ -2542,6 +2553,8 @@ main (int argc,
/* Ensure we don't idle exit */
schedule_idle_callback ();
+ network_monitor = g_network_monitor_get_default ();
+
main_loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (main_loop);