[gnome-software/1486-gs-repos-dialog-call-refresh-on-repository-setup-change: 182/184] gs-application: Introduce gs_application_refresh()




commit 01fa46e7cb699e09c564cfd6c7633c0524c8b193
Author: Milan Crha <mcrha redhat com>
Date:   Tue Oct 5 19:45:10 2021 +0200

    gs-application: Introduce gs_application_refresh()
    
    It can be used to call a non-interactive refresh call for the plugins.
    
    The refresh can cause new applications or alternative sources being
    found in the newly enabled repositories, thus also reload the pages,
    to reflect the current state (like in the search page).

 src/gs-application.c | 31 +++++++++++++++++++++++++++++++
 src/gs-application.h |  3 ++-
 2 files changed, 33 insertions(+), 1 deletion(-)
---
diff --git a/src/gs-application.c b/src/gs-application.c
index b62931bc1..7e8fa076e 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -1343,3 +1343,34 @@ gs_application_emit_install_resources_done (GsApplication *application,
 {
        g_signal_emit (application, signals[INSTALL_RESOURCES_DONE], 0, ident, op_error, NULL);
 }
+
+static void
+gs_application_refresh_cb (GsPluginLoader *plugin_loader,
+                          GAsyncResult *result,
+                          GsApplication *self)
+{
+       gboolean success;
+       g_autoptr(GError) error = NULL;
+
+       success = gs_plugin_loader_job_action_finish (plugin_loader, result, &error);
+       if (!success &&
+           !g_error_matches (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_CANCELLED))
+               g_warning ("failed to refresh: %s", error->message);
+
+       if (success)
+               g_signal_emit_by_name (self->plugin_loader, "reload", 0, NULL);
+}
+
+void
+gs_application_refresh (GsApplication *self)
+{
+       g_autoptr(GsPluginJob) plugin_job = NULL;
+       plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REFRESH,
+                                        "interactive", FALSE,
+                                        "age", (guint64) 1,
+                                        NULL);
+       gs_plugin_loader_job_process_async (self->plugin_loader, plugin_job,
+                                           self->cancellable,
+                                           (GAsyncReadyCallback) gs_application_refresh_cb,
+                                           self);
+}
diff --git a/src/gs-application.h b/src/gs-application.h
index 40bad4d4c..92978e1f5 100644
--- a/src/gs-application.h
+++ b/src/gs-application.h
@@ -23,4 +23,5 @@ gboolean       gs_application_has_active_window       (GsApplication *application);
 void            gs_application_emit_install_resources_done
                                                        (GsApplication *application,
                                                         const gchar *ident,
-                                                        const GError *op_error);
\ No newline at end of file
+                                                        const GError *op_error);
+void            gs_application_refresh                 (GsApplication *self);


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