From a3d63b3579d62df4b390e3dce869290f6a0b9685 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 26 Apr 2024 14:58:41 -0400 Subject: [PATCH] label: Report errors Print a warning when launching a handler fails. --- gtk/gtklabel.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c index fe9c72fd91..776ab34ac4 100644 --- a/gtk/gtklabel.c +++ b/gtk/gtklabel.c @@ -2113,6 +2113,28 @@ gtk_label_unroot (GtkWidget *widget) GTK_WIDGET_CLASS (gtk_label_parent_class)->unroot (widget); } +static void +launch_done (GObject *source, + GAsyncResult *result, + gpointer data) +{ + GError *error = NULL; + gboolean success; + + if (GTK_IS_FILE_LAUNCHER (source)) + success = gtk_file_launcher_launch_finish (GTK_FILE_LAUNCHER (source), result, &error); + else if (GTK_IS_URI_LAUNCHER (source)) + success = gtk_uri_launcher_launch_finish (GTK_URI_LAUNCHER (source), result, &error); + else + g_assert_not_reached (); + + if (!success) + { + g_warning ("Failed to launch handler: %s", error->message); + g_error_free (error); + } +} + static gboolean gtk_label_activate_link (GtkLabel *self, const char *uri) @@ -2132,7 +2154,7 @@ gtk_label_activate_link (GtkLabel *self, file = g_file_new_for_uri (uri); launcher = gtk_file_launcher_new (file); - gtk_file_launcher_launch (launcher, GTK_WINDOW (toplevel), NULL, NULL, NULL); + gtk_file_launcher_launch (launcher, GTK_WINDOW (toplevel), NULL, launch_done, NULL); g_object_unref (launcher); g_object_unref (file); } @@ -2141,7 +2163,7 @@ gtk_label_activate_link (GtkLabel *self, GtkUriLauncher *launcher; launcher = gtk_uri_launcher_new (uri); - gtk_uri_launcher_launch (launcher, GTK_WINDOW (toplevel), NULL, NULL, NULL); + gtk_uri_launcher_launch (launcher, GTK_WINDOW (toplevel), NULL, launch_done, NULL); g_object_unref (launcher); }