11/*
2- * Copyright © 2017 Red Hat, Inc
2+ * Copyright © 2025 Red Hat, Inc
33 *
44 * SPDX-License-Identifier: LGPL-2.1-or-later
55 *
1515 *
1616 * You should have received a copy of the GNU Lesser General Public
1717 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
18- *
19- * Authors:
20- * Matthias Clasen <[email protected] > 2118 */
2219
2320#include "config.h"
3835#include "xdp-impl-dbus.h"
3936#include "xdp-portal-config.h"
4037#include "xdp-request.h"
38+ #include "xdp-request-future.h"
4139#include "xdp-utils.h"
4240
4341#include "email.h"
@@ -46,6 +44,7 @@ struct _XdpEmail
4644{
4745 XdpDbusEmailSkeleton parent_instance ;
4846
47+ XdpContext * context ;
4948 XdpDbusImplEmail * impl ;
5049};
5150
@@ -237,28 +236,11 @@ handle_compose_email (XdpDbusEmail *object,
237236 GVariant * arg_options )
238237{
239238 XdpEmail * email = XDP_EMAIL (object );
240- XdpRequest * request = xdp_request_from_invocation (invocation );
241- XdpAppInfo * app_info = request -> app_info ;
242- g_autoptr (XdpDbusImplRequest ) impl_request = NULL ;
239+ g_autoptr (XdpRequestFuture ) request = NULL ;
240+ XdpAppInfo * app_info = xdp_invocation_get_app_info (invocation );
243241 g_autoptr (GVariant ) options = NULL ;
244- g_autoptr (XdpDbusImplEmailComposeEmailResult ) result = NULL ;
245- XdgDesktopPortalResponseEnum response = XDG_DESKTOP_PORTAL_RESPONSE_OTHER ;
246242 g_autoptr (GError ) error = NULL ;
247243
248- impl_request = dex_await_object (xdp_dbus_impl_request_proxy_new_future (
249- g_dbus_proxy_get_connection (G_DBUS_PROXY (email -> impl )),
250- G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES ,
251- g_dbus_proxy_get_name (G_DBUS_PROXY (email -> impl )),
252- request -> id ),
253- & error );
254-
255- if (!impl_request )
256- {
257- g_dbus_method_invocation_return_gerror (g_steal_pointer (& invocation ),
258- error );
259- return G_DBUS_METHOD_INVOCATION_HANDLED ;
260- }
261-
262244 options = compose_email_validate_options (app_info ,
263245 fd_list ,
264246 arg_options ,
@@ -270,51 +252,53 @@ handle_compose_email (XdpDbusEmail *object,
270252 return G_DBUS_METHOD_INVOCATION_HANDLED ;
271253 }
272254
273- {
274- REQUEST_AUTOLOCK (request );
275-
276- xdp_request_set_impl_request (request , impl_request );
277- xdp_request_export (request , g_dbus_method_invocation_get_connection (invocation ));
278- }
255+ request = dex_await_object (xdp_request_future_new (email -> context ,
256+ app_info ,
257+ G_DBUS_INTERFACE_SKELETON (object ),
258+ G_DBUS_PROXY (email -> impl ),
259+ arg_options ),
260+ & error );
261+ if (!request )
262+ {
263+ g_dbus_method_invocation_return_gerror (g_steal_pointer (& invocation ),
264+ error );
265+ return G_DBUS_METHOD_INVOCATION_HANDLED ;
266+ }
279267
280268 xdp_dbus_email_complete_compose_email (object ,
281269 g_steal_pointer (& invocation ),
282270 NULL ,
283- request -> id );
284-
285- result = dex_await_boxed (xdp_dbus_impl_email_call_compose_email_future (
286- email -> impl ,
287- request -> id ,
288- xdp_app_info_get_id (app_info ),
289- arg_parent_window ,
290- options ),
291- & error );
292-
293- if (result )
294- {
295- response = result -> response ;
296- }
297- else
298- {
299- g_dbus_error_strip_remote_error (error );
300- g_warning ("Backend call failed: %s" , error -> message );
301-
302- response = XDG_DESKTOP_PORTAL_RESPONSE_OTHER ;
303- }
271+ xdp_request_future_get_object_path (request ));
304272
305273 {
306- REQUEST_AUTOLOCK (request );
307-
308- if (request -> exported )
274+ g_autoptr (XdpDbusImplEmailComposeEmailResult ) result = NULL ;
275+ XdgDesktopPortalResponseEnum response ;
276+ g_auto (GVariantBuilder ) new_results =
277+ G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_VARDICT );
278+
279+ result = dex_await_boxed (xdp_dbus_impl_email_call_compose_email_future (
280+ email -> impl ,
281+ xdp_request_future_get_object_path (request ),
282+ xdp_app_info_get_id (app_info ),
283+ arg_parent_window ,
284+ options ),
285+ & error );
286+
287+ if (result )
288+ {
289+ response = result -> response ;
290+ }
291+ else
309292 {
310- g_auto ( GVariantBuilder ) new_results =
311- G_VARIANT_BUILDER_INIT ( G_VARIANT_TYPE_VARDICT );
293+ g_dbus_error_strip_remote_error ( error );
294+ g_warning ( "Backend call failed: %s" , error -> message );
312295
313- xdp_dbus_request_emit_response (XDP_DBUS_REQUEST (request ),
314- response ,
315- g_variant_builder_end (& new_results ));
316- xdp_request_unexport (request );
296+ response = XDG_DESKTOP_PORTAL_RESPONSE_OTHER ;
317297 }
298+
299+ xdp_request_future_emit_response (request ,
300+ response ,
301+ g_variant_builder_end (& new_results ));
318302 }
319303
320304 return G_DBUS_METHOD_INVOCATION_HANDLED ;
@@ -350,11 +334,13 @@ xdp_email_class_init (XdpEmailClass *klass)
350334}
351335
352336static XdpEmail *
353- xdp_email_new (XdpDbusImplEmail * impl )
337+ xdp_email_new (XdpContext * context ,
338+ XdpDbusImplEmail * impl )
354339{
355340 XdpEmail * email ;
356341
357342 email = g_object_new (xdp_email_get_type (), NULL );
343+ email -> context = context ; // FIXME there might be problems with the context lifetime
358344 email -> impl = g_object_ref (impl );
359345
360346 g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (email -> impl ), G_MAXINT );
@@ -364,10 +350,10 @@ xdp_email_new (XdpDbusImplEmail *impl)
364350 return email ;
365351}
366352
367- static DexFuture *
368- run_email_fiber (gpointer user_data )
353+ DexFuture *
354+ init_email (gpointer user_data )
369355{
370- XdpContext * context = user_data ;
356+ XdpContext * context = XDP_CONTEXT ( user_data ) ;
371357 g_autoptr (XdpEmail ) email = NULL ;
372358 GDBusConnection * connection = xdp_context_get_connection (context );
373359 XdpPortalConfig * config = xdp_context_get_config (context );
@@ -391,24 +377,10 @@ run_email_fiber (gpointer user_data)
391377 return dex_future_new_false ();
392378 }
393379
394- email = xdp_email_new (impl );
380+ email = xdp_email_new (context , impl );
395381
396382 xdp_context_take_and_export_portal (context ,
397383 G_DBUS_INTERFACE_SKELETON (g_steal_pointer (& email )),
398384 XDP_CONTEXT_EXPORT_FLAGS_RUN_IN_FIBER );
399385 return dex_future_new_true ();
400386}
401-
402- void
403- init_email (XdpContext * context ,
404- GCancellable * cancellable )
405- {
406- DexFuture * f ;
407-
408- f = dex_future_first (dex_scheduler_spawn (NULL , 0 ,
409- run_email_fiber ,
410- context , NULL ),
411- dex_cancellable_new_from_cancellable (cancellable ),
412- NULL );
413- dex_future_disown (f );
414- }
0 commit comments