[gnome-builder] flatpak: Refresh list of runtimes when necessary
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] flatpak: Refresh list of runtimes when necessary
- Date: Tue, 13 Dec 2016 00:48:16 +0000 (UTC)
commit 467ffec495a4024cc5a73c4ef5d38f23ce0ab8fd
Author: Matthew Leeds <mleeds redhat com>
Date: Fri Dec 9 03:22:13 2016 -0600
flatpak: Refresh list of runtimes when necessary
If the user installs or uninstalls a runtime while Builder is running,
we want to detect that and update the list of runtimes in the Build
Preferences view. This commit accomplishes that using a GFileMonitor.
It does have the side effect that the runtimes are reloaded even if an
unrelated change happens to the flatpak installation (such as installing
or updating apps).
https://bugzilla.gnome.org/show_bug.cgi?id=775863
plugins/flatpak/gbp-flatpak-runtime-provider.c | 78 ++++++++++++++++++++++++
1 files changed, 78 insertions(+), 0 deletions(-)
---
diff --git a/plugins/flatpak/gbp-flatpak-runtime-provider.c b/plugins/flatpak/gbp-flatpak-runtime-provider.c
index ddc57c5..ea748f2 100644
--- a/plugins/flatpak/gbp-flatpak-runtime-provider.c
+++ b/plugins/flatpak/gbp-flatpak-runtime-provider.c
@@ -35,6 +35,8 @@ struct _GbpFlatpakRuntimeProvider
FlatpakInstallation *system_installation;
GCancellable *cancellable;
GPtrArray *runtimes;
+ GFileMonitor *system_flatpak_monitor;
+ GFileMonitor *user_flatpak_monitor;
};
typedef struct
@@ -53,6 +55,9 @@ G_DEFINE_TYPE_EXTENDED (GbpFlatpakRuntimeProvider, gbp_flatpak_runtime_provider,
G_IMPLEMENT_INTERFACE (IDE_TYPE_RUNTIME_PROVIDER,
runtime_provider_iface_init))
+static void gbp_flatpak_runtime_provider_load (IdeRuntimeProvider *provider, IdeRuntimeManager *manager);
+static void gbp_flatpak_runtime_provider_unload (IdeRuntimeProvider *provider, IdeRuntimeManager *manager);
+
static inline void
sanitize_name (gchar *name)
{
@@ -437,6 +442,31 @@ gbp_flatpak_runtime_provider_load_manifests (GbpFlatpakRuntimeProvider *self,
}
static void
+on_flatpak_installation_changed (GbpFlatpakRuntimeProvider *self,
+ GFile *file,
+ GFile *other_file,
+ GFileMonitorEvent event_type,
+ GFileMonitor *monitor)
+{
+ IdeRuntimeManager *manager;
+
+ IDE_ENTRY;
+
+ g_assert (GBP_IS_FLATPAK_RUNTIME_PROVIDER (self));
+ g_assert (G_IS_FILE_MONITOR (self));
+ g_assert (!file || G_IS_FILE (file));
+ g_assert (!other_file || G_IS_FILE (other_file));
+
+ /* Save a pointer to manager before unload() wipes it out */
+ manager = self->manager;
+
+ gbp_flatpak_runtime_provider_unload (IDE_RUNTIME_PROVIDER (self), manager);
+ gbp_flatpak_runtime_provider_load (IDE_RUNTIME_PROVIDER (self), manager);
+
+ IDE_EXIT;
+}
+
+static void
gbp_flatpak_runtime_provider_load_worker (GTask *task,
gpointer source_object,
gpointer task_data,
@@ -482,6 +512,43 @@ gbp_flatpak_runtime_provider_load_worker (GTask *task,
g_clear_error (&error);
}
+ /* Set up file monitors so the list of runtimes refreshes when necessary */
+ if (self->system_installation != NULL)
+ {
+ if (NULL == (self->system_flatpak_monitor = flatpak_installation_create_monitor
(self->system_installation,
+ cancellable, &error)))
+ {
+ g_warning ("Failed to create flatpak installation file monitor: %s", error->message);
+ g_clear_error (&error);
+ }
+ else
+ {
+ g_signal_connect_object (self->system_flatpak_monitor,
+ "changed",
+ G_CALLBACK (on_flatpak_installation_changed),
+ self,
+ G_CONNECT_SWAPPED);
+ }
+ }
+
+ if (self->user_installation != NULL)
+ {
+ if (NULL == (self->user_flatpak_monitor = flatpak_installation_create_monitor (self->user_installation,
+ cancellable, &error)))
+ {
+ g_warning ("Failed to create flatpak installation file monitor: %s", error->message);
+ g_clear_error (&error);
+ }
+ else
+ {
+ g_signal_connect_object (self->user_flatpak_monitor,
+ "changed",
+ G_CALLBACK (on_flatpak_installation_changed),
+ self,
+ G_CONNECT_SWAPPED);
+ }
+ }
+
g_task_return_pointer (task, g_steal_pointer (&ret), (GDestroyNotify)g_ptr_array_unref);
IDE_EXIT;
@@ -554,6 +621,17 @@ gbp_flatpak_runtime_provider_unload (IdeRuntimeProvider *provider,
g_assert (GBP_IS_FLATPAK_RUNTIME_PROVIDER (self));
g_assert (IDE_IS_RUNTIME_MANAGER (manager));
+ if (self->system_flatpak_monitor != NULL)
+ {
+ g_file_monitor_cancel (self->system_flatpak_monitor);
+ g_clear_object (&self->system_flatpak_monitor);
+ }
+ if (self->user_flatpak_monitor != NULL)
+ {
+ g_file_monitor_cancel (self->user_flatpak_monitor);
+ g_clear_object (&self->user_flatpak_monitor);
+ }
+
if (self->runtimes != NULL)
{
for (guint i= 0; i < self->runtimes->len; i++)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]