2
* Copyright 2013 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 3, as published
6
* by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License along
14
* with this program. If not, see <http://www.gnu.org/licenses/>.
17
* Ted Gould <ted.gould@canonical.com>
21
#include "libupstart-app-launch/upstart-app-launch.h"
24
const gchar * global_appid;
27
app_started (const gchar * appid, gpointer user_data)
29
if (g_strcmp0(appid, global_appid) != 0)
31
g_debug("Application Started: %s", appid);
32
g_main_loop_quit((GMainLoop *)user_data);
36
app_focus (const gchar * appid, gpointer user_data)
38
if (g_strcmp0(appid, global_appid) != 0)
40
g_debug("Application Focused");
41
g_main_loop_quit((GMainLoop *)user_data);
45
app_failed (const gchar * appid, upstart_app_launch_app_failed_t failure_type, gpointer user_data)
47
if (g_strcmp0(appid, global_appid) != 0)
49
g_warning("Application Startup Failed");
51
g_main_loop_quit((GMainLoop *)user_data);
55
main (int argc, char * argv[])
57
GDBusConnection * con = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
58
g_return_val_if_fail(con != NULL, 1);
60
global_appid = g_getenv("APP_ID");
61
g_return_val_if_fail(global_appid != NULL, 1);
63
const gchar * uris_str = g_getenv("APP_URIS");
65
if (uris_str != NULL) {
66
GError * error = NULL;
68
g_shell_parse_argv(uris_str, &uri_count, &uris, &error);
71
g_warning("Unable to parse uris '%s': %s", uris_str, error->message);
74
g_debug("Got %d URIs", uri_count);
78
GMainLoop * mainloop = g_main_loop_new(NULL, FALSE);
80
upstart_app_launch_observer_add_app_started(app_started, mainloop);
81
upstart_app_launch_observer_add_app_focus(app_focus, mainloop);
82
upstart_app_launch_observer_add_app_failed(app_failed, mainloop);
84
g_debug("Start Application: %s", global_appid);
85
g_return_val_if_fail(upstart_app_launch_start_application(global_appid, (const gchar * const *)uris), -1);
88
g_debug("Wait for results");
89
g_main_loop_run(mainloop);
91
upstart_app_launch_observer_delete_app_started(app_started, mainloop);
92
upstart_app_launch_observer_delete_app_focus(app_focus, mainloop);
93
upstart_app_launch_observer_delete_app_failed(app_failed, mainloop);
95
g_main_loop_unref(mainloop);