summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOndrej Holy <oholy@redhat.com>2019-01-22 16:29:20 +0100
committerOndrej Holy <oholy@redhat.com>2019-01-28 16:42:34 +0100
commit051c6ba4e7111b04ab417403730b82de02a1c0d8 (patch)
tree57304ac839b81f252c3f0a9f28b9ff29c31d567a
parent904bb264e90a56f75586369810bbc50c45b3ed2f (diff)
downloadglib-051c6ba4e7111b04ab417403730b82de02a1c0d8.tar.gz
gio-tool-open: Use g_app_info_launch_default_for_uri_async()
The recent changes of the g_app_info_launch_default_for_uri_async() function ensures that the callback is not called before DBus-activated applications start. Let's use g_app_info_launch_default_for_uri_async() and remove the workarounds for DBus-activated applications. Closes: https://gitlab.gnome.org/GNOME/glib/issues/1249
-rw-r--r--gio/gio-tool-open.c120
1 files changed, 26 insertions, 94 deletions
diff --git a/gio/gio-tool-open.c b/gio/gio-tool-open.c
index 73863c7c5..ac6764a97 100644
--- a/gio/gio-tool-open.c
+++ b/gio/gio-tool-open.c
@@ -29,73 +29,32 @@
#include "gio-tool.h"
+static int n_outstanding = 0;
+static gboolean success = TRUE;
static const GOptionEntry entries[] = {
{ NULL }
};
-#if defined(G_OS_UNIX) && !defined(HAVE_COCOA)
-static gboolean
-get_bus_name_and_path_from_uri (const char *uri,
- char **bus_name_out,
- char **object_path_out)
+static void
+launch_default_for_uri_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
{
- GAppInfo *app_info = NULL;
- char *bus_name = NULL;
- char *object_path = NULL;
- char *uri_scheme;
- const char *filename;
- char *basename = NULL;
- char *p;
- gboolean got_name = FALSE;
-
- uri_scheme = g_uri_parse_scheme (uri);
- if (uri_scheme && uri_scheme[0] != '\0')
- app_info = g_app_info_get_default_for_uri_scheme (uri_scheme);
- g_free (uri_scheme);
-
- if (app_info == NULL)
- {
- GFile *file;
+ GError *error = NULL;
+ gchar *uri = user_data;
- file = g_file_new_for_uri (uri);
- app_info = g_file_query_default_handler (file, NULL, NULL);
- g_object_unref (file);
+ if (!g_app_info_launch_default_for_uri_finish (res, &error))
+ {
+ print_error ("%s: %s", uri, error->message);
+ g_clear_error (&error);
+ success = FALSE;
}
- if (app_info == NULL || !G_IS_DESKTOP_APP_INFO (app_info) ||
- !g_desktop_app_info_get_boolean (G_DESKTOP_APP_INFO (app_info), "DBusActivatable"))
- goto out;
-
- filename = g_desktop_app_info_get_filename (G_DESKTOP_APP_INFO (app_info));
- if (filename == NULL)
- goto out;
-
- basename = g_path_get_basename (filename);
- if (!g_str_has_suffix (basename, ".desktop"))
- goto out;
-
- basename[strlen (basename) - strlen (".desktop")] = '\0';
- if (!g_dbus_is_name (basename))
- goto out;
-
- bus_name = g_strdup (basename);
- object_path = g_strdup_printf ("/%s", bus_name);
- for (p = object_path; *p != '\0'; p++)
- if (*p == '.')
- *p = '/';
+ n_outstanding--;
- *bus_name_out = g_steal_pointer (&bus_name);
- *object_path_out = g_steal_pointer (&object_path);
- got_name = TRUE;
-
-out:
- g_clear_object (&app_info);
- g_clear_pointer (&basename, g_free);
-
- return got_name;
+ g_free (uri);
}
-#endif
int
handle_open (int argc, char *argv[], gboolean do_help)
@@ -104,8 +63,6 @@ handle_open (int argc, char *argv[], gboolean do_help)
gchar *param;
GError *error = NULL;
int i;
- gboolean success;
- gboolean res;
g_set_prgname ("gio open");
@@ -143,7 +100,6 @@ handle_open (int argc, char *argv[], gboolean do_help)
g_option_context_free (context);
- success = TRUE;
for (i = 1; i < argc; i++)
{
char *uri = NULL;
@@ -162,47 +118,23 @@ handle_open (int argc, char *argv[], gboolean do_help)
uri = g_file_get_uri (file);
g_object_unref (file);
}
+ else
+ uri = g_strdup (argv[i]);
g_free (uri_scheme);
- res = g_app_info_launch_default_for_uri (uri ? uri : argv[i], NULL, &error);
- if (!res)
- {
- print_error ("%s: %s", uri ? uri : argv[i], error->message);
- g_clear_error (&error);
- success = FALSE;
- }
+ g_app_info_launch_default_for_uri_async (uri,
+ NULL,
+ NULL,
+ launch_default_for_uri_cb,
+ g_strdup (uri));
-#if defined(G_OS_UNIX) && !defined(HAVE_COCOA)
- /* FIXME: This chunk of madness is a workaround for a dbus-daemon bug.
- * See https://bugzilla.gnome.org/show_bug.cgi?id=780296
- */
- if (res)
- {
- char *bus_name = NULL;
- char *object_path = NULL;
-
- if (get_bus_name_and_path_from_uri (uri ? uri : argv[i], &bus_name, &object_path))
- {
- GDBusConnection *connection;
- connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
-
- if (connection)
- g_dbus_connection_call_sync (connection,
- bus_name,
- object_path,
- "org.freedesktop.DBus.Peer",
- "Ping",
- NULL, NULL,
- G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL);
- g_clear_object (&connection);
- g_free (bus_name);
- g_free (object_path);
- }
- }
-#endif
+ n_outstanding++;
g_free (uri);
}
+ while (n_outstanding > 0)
+ g_main_context_iteration (NULL, TRUE);
+
return success ? 0 : 2;
}