[gnome-builder] app: add workaround network availability
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] app: add workaround network availability
- Date: Thu, 9 Aug 2018 01:14:14 +0000 (UTC)
commit db681e7a1cfefc6acf216d71c37f4dace455afbb
Author: Christian Hergert <chergert redhat com>
Date: Wed Aug 8 18:07:57 2018 -0700
app: add workaround network availability
This allows us to work around the portal issue for now until upstream glib
gets a bug fix that we want.
src/libide/application/ide-application-private.h | 4 ++
src/libide/application/ide-application.c | 57 ++++++++++++++++++++++++
src/libide/application/ide-application.h | 2 +
3 files changed, 63 insertions(+)
---
diff --git a/src/libide/application/ide-application-private.h
b/src/libide/application/ide-application-private.h
index ff73868c4..95e6b7f9a 100644
--- a/src/libide/application/ide-application-private.h
+++ b/src/libide/application/ide-application-private.h
@@ -68,6 +68,10 @@ struct _IdeApplication
GSettings *settings;
GDBusProxy *color_proxy;
+
+ /* Work around network portal errors */
+ GNetworkMonitor *network_monitor;
+ guint has_network : 1;
} DZL_ALIGNED_END(8);
void ide_application_discover_plugins (IdeApplication *self) G_GNUC_INTERNAL;
diff --git a/src/libide/application/ide-application.c b/src/libide/application/ide-application.c
index e3d309d36..976b9bb99 100644
--- a/src/libide/application/ide-application.c
+++ b/src/libide/application/ide-application.c
@@ -560,6 +560,7 @@ ide_application_finalize (GObject *object)
g_clear_object (&self->settings);
g_clear_object (&self->color_proxy);
g_clear_object (&self->projects_directory);
+ g_clear_object (&self->network_monitor);
G_OBJECT_CLASS (ide_application_parent_class)->finalize (object);
}
@@ -1008,3 +1009,59 @@ ide_application_get_projects_directory (IdeApplication *self)
return g_object_ref (self->projects_directory);
}
+
+static void
+ide_application_network_changed_cb (IdeApplication *self,
+ gboolean available,
+ GNetworkMonitor *monitor)
+{
+ g_assert (IDE_IS_APPLICATION (self));
+ g_assert (G_IS_NETWORK_MONITOR (monitor));
+
+ self->has_network = !!available;
+}
+
+/**
+ * ide_application_has_network:
+ * @self: (nullable): a #IdeApplication
+ *
+ * This is a helper that uses an internal #GNetworkMonitor to track if we
+ * have access to the network. It works around some issues we've seen in
+ * the wild that make determining if we have network access difficult.
+ *
+ * Returns: %TRUE if we think there is network access.
+ *
+ * Since: 3.30
+ */
+gboolean
+ide_application_has_network (IdeApplication *self)
+{
+ g_return_val_if_fail (!self || IDE_IS_APPLICATION (self), FALSE);
+
+ if (self == NULL)
+ self = IDE_APPLICATION_DEFAULT;
+
+ if (self->network_monitor == NULL)
+ {
+ self->network_monitor = g_object_ref (g_network_monitor_get_default ());
+
+ g_signal_connect_object (self->network_monitor,
+ "network-changed",
+ G_CALLBACK (ide_application_network_changed_cb),
+ self,
+ G_CONNECT_SWAPPED);
+
+ self->has_network = g_network_monitor_get_network_available (self->network_monitor);
+
+ /*
+ * FIXME: Ignore the network portal initially for now.
+ *
+ * See https://gitlab.gnome.org/GNOME/glib/merge_requests/227 for more
+ * information about when this is fixed.
+ */
+ if (!self->has_network && ide_is_flatpak ())
+ self->has_network = TRUE;
+ }
+
+ return self->has_network;
+}
diff --git a/src/libide/application/ide-application.h b/src/libide/application/ide-application.h
index 09bf84567..61aaed2b0 100644
--- a/src/libide/application/ide-application.h
+++ b/src/libide/application/ide-application.h
@@ -77,5 +77,7 @@ void ide_application_add_reaper (IdeApplication
DzlDirectoryReaper *reaper);
IDE_AVAILABLE_IN_3_28
GFile *ide_application_get_projects_directory (IdeApplication *self);
+IDE_AVAILABLE_IN_3_30
+gboolean ide_application_has_network (IdeApplication *self);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]