[gnome-software] flatpak: Add support for download scheduling



commit 1a1c152937b160fda870fe7dc1a1f6d4f7c6c024
Author: Philip Withnall <withnall endlessm com>
Date:   Sat Mar 16 17:51:59 2019 +0000

    flatpak: Add support for download scheduling
    
    Signed-off-by: Philip Withnall <withnall endlessm com>

 plugins/flatpak/gs-plugin-flatpak.c | 24 ++++++++++++++++++++++++
 plugins/flatpak/meson.build         | 20 +++++++++++---------
 2 files changed, 35 insertions(+), 9 deletions(-)
---
diff --git a/plugins/flatpak/gs-plugin-flatpak.c b/plugins/flatpak/gs-plugin-flatpak.c
index 62fd4078..fca0d123 100644
--- a/plugins/flatpak/gs-plugin-flatpak.c
+++ b/plugins/flatpak/gs-plugin-flatpak.c
@@ -24,6 +24,7 @@
 #include "gs-flatpak.h"
 #include "gs-flatpak-transaction.h"
 #include "gs-flatpak-utils.h"
+#include "gs-metered.h"
 
 struct GsPluginData {
        GPtrArray               *flatpaks; /* of GsFlatpak */
@@ -448,6 +449,16 @@ gs_plugin_download (GsPlugin *plugin, GsAppList *list,
        if (flatpak == NULL)
                return TRUE;
 
+       if (!gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_INTERACTIVE)) {
+               g_autoptr(GError) error_local = NULL;
+
+               if (!gs_metered_block_app_list_on_download_scheduler (list_tmp, cancellable, &error_local)) {
+                       g_warning ("Failed to block on download scheduler: %s",
+                                  error_local->message);
+                       g_clear_error (&error_local);
+               }
+       }
+
        /* build and run non-deployed transaction */
        transaction = _build_transaction (plugin, flatpak, cancellable, error);
        if (transaction == NULL) {
@@ -576,6 +587,19 @@ gs_plugin_app_install (GsPlugin *plugin,
        if (gs_app_get_kind (app) == AS_APP_KIND_SOURCE)
                return gs_flatpak_app_install_source (flatpak, app, cancellable, error);
 
+       if (!gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_INTERACTIVE)) {
+               g_autoptr(GError) error_local = NULL;
+
+               /* FIXME: Add additional details here, especially the download
+                * size bounds (using `size-minimum` and `size-maximum`, both
+                * type `t`). */
+               if (!gs_metered_block_app_on_download_scheduler (app, cancellable, &error_local)) {
+                       g_warning ("Failed to block on download scheduler: %s",
+                                  error_local->message);
+                       g_clear_error (&error_local);
+               }
+       }
+
        /* build */
        transaction = _build_transaction (plugin, flatpak, cancellable, error);
        if (transaction == NULL) {
diff --git a/plugins/flatpak/meson.build b/plugins/flatpak/meson.build
index 5a93297e..07f82959 100644
--- a/plugins/flatpak/meson.build
+++ b/plugins/flatpak/meson.build
@@ -1,6 +1,15 @@
 subdir('tests')
 
 cargs = ['-DG_LOG_DOMAIN="GsPluginFlatpak"']
+deps = [
+  plugin_libs,
+  flatpak,
+  libxmlb,
+]
+
+if get_option('mogwai')
+  deps += mogwai_schedule_client
+endif
 
 shared_module(
   'gs_plugin_flatpak',
@@ -19,11 +28,7 @@ shared_module(
   install : true,
   install_dir: plugin_dir,
   c_args : cargs,
-  dependencies : [
-    plugin_libs,
-    flatpak,
-    libxmlb,
-  ],
+  dependencies : deps,
   link_with : [
     libgnomesoftware
   ]
@@ -54,10 +59,7 @@ if get_option('tests')
       include_directories('../..'),
       include_directories('../../lib'),
     ],
-    dependencies : [
-      plugin_libs,
-      flatpak,
-    ],
+    dependencies : deps,
     link_with : [
       libgnomesoftware
     ],


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