[gnome-builder/gnome-builder-3-28] app: add workaround network availability
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/gnome-builder-3-28] app: add workaround network availability
- Date: Thu, 9 Aug 2018 02:19:27 +0000 (UTC)
commit e246d5458043d24fe3c298765c2243c94898c655
Author: Christian Hergert <chergert redhat com>
Date: Wed Aug 8 19:15:23 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.
# Conflicts:
# src/libide/application/ide-application.c
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 096e645ee..23e61c765 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 94134b09a..c7fee5c32 100644
--- a/src/libide/application/ide-application.c
+++ b/src/libide/application/ide-application.c
@@ -645,6 +645,7 @@ ide_application_finalize (GObject *object)
g_clear_object (&self->recent_projects);
g_clear_object (&self->settings);
g_clear_object (&self->color_proxy);
+ g_clear_object (&self->network_monitor);
G_OBJECT_CLASS (ide_application_parent_class)->finalize (object);
}
@@ -1088,3 +1089,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 0a38b9962..216578a41 100644
--- a/src/libide/application/ide-application.h
+++ b/src/libide/application/ide-application.h
@@ -76,5 +76,7 @@ IDE_AVAILABLE_IN_ALL
DzlDirectoryReaper *reaper);
IDE_AVAILABLE_IN_3_28
GFile *ide_application_get_projects_directory (IdeApplication *self);
+IDE_AVAILABLE_IN_3_28
+gboolean ide_application_has_network (IdeApplication *self);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]