Commit e246d545 authored by Christian Hergert's avatar Christian Hergert

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
parent 59531e2b
......@@ -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;
......
......@@ -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;
}
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment