After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 699259 - add org.freedesktop.Application support to GIO
add org.freedesktop.Application support to GIO
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gapplication
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on: 697994
Blocks:
 
 
Reported: 2013-04-29 20:42 UTC by Allison Karlitskaya (desrt)
Modified: 2013-07-11 19:49 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
GApplication: implement fd.o application spec (6.11 KB, patch)
2013-04-29 20:42 UTC, Allison Karlitskaya (desrt)
committed Details | Review
GDesktopAppInfo: support DBusActivatable (12.56 KB, patch)
2013-04-29 20:42 UTC, Allison Karlitskaya (desrt)
needs-work Details | Review
GApplication: set prgname to appid for services (1.88 KB, patch)
2013-05-09 13:43 UTC, Allison Karlitskaya (desrt)
committed Details | Review
GDesktopAppInfo: support DBusActivatable (13.94 KB, patch)
2013-06-05 17:16 UTC, Allison Karlitskaya (desrt)
reviewed Details | Review
GDesktopAppInfo: support DBusActivatable (14.06 KB, patch)
2013-06-07 19:55 UTC, Allison Karlitskaya (desrt)
committed Details | Review
Add a testcase for DBusActivatable=true (9.64 KB, patch)
2013-06-08 22:15 UTC, Allison Karlitskaya (desrt)
committed Details | Review

Description Allison Karlitskaya (desrt) 2013-04-29 20:42:16 UTC
See patches.
Comment 1 Allison Karlitskaya (desrt) 2013-04-29 20:42:17 UTC
Created attachment 242843 [details] [review]
GApplication: implement fd.o application spec

The freedesktop application specification is largely overlapping the
GLib application D-Bus interface but implementing it will allow for
applications to be launched directly from desktop files, which we want.

We keep the old Gtk interface for compatibility reasons and because it
has some functionality not in the freedesktop spec (Busy state,
CommandLine, etc.).
Comment 2 Allison Karlitskaya (desrt) 2013-04-29 20:42:20 UTC
Created attachment 242844 [details] [review]
GDesktopAppInfo: support DBusActivatable

Support the sender-side of the freedesktop application specification for
cases that we find 'DBusActivatable=true' in the desktop file.
Comment 3 Colin Walters 2013-04-29 20:45:01 UTC
Link to spec?  I don't see any discussion of it in xdg-list.
Comment 4 Allison Karlitskaya (desrt) 2013-04-29 21:08:42 UTC
(In reply to comment #3)
> Link to spec?  I don't see any discussion of it in xdg-list.

pending me getting commit access :)
Comment 5 Cosimo Cecchi 2013-04-29 23:22:28 UTC
Review of attachment 242844 [details] [review]:

::: gio/gdesktopappinfo.c
@@ +433,3 @@
+          else
+            g_free (basename);
+

You leak basename in case the if is not entered...I would just strdup it in the g_dbus_is_interface_name() condition and always free it after the if block.

