From 6ae0b8e104b233b2466a2ffa248e667148117d3b Mon Sep 17 00:00:00 2001 From: Xiaotian Wu Date: Sat, 7 Jan 2023 19:23:26 +0800 Subject: Open default application using async function --- plugins/media-keys/msd-media-keys-manager.c | 39 ++++++++++++++++------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/plugins/media-keys/msd-media-keys-manager.c b/plugins/media-keys/msd-media-keys-manager.c index 0aee95f..5ab8946 100644 --- a/plugins/media-keys/msd-media-keys-manager.c +++ b/plugins/media-keys/msd-media-keys-manager.c @@ -492,27 +492,32 @@ dialog_show (MsdMediaKeysManager *manager) gdk_display_sync (gdk_screen_get_display (manager->priv->current_screen)); } +static void +launch_default_for_uri_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GError *error = NULL; + gchar *uri = user_data; + + if (!g_app_info_launch_default_for_uri_finish (res, &error)) + { + g_warning ("Could not launch '%s': %s", uri, + error->message); + g_clear_error (&error); + } + g_free (uri); +} + static void do_url_action (MsdMediaKeysManager *manager, const gchar *scheme) { - GError *error = NULL; - GAppInfo *app_info; - - app_info = g_app_info_get_default_for_uri_scheme (scheme); - - if (app_info != NULL) { - if (!g_app_info_launch (app_info, NULL, NULL, &error)) { - g_warning ("Could not launch '%s': %s", - g_app_info_get_commandline (app_info), - error->message); - g_object_unref (app_info); - g_error_free (error); - } - } - else { - g_warning ("Could not find default application for '%s' scheme", scheme); - } + g_app_info_launch_default_for_uri_async (scheme, + NULL, + NULL, + launch_default_for_uri_cb, + g_strdup (scheme)); } static void -- cgit v1.2.1