Migrating from libunique to GApplication or GtkApplication

Uniqueness
Commands and Messages

libunique offers 'unique application' support as well as ways to communicate with a running application instance. This is implemented in various ways, either using D-Bus, or socket-based communication.

Starting with GLib 2.26, D-Bus support has been integrated into GIO in the form of GDBus, and GApplication has been added to provide the same level of application support as libunique.

Example 20. A unique application

Here is a simple application using libunique:

1

The same application using GtkApplication:

1


Uniqueness

Instead of creating a UniqueApp with unique_app_new(), create a GApplication with g_application_new() or a GtkApplication with gtk_application_new(). The name that was used with unique_app_new() is very likely usable as the application_id for g_application_new() without any changes, and GtkApplication passes the DESKTOP_STARTUP_ID environment variable automatically.

While libunique expects you to check for an already running instance yourself and activate it manually, GApplication handles all this on its own in g_application_run(). If you still need to find out if there is a running instance of your application, use g_application_get_is_remote() instead of unique_app_is_running().