Skip to content

Commit 0f8d102

Browse files
committed
cog-launcher: fix system dbus appid connection
1 parent bd343d0 commit 0f8d102

File tree

1 file changed

+40
-39
lines changed

1 file changed

+40
-39
lines changed

launcher/cog-launcher.c

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,34 @@ on_web_view_create(WebKitWebView *web_view, WebKitNavigationAction *action)
263263
return NULL;
264264
}
265265

266+
#if COG_DBUS_SYSTEM_BUS
267+
static void
268+
on_system_bus_acquired(GDBusConnection *connection, const char *name, void *userdata)
269+
{
270+
g_autofree char *object_path =
271+
cog_appid_to_dbus_object_path(g_application_get_application_id(G_APPLICATION(userdata)));
272+
g_autoptr(GError) error = NULL;
273+
if (!g_dbus_connection_export_action_group(connection, object_path, G_ACTION_GROUP(userdata), &error))
274+
g_warning("Cannot expose remote control interface to system bus: %s", error->message);
275+
}
276+
277+
static void
278+
on_system_bus_name_acquired(G_GNUC_UNUSED GDBusConnection *connection, const char *name, G_GNUC_UNUSED void *userdata)
279+
{
280+
g_message("Acquired D-Bus well-known name %s", name);
281+
}
282+
283+
static void
284+
on_system_bus_name_lost(GDBusConnection *connection, const char *name, G_GNUC_UNUSED void *userdata)
285+
{
286+
if (connection) {
287+
g_message("Lost D-Bus well-known name %s", name);
288+
} else {
289+
g_message("Lost D-Bus connection to system bus");
290+
}
291+
}
292+
#endif // COG_DBUS_SYSTEM_BUS
293+
266294
static WebKitWebView *
267295
cog_launcher_create_view(CogLauncher *self, CogShell *shell)
268296
{
@@ -434,6 +462,18 @@ cog_launcher_startup(GApplication *application)
434462
s_options.ignore_tls_errors ? WEBKIT_TLS_ERRORS_POLICY_IGNORE
435463
: WEBKIT_TLS_ERRORS_POLICY_FAIL);
436464
#endif
465+
466+
#if COG_DBUS_SYSTEM_BUS
467+
const gchar *appid = g_application_get_application_id(G_APPLICATION(self));
468+
g_bus_own_name(G_BUS_TYPE_SYSTEM,
469+
appid,
470+
G_BUS_NAME_OWNER_FLAGS_NONE,
471+
on_system_bus_acquired,
472+
on_system_bus_name_acquired,
473+
on_system_bus_name_lost,
474+
self,
475+
NULL);
476+
#endif
437477
}
438478

439479
static void
@@ -484,34 +524,6 @@ cog_launcher_dispose(GObject *object)
484524
G_OBJECT_CLASS(cog_launcher_parent_class)->dispose(object);
485525
}
486526

487-
#if COG_DBUS_SYSTEM_BUS
488-
static void
489-
on_system_bus_acquired(GDBusConnection *connection, const char *name, void *userdata)
490-
{
491-
g_autofree char *object_path =
492-
cog_appid_to_dbus_object_path(g_application_get_application_id(G_APPLICATION(userdata)));
493-
g_autoptr(GError) error = NULL;
494-
if (!g_dbus_connection_export_action_group(connection, object_path, G_ACTION_GROUP(userdata), &error))
495-
g_warning("Cannot expose remote control interface to system bus: %s", error->message);
496-
}
497-
498-
static void
499-
on_system_bus_name_acquired(G_GNUC_UNUSED GDBusConnection *connection, const char *name, G_GNUC_UNUSED void *userdata)
500-
{
501-
g_message("Acquired D-Bus well-known name %s", name);
502-
}
503-
504-
static void
505-
on_system_bus_name_lost(GDBusConnection *connection, const char *name, G_GNUC_UNUSED void *userdata)
506-
{
507-
if (connection) {
508-
g_message("Lost D-Bus well-known name %s", name);
509-
} else {
510-
g_message("Lost D-Bus connection to system bus");
511-
}
512-
}
513-
#endif // COG_DBUS_SYSTEM_BUS
514-
515527
#ifndef COG_DEFAULT_APPID
516528
# define COG_DEFAULT_APPID "com.igalia." COG_DEFAULT_APPNAME
517529
#endif /* !COG_DEFAULT_APPID */
@@ -1256,17 +1268,6 @@ cog_launcher_constructed(GObject *object)
12561268

12571269
launcher->sigint_source = g_unix_signal_add(SIGINT, G_SOURCE_FUNC(on_signal_quit), launcher);
12581270
launcher->sigterm_source = g_unix_signal_add(SIGTERM, G_SOURCE_FUNC(on_signal_quit), launcher);
1259-
1260-
#if COG_DBUS_SYSTEM_BUS
1261-
g_bus_own_name(G_BUS_TYPE_SYSTEM,
1262-
COG_DEFAULT_APPID,
1263-
G_BUS_NAME_OWNER_FLAGS_NONE,
1264-
on_system_bus_acquired,
1265-
on_system_bus_name_acquired,
1266-
on_system_bus_name_lost,
1267-
launcher,
1268-
NULL);
1269-
#endif
12701271
}
12711272

12721273
static int

0 commit comments

Comments
 (0)