10 static gboolean action3_added = FALSE;
13 on_app_action (GApplication *application,
14 const gchar *action_name,
15 GVariant *platform_data)
17 if (strcmp (action_name, "action1") == 0)
19 else if (strcmp (action_name, "action2") == 0)
22 g_application_remove_action (application, "action3");
24 g_application_add_action (application, "action3", "An extra action");
25 action3_added = !action3_added;
30 on_app_activated (GApplication *application,
32 GVariant *platform_data)
39 cwd = g_get_current_dir ();
40 g_variant_iter_init (&iter, platform_data);
41 while (g_variant_iter_next (&iter, "{&sv}", &key, &value))
43 const char *activate_cwd;
45 if (strcmp (key, "cwd") != 0)
48 activate_cwd = g_variant_get_bytestring (value);
49 g_assert_cmpstr (cwd, ==, activate_cwd);
50 g_variant_unref (value);
57 on_monitor_fd_io (GIOChannel *source,
58 GIOCondition condition,
66 main (int argc, char *argv[])
72 const char *slave_fd_env = g_getenv ("_G_TEST_SLAVE_FD");
75 int slave_fd = atoi (slave_fd_env);
76 fcntl (slave_fd, F_SETFD, FD_CLOEXEC);
77 g_io_add_watch (g_io_channel_unix_new (slave_fd), G_IO_HUP | G_IO_ERR,
78 on_monitor_fd_io, NULL);
83 app = g_application_unregistered_try_new ("org.gtk.test.app",
85 if (!(argc > 1 && strcmp (argv[1], "--non-unique") == 0))
87 if (!g_application_register (app))
91 if (g_application_is_remote (app))
93 g_application_invoke_action (app, "action1", 0);
97 g_application_add_action (app, "action1", "Action1");
98 g_application_add_action (app, "action2", "Action2");
99 g_signal_connect (app, "action-with-data",
100 G_CALLBACK (on_app_action), NULL);
101 g_signal_connect (app, "prepare-activation",
102 G_CALLBACK (on_app_activated), NULL);
103 g_application_run (app);