[glib] GApplication: don't fail if can't get session bus
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] GApplication: don't fail if can't get session bus
- Date: Tue, 22 Nov 2011 22:36:40 +0000 (UTC)
commit 345688c9e9d811b2844ea573c82be63cb02996ce
Author: Ryan Lortie <desrt desrt ca>
Date: Tue Nov 22 17:32:04 2011 -0500
GApplication: don't fail if can't get session bus
If we can't get on the session bus, just behave like a normal non-unique
application.
This turns out to be remarkably easy to implement and lets us avoid
adding a 'dummy' backend.
Add a test for this case as well.
Idea from Zachary Dovel.
https://bugzilla.gnome.org/show_bug.cgi?id=651997
gio/gapplicationimpl-dbus.c | 15 +++++++++------
gio/tests/gapplication.c | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+), 6 deletions(-)
---
diff --git a/gio/gapplicationimpl-dbus.c b/gio/gapplicationimpl-dbus.c
index 3fae844..8a19b0d 100644
--- a/gio/gapplicationimpl-dbus.c
+++ b/gio/gapplicationimpl-dbus.c
@@ -584,18 +584,20 @@ g_application_impl_register (GApplication *application,
GVariant *reply;
guint32 rval;
- impl = g_slice_new (GApplicationImpl);
+ impl = g_slice_new0 (GApplicationImpl);
impl->app = application;
impl->bus_name = appid;
- impl->session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION,
- cancellable, error);
+ impl->session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, cancellable, NULL);
if (impl->session_bus == NULL)
{
- g_slice_free (GApplicationImpl, impl);
- return NULL;
+ /* If we can't connect to the session bus, proceed as a normal
+ * non-unique application.
+ */
+ *remote_actions = NULL;
+ return impl;
}
impl->object_path = application_path_from_appid (appid);
@@ -952,7 +954,8 @@ g_application_impl_activate_action (GApplicationImpl *impl,
void
g_application_impl_flush (GApplicationImpl *impl)
{
- g_dbus_connection_flush_sync (impl->session_bus, NULL, NULL);
+ if (impl->session_bus)
+ g_dbus_connection_flush_sync (impl->session_bus, NULL, NULL);
}
diff --git a/gio/tests/gapplication.c b/gio/tests/gapplication.c
index 20a511c..715e5f5 100644
--- a/gio/tests/gapplication.c
+++ b/gio/tests/gapplication.c
@@ -247,6 +247,42 @@ appid (void)
g_assert (g_application_id_is_valid ("org.gnome.SessionManager"));
}
+static gboolean nodbus_activated;
+
+static gboolean
+release_app (gpointer user_data)
+{
+ g_application_release (user_data);
+ return FALSE;
+}
+
+static void
+nodbus_activate (GApplication *app)
+{
+ nodbus_activated = TRUE;
+ g_application_hold (app);
+ g_idle_add (release_app, app);
+}
+
+static void
+test_nodbus (void)
+{
+ gchar *argv[] = { "./unimportant", NULL };
+ GDBusConnection *session;
+ GApplication *app;
+
+ session = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
+ g_assert (session == NULL);
+
+ app = g_application_new ("org.gtk.Unimportant",
+ G_APPLICATION_FLAGS_NONE);
+ g_signal_connect (app, "activate", G_CALLBACK (nodbus_activate), NULL);
+ g_application_run (app, 1, argv);
+ g_object_unref (app);
+
+ g_assert (nodbus_activated);
+}
+
int
main (int argc, char **argv)
{
@@ -261,6 +297,7 @@ main (int argc, char **argv)
g_unsetenv ("DISPLAY");
g_setenv ("DBUS_SESSION_BUS_ADDRESS", session_bus_get_temporary_address (), TRUE);
+ g_test_add_func ("/gapplication/no-dbus", test_nodbus);
g_test_add_func ("/gapplication/basic", basic);
g_test_add_func ("/gapplication/non-unique", test_nonunique);
g_test_add_func ("/gapplication/properties", properties);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]