[glib] GApplication: add --gapplication-service switch
- From: Ryan Lortie <desrt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] GApplication: add --gapplication-service switch
- Date: Fri, 10 Jan 2014 14:29:44 +0000 (UTC)
commit e8b7dd32fcfb4be82d3d78561fc36fbc560f3394
Author: Ryan Lortie <desrt desrt ca>
Date: Sat Oct 26 12:27:20 2013 -0400
GApplication: add --gapplication-service switch
Add a --gapplication-service switch to the default implementation of
local_command_line. This name is unlikely to clash with any option used
by an existing application.
When a normal application (neither service nor launcher) is launched with
exactly this one argument, G_APPLICATION_IS_SERVICE will be set.
The idea is that people will write their D-Bus service file with
--gapplication-service on the Exec line. This provides a nice
compromise for people who want the benefits of DBusActivatable
applications but without losing the ability to easily run them directly
(under the debugger or inside jhbuild, etc.)
https://bugzilla.gnome.org/show_bug.cgi?id=710965
gio/gapplication.c | 40 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 40 insertions(+), 0 deletions(-)
---
diff --git a/gio/gapplication.c b/gio/gapplication.c
index 1ffefe8..722e1ab 100644
--- a/gio/gapplication.c
+++ b/gio/gapplication.c
@@ -471,6 +471,29 @@ g_application_real_local_command_line (GApplication *application,
gchar ***arguments,
int *exit_status)
{
+ if ((application->priv->flags & (G_APPLICATION_IS_SERVICE | G_APPLICATION_IS_LAUNCHER)) == 0)
+ {
+ if ((*arguments)[0] && (*arguments)[1] && g_str_equal ((*arguments)[1], "--gapplication-service"))
+ {
+ GError *error = NULL;
+
+ if ((*arguments)[2])
+ g_warning ("Additional arguments following --gapplication-service are ignored");
+
+ application->priv->flags |= G_APPLICATION_IS_SERVICE;
+ if (!g_application_register (application, NULL, &error))
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ *exit_status = 1;
+ }
+ else
+ *exit_status = 0;
+
+ return TRUE;
+ }
+ }
+
if (application->priv->flags & G_APPLICATION_HANDLES_COMMAND_LINE)
return FALSE;
@@ -1552,6 +1575,23 @@ g_application_open (GApplication *application,
* be set accordingly, which helps the window manager determine which
* application is showing the window.
*
+ * Since 2.40, applications that are not explicitly flagged as services
+ * or launchers (ie: neither %G_APPLICATION_IS_SERVICE or
+ * %G_APPLICATION_IS_LAUNCHER are given as flags) will check (from the
+ * default handler for local_command_line) if "--gapplication-service"
+ * was given in the command line. If this flag is present then normal
+ * commandline processing is interrupted and the
+ * %G_APPLICATION_IS_SERVICE flag is set. This provides a "compromise"
+ * solution whereby running an application directly from the commandline
+ * will invoke it in the normal way (which can be useful for debugging)
+ * while still allowing applications to be D-Bus activated in service
+ * mode. The D-Bus service file should invoke the executable with
+ * "--gapplication-service" as the sole commandline argument. This
+ * approach is suitable for use by most graphical applications but
+ * should not be used from applications like editors that need precise
+ * control over when processes invoked via the commandline will exit and
+ * what their exit status will be.
+ *
* Returns: the exit status
*
* Since: 2.28
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]