@@ +1523,3 @@
+  g_dbus_connection_call (session_bus, info->app_id, object_path, "org.freedesktop.Application",
+                          uris ? "Open" : "Activate", g_variant_builder_end (&builder),
+  GVariantBuilder builder;

Shouldn't you check for errors and return an appropriate value accordingly here?

On the other hand that would force you to use g_dbus_connection_call_sync(), but I'm not sure I like silently ignoring errors better.
Comment 6 Allison Karlitskaya (desrt) 2013-04-29 23:25:49 UTC
Calling _sync() is really not acceptable here because this is an application starting up....

It's already documented that there is no real way to know if starting the app failed... Basically, once the child process has forked off, it's gone... even failing to load shared libraries won't be detected.
Comment 7 Allison Karlitskaya (desrt) 2013-04-29 23:31:56 UTC
(In reply to comment #5)
> Review of attachment 242844 [details] [review]:
> You leak basename in case the if is not entered...I would just strdup it in the
> g_dbus_is_interface_name() condition and always free it after the if block.

Ya... I should know better than this.  Fixed.
Comment 8 Allison Karlitskaya (desrt) 2013-04-30 00:54:30 UTC
Meanwhile, I put a bug upstream:  https://bugs.freedesktop.org/show_bug.cgi?id=64066
Comment 9 Matthias Clasen 2013-04-30 22:17:29 UTC
> We keep the old Gtk interface for compatibility reasons and because it
> has some functionality not in the freedesktop spec (Busy state,
CommandLine, etc.).

So whats the story going forward, for adding new functionality ? Do we keep the fd.o interface as a minimal shared base and add new functionality to the org.gtk interface ?
Comment 10 Allison Karlitskaya (desrt) 2013-04-30 23:54:06 UTC
it depends on if we believe it is useful to standardise the behaviour and if we are successful in doing so.
Comment 11 Allison Karlitskaya (desrt) 2013-05-09 13:43:12 UTC
Created attachment 243700 [details] [review]
GApplication: set prgname to appid for services

Since services are based on D-Bus activation and desktop files are
supposed to be named like the busname for DBusActivatable applications
and since gnome-shell wants wmclass equal to the desktop file name, we
therefore want wmclass equal to the application ID in this case.

wmclass is determined from the prgname, which is otherwise pretty
pointless to set to some random thing in $(libexec) for a D-Bus service,
so set that to the appid.

This means that for D-Bus services, the following things are now all the
same:

 - application ID
 - prgname
 - wmclass property set on all windows
 - desktop file name
 - well-known bus name

There are not many applications running as D-Bus services at present so
this shouldn't impact anybody except for gnome-clocks (where this change
will be fixing a bug).
Comment 12 Matthias Clasen 2013-06-04 14:03:34 UTC
Review of attachment 242843 [details] [review]:

::: gio/gapplicationimpl-dbus.c
@@ +269,3 @@
+      const gchar *name;
+
+      /* Only on the freedesktop interface */

Is there any reason to not at least make org.gtk.Application a superset of org.freedesktop.Application ?
Comment 13 Allison Karlitskaya (desrt) 2013-06-04 14:08:58 UTC
(In reply to comment #12)
> Is there any reason to not at least make org.gtk.Application a superset of
> org.freedesktop.Application ?

Because we also have an actiongroup interface.  The freedesktop interface has ActivateAction because actiongroups (in their own right) are not available at that level.
Comment 14 Matthias Clasen 2013-06-04 14:14:01 UTC
Review of attachment 242844 [details] [review]:

::: gio/gdesktopappinfo.c
@@ +1673,3 @@
+                                                  user_setup_data,
+                                                  pid_callback,
+                                                  pid_callback_data,

launch_uris_as_manager docs say:

In contrast to g_app_info_launch_uris(), all processes created will
always be run directly as children as if by the UNIX fork()/exec()
calls.

Looks like you break that guarantee here ?
Comment 15 Matthias Clasen 2013-06-04 14:16:44 UTC
Review of attachment 243700 [details] [review]:

Doesn't look like we document the prgname setting aspect of GApplication at all, currently.
It is probably worth mentioning this in the release notes, since we do change observable behaviour here.
Comment 16 Allison Karlitskaya (desrt) 2013-06-04 14:30:26 UTC
(In reply to comment #14)
> Review of attachment 242844 [details] [review]:
> 
> ::: gio/gdesktopappinfo.c
> @@ +1673,3 @@
> +                                                  user_setup_data,
> +                                                  pid_callback,
> +                                                  pid_callback_data,
> 
> launch_uris_as_manager docs say:
> 
> In contrast to g_app_info_launch_uris(), all processes created will
> always be run directly as children as if by the UNIX fork()/exec()
> calls.
> 
> Looks like you break that guarantee here ?

(as per discussion on IRC) I will update the patch so that the docs say "if the process is launched via fork/exec then you will get a pid and user setup callback..."

This API was really meant to get information from processes that the shell could not otherwise track (due to inability to match based on wmclass, startup notification or other mechanisms).  GApplications launched via D-Bus don't suffer from these problems so the pid callback is not needed.  Old programs with these problems will continue to be fork/execed, so the callback will still happen.
Comment 17 Matthias Clasen 2013-06-05 15:10:01 UTC
(In reply to comment #13)
> (In reply to comment #12)
> > Is there any reason to not at least make org.gtk.Application a superset of
> > org.freedesktop.Application ?
> 
> Because we also have an actiongroup interface.  The freedesktop interface has
> ActivateAction because actiongroups (in their own right) are not available at
> that level.

Ah, I missed that. Makes sense then
Comment 18 Allison Karlitskaya (desrt) 2013-06-05 16:51:51 UTC
Comment on attachment 243700 [details] [review]
GApplication: set prgname to appid for services

Attachment 243700 [details] pushed as 7baea0a - GApplication: set prgname to appid for services

Pushed with the suggested documentation changes (and a small logic tweak).
Comment 19 Allison Karlitskaya (desrt) 2013-06-05 17:07:51 UTC
Comment on attachment 242843 [details] [review]
GApplication: implement fd.o application spec

Attachment 242843 [details] pushed as b4df86f - GApplication: implement fd.o application spec
Comment 20 Allison Karlitskaya (desrt) 2013-06-05 17:16:23 UTC
Created attachment 246103 [details] [review]
GDesktopAppInfo: support DBusActivatable

Support the sender-side of the freedesktop application specification for
cases that we find 'DBusActivatable=true' in the desktop file.
Comment 21 Allison Karlitskaya (desrt) 2013-06-05 17:17:36 UTC
The patch has been updated to fix the memory leak issue and the docs for _as_manager() have also been changed.
Comment 22 Colin Walters 2013-06-05 21:40:11 UTC
Review of attachment 246103 [details] [review]:

A few mechanical comments only...the idea seems fine but I haven't looked at the big picture in detail.

::: gio/gdesktopappinfo.c
@@ +294,3 @@
   char *try_exec;
   char *exec;
+  gboolean dbusable;

An odd word; how about bus_activatable?  It's not much more verbose.

@@ +436,3 @@
   info->keyfile = g_key_file_ref (key_file);
 
+  g_free (basename);

How does this compile?  Basename isn't defined in this scope.

@@ +1521,3 @@
+  g_variant_builder_close (&builder);
+
+  /* This is non-nlocking API.  Similar to launching via fork()/exec()

blocking

@@ +1567,3 @@
     }
 
+  return success;

Still needs g_clear_object (&session_bus) in theory; not that this really matters since pretty much no one unrefs it and we end up with a refcount on the bus of over 9000.
Comment 23 Allison Karlitskaya (desrt) 2013-06-07 19:54:23 UTC
(In reply to comment #22)
> @@ +436,3 @@
>    info->keyfile = g_key_file_ref (key_file);
> 
> +  g_free (basename);
> 
> How does this compile?  Basename isn't defined in this scope.

lol.  'basename' is a public function of the C library...  oops =)
Comment 24 Allison Karlitskaya (desrt) 2013-06-07 19:55:03 UTC
Created attachment 246277 [details] [review]
GDesktopAppInfo: support DBusActivatable

Support the sender-side of the freedesktop application specification for
cases that we find 'DBusActivatable=true' in the desktop file.
Comment 25 Colin Walters 2013-06-07 20:28:30 UTC
Review of attachment 246277 [details] [review]:

One super minor thing, feel free to ignore.

::: gio/gdesktopappinfo.c
@@ +425,3 @@
+      last_dot = strrchr (basename, '.');
+
+      if (g_str_equal (last_dot, ".desktop"))

I'd be a bit more comfortable if this was:

if (last_dot != NULL && g_str_equal (last_dot, ".desktop"))

Yeah I don't think we'd ever load a desktop file with no ., but might as well be safe.
Comment 26 Matthias Clasen 2013-06-07 23:12:42 UTC
Before we close out this bug - it would be great to have some tests exercising the org.freedesktop.Application dbus api, in the name of coverage.
Comment 27 Allison Karlitskaya (desrt) 2013-06-08 20:39:15 UTC
Comment on attachment 246277 [details] [review]
GDesktopAppInfo: support DBusActivatable

Attachment 246277 [details] pushed as afc8b10 - GDesktopAppInfo: support DBusActivatable

Tests coming soon...
Comment 28 Allison Karlitskaya (desrt) 2013-06-08 22:15:21 UTC
Created attachment 246338 [details] [review]
Add a testcase for DBusActivatable=true

Add a fairly realistic testcase that ensures that GDesktopAppInfo with
DBusActivatable=true can successfully talk to GApplication for a variety
of purposes.
Comment 29 Allison Karlitskaya (desrt) 2013-06-08 22:15:42 UTC
testcase depends on patch in bug 664444.
Comment 30 Matthias Clasen 2013-06-09 13:14:33 UTC
Review of attachment 246338 [details] [review]:

Looks good, in general. We just need to land the desktop entry spec update soon, so this all becomes 'legal'.

::: gio/tests/org.gtk.test.dbusappinfo.desktop
@@ +5,3 @@
+
+[Desktop Action frob]
+Name=Frobnicate

After looking up if the desktop action thing ever made it into the spec, I find that this desktop file is not valid according to the current spec: the Exec key in the Desktop Action group is required. Does your spec change make that optional ?

Also, you have your simple actions here, but not send-message. I guess there's no plan to update the spec to make it possible to declare such actions ?
Comment 31 Allison Karlitskaya (desrt) 2013-06-09 15:01:37 UTC
(In reply to comment #30)
> ::: gio/tests/org.gtk.test.dbusappinfo.desktop
> @@ +5,3 @@
> +
> +[Desktop Action frob]
> +Name=Frobnicate
> 
> After looking up if the desktop action thing ever made it into the spec, I find
> that this desktop file is not valid according to the current spec: the Exec key
> in the Desktop Action group is required. Does your spec change make that
> optional ?

Correct.

> Also, you have your simple actions here, but not send-message. I guess there's
> no plan to update the spec to make it possible to declare such actions ?

This is what I was talking about when I said (in the docs):

+ * If you know the application corresponding to @info to be a
+ * #GApplication with "DBusActivatable" set to "true" in its desktop
+ * file, then this function can be used to invoke arbitrary actions
+ * (with arbitrary @parameter value) on the application's primary
+ * ("app.") action group, even if they are not listed in the desktop
+ * file.  This may or may not work with non-#GApplications, and will
+ * almost definitely not work at all if "DBusActivatable" is not true.
Comment 32 Allison Karlitskaya (desrt) 2013-06-10 02:43:58 UTC
Bug 697994 is going to affect this a little...

When doing g_app_info_launch() or g_desktop_app_info_activate_action() without a GAppLaunchContext, in the DBusActivatable=true case, we can do better than we did before.  Specifically, once we have the platform_data hooks, we can use this to fill in a reasonable value for the platform_data on the D-Bus calls, even if we are missing the launch context.  This will allow us to at least forward timestamp information...
Comment 33 Matthias Clasen 2013-06-30 03:21:56 UTC
Should we wrap this up ?
Comment 34 Allison Karlitskaya (desrt) 2013-07-11 19:49:41 UTC
Attachment 246338 [details] pushed as 3b1b044 - Add a testcase for DBusActivatable=true