From: Matthias Clasen Date: Tue, 14 Jan 2020 06:03:48 +0000 (-0500) Subject: Handle lack of file transfer portal X-Git-Tag: archive/raspbian/4.4.1+ds1-2+rpi1^2~18^2~20^2~338 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=806e159b8ba18d9044641994d89d2c32dbf09ffa;p=gtk4.git Handle lack of file transfer portal Don't block for 25 seconds trying to get a bus connection. Give up after 1 second. --- diff --git a/gdk/filetransferportal.c b/gdk/filetransferportal.c index 382c8bd299..6f31c917ff 100644 --- a/gdk/filetransferportal.c +++ b/gdk/filetransferportal.c @@ -42,6 +42,40 @@ #include "filetransferportalprivate.h" static GDBusProxy *file_transfer_proxy = NULL; +static gboolean done; +static guint timeout_id; + +static void +got_proxy (GObject *source, + GAsyncResult *result, + gpointer data) +{ + GError *error = NULL; + + file_transfer_proxy = g_dbus_proxy_new_for_bus_finish (result, &error); + if (!file_transfer_proxy) + { + g_message ("failed to get file transfer portal proxy: %s", error->message); + g_error_free (error); + } + + done = TRUE; +} + +static gboolean +give_up_on_proxy (gpointer data) +{ + GCancellable *cancellable = data; + + g_cancellable_cancel (cancellable); + + timeout_id = 0; + done = TRUE; + + g_main_context_wakeup (NULL); + + return G_SOURCE_REMOVE; +} static GDBusProxy * ensure_file_transfer_portal (void) @@ -49,16 +83,29 @@ ensure_file_transfer_portal (void) if (file_transfer_proxy == NULL) { GError *error = NULL; + GCancellable *cancellable; + + cancellable = g_cancellable_new (); + + g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES + | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS + | G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, + NULL, + "org.freedesktop.portal.Documents", + "/org/freedesktop/portal/documents", + "org.freedesktop.portal.FileTransfer", + cancellable, + got_proxy, + NULL); + + timeout_id = g_timeout_add_full (1000, 0, give_up_on_proxy, cancellable, g_object_unref); + + while (!done) + g_main_context_iteration (NULL, TRUE); - file_transfer_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, - G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES - | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS - | G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, - NULL, - "org.freedesktop.portal.Documents", - "/org/freedesktop/portal/documents", - "org.freedesktop.portal.FileTransfer", - NULL, &error); + if (timeout_id) + g_source_remove (timeout_id); if (error) {