[gnome-software/1310-updates-page-blanks-while-updating-flatpaks] flatpak: Delay installation changes notification when running update
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/1310-updates-page-blanks-while-updating-flatpaks] flatpak: Delay installation changes notification when running update
- Date: Thu, 15 Jul 2021 11:01:05 +0000 (UTC)
commit 4a2717106ddce5d77a6d8606db42029574a119dc
Author: Milan Crha <mcrha redhat com>
Date: Thu Jul 15 12:58:31 2021 +0200
flatpak: Delay installation changes notification when running update
When running update of several applications, each of them causes a notification
about the Flatpak installation change. No need to reload the GUI for every
single application, better to delay the notification until the update is done.
Closes https://gitlab.gnome.org/GNOME/gnome-software/-/issues/1310
plugins/flatpak/gs-flatpak.c | 52 ++++++++++++++++++++++++++++++++++---
plugins/flatpak/gs-flatpak.h | 3 +++
plugins/flatpak/gs-plugin-flatpak.c | 6 ++++-
3 files changed, 57 insertions(+), 4 deletions(-)
---
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index f1f87f61a..7b0088db3 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -44,6 +44,8 @@ struct _GsFlatpak {
GHashTable *remote_title; /* gchar *remote name ~> gchar *remote title */
GMutex remote_title_mutex;
gboolean requires_full_rescan;
+ gint busy;
+ gboolean changed_while_busy;
};
G_DEFINE_TYPE (GsFlatpak, gs_flatpak, G_TYPE_OBJECT)
@@ -416,10 +418,14 @@ gs_plugin_flatpak_changed_cb (GFileMonitor *monitor,
xb_silo_invalidate (self->silo);
g_clear_pointer (&writer_locker, g_rw_lock_writer_locker_free);
- self->requires_full_rescan = TRUE;
+ if (gs_flatpak_get_busy (self)) {
+ self->changed_while_busy = TRUE;
+ } else {
+ self->requires_full_rescan = TRUE;
- gs_plugin_cache_invalidate (self->plugin);
- gs_plugin_reload (self->plugin);
+ gs_plugin_cache_invalidate (self->plugin);
+ gs_plugin_reload (self->plugin);
+ }
}
static gboolean
@@ -3789,3 +3795,43 @@ gs_flatpak_new (GsPlugin *plugin, FlatpakInstallation *installation, GsFlatpakFl
self->flags = flags;
return GS_FLATPAK (self);
}
+
+static gboolean
+gs_flatpak_claim_changed_idle_cb (gpointer user_data)
+{
+ GsFlatpak *self = user_data;
+
+ self->requires_full_rescan = TRUE;
+
+ gs_plugin_cache_invalidate (self->plugin);
+ gs_plugin_reload (self->plugin);
+
+ return G_SOURCE_REMOVE;
+}
+
+void
+gs_flatpak_set_busy (GsFlatpak *self,
+ gboolean busy)
+{
+ g_return_if_fail (GS_IS_FLATPAK (self));
+
+ if (busy) {
+ g_atomic_int_inc (&self->busy);
+ } else {
+ g_return_if_fail (g_atomic_int_get (&self->busy) > 0);
+ if (g_atomic_int_dec_and_test (&self->busy)) {
+ if (self->changed_while_busy) {
+ self->changed_while_busy = FALSE;
+ g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, gs_flatpak_claim_changed_idle_cb,
+ g_object_ref (self), g_object_unref);
+ }
+ }
+ }
+}
+
+gboolean
+gs_flatpak_get_busy (GsFlatpak *self)
+{
+ g_return_val_if_fail (GS_IS_FLATPAK (self), FALSE);
+ return g_atomic_int_get (&self->busy) > 0;
+}
diff --git a/plugins/flatpak/gs-flatpak.h b/plugins/flatpak/gs-flatpak.h
index 5eb7bb452..26a16e6f2 100644
--- a/plugins/flatpak/gs-flatpak.h
+++ b/plugins/flatpak/gs-flatpak.h
@@ -128,5 +128,8 @@ gboolean gs_flatpak_add_recent (GsFlatpak *self,
guint64 age,
GCancellable *cancellable,
GError **error);
+void gs_flatpak_set_busy (GsFlatpak *self,
+ gboolean busy);
+gboolean gs_flatpak_get_busy (GsFlatpak *self);
G_END_DECLS
diff --git a/plugins/flatpak/gs-plugin-flatpak.c b/plugins/flatpak/gs-plugin-flatpak.c
index 364bc27d1..91162ce78 100644
--- a/plugins/flatpak/gs-plugin-flatpak.c
+++ b/plugins/flatpak/gs-plugin-flatpak.c
@@ -1240,12 +1240,16 @@ gs_plugin_update (GsPlugin *plugin,
while (g_hash_table_iter_next (&iter, &key, &value)) {
GsFlatpak *flatpak = GS_FLATPAK (key);
GsAppList *list_tmp = GS_APP_LIST (value);
+ gboolean success;
g_assert (GS_IS_FLATPAK (flatpak));
g_assert (list_tmp != NULL);
g_assert (gs_app_list_length (list_tmp) > 0);
- if (!gs_plugin_flatpak_update (plugin, flatpak, list_tmp, cancellable, error))
+ gs_flatpak_set_busy (flatpak, TRUE);
+ success = gs_plugin_flatpak_update (plugin, flatpak, list_tmp, cancellable, error);
+ gs_flatpak_set_busy (flatpak, FALSE);
+ if (!success)
return FALSE;
}
return TRUE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]