mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 03:16:17 +01:00
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
This commit is contained in:
parent
1f02ef3205
commit
345688c9e9
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user