Launch gtk application with payload via dbus through `org.freedesktop.Application.Activate`

Hello everyone,

I’m working on launching a GTK application using DBus and have followed this guide: GNOME DBus Application Launching. I have set up a service file and configured the desktop to support DBus launching.

My application, MyApp, is successfully launched using the following DBus command:

gdbus call --session --dest org.example.MyApp --object-path /org/example/MyApp --method org.freedesktop.Application.Activate "{ 'token': <'example_data'> }"

Although MyApp launches correctly, I am struggling to access the payload { 'token': <'example_data'> } within the application. The method org.freedesktop.Application.Activate (as shown) allows an argument called platform_data, which I assume should let me pass and retrieve this payload.

<interface name='org.freedesktop.Application'>
    <method name='Activate'>
      <arg type='a{sv}' name='platform_data' direction='in'/>

Is there a specific method or process to access platform_data inside the application once it has been activated via DBus? Any guidance or examples would be greatly appreciated!

Thank you!

Looking at the code, it calls before_emit() and after_emit() with the platform data. According to the documentation:

Regardless of which of these entry points is used to start the application, GApplication passes some ‘platform data’ from the launching instance to the primary instance, in the form of a GVariant dictionary mapping strings to variants. To use platform data, override the Gio.ApplicationClass.before_emit or Gio.ApplicationClass.after_emit virtual functions in your GApplication subclass.

Thanks for the reply.
I also found that piece of info. I tried printing the platform data in my before_emit and after_emit function in my gtk.application class but no luck. The question now is when are those functions getting called? Are they called when the gtk app gets activated? Their function name implies they get called automatically before/after a signal, what is that signal?

As you can see from the linked code, before_emit() and after_emit() are called when before and after emitting the activate signal respectively. I just tested it in Python with PyGObject and it works fine:

from gi.repository import Gio

class MyApplication(Gio.Application):

    def do_before_emit(self, variant):
        Gio.Application.do_before_emit(self, variant)

    def do_after_emit(self, variant):
        Gio.Application.do_after_emit(self, variant)

    def do_activate(self):
        self.hold()  # Keep alive


Output with your gdbus command afterwards (first activate is from running as a command because I didn’t use DBus startup thing):

before_emit({'token': <'example_data'>})
after_emit({'token': <'example_data'>})

You may want to show what language/binding you are using (if any) and how you are doing the override.

1 Like

The issue was resolved thanks!
Not sure why I was not getting the emit to fire but it is working now. It works for gtk.application as well.