@@ -496,24 +496,30 @@ Error FreeDesktopPortalDesktop::file_dialog_show(DisplayServer::WindowID p_windo
496496 return OK;
497497}
498498
499- void FreeDesktopPortalDesktop::_file_dialog_callback (const Callable &p_callable, const Variant &p_status, const Variant &p_list, const Variant &p_index, const Variant &p_options, bool p_opt_in_cb) {
500- if (p_opt_in_cb) {
501- Variant ret;
502- Callable::CallError ce;
503- const Variant *args[4 ] = { &p_status, &p_list, &p_index, &p_options };
504-
505- p_callable.callp (args, 4 , ret, ce);
506- if (ce.error != Callable::CallError::CALL_OK) {
507- ERR_PRINT (vformat (" Failed to execute file dialogs callback: %s." , Variant::get_callable_error_text (p_callable, args, 4 , ce)));
508- }
509- } else {
510- Variant ret;
511- Callable::CallError ce;
512- const Variant *args[3 ] = { &p_status, &p_list, &p_index };
499+ void FreeDesktopPortalDesktop::process_file_dialog_callbacks () {
500+ MutexLock lock (file_dialog_mutex);
501+ while (!pending_cbs.is_empty ()) {
502+ FileDialogCallback cb = pending_cbs.front ()->get ();
503+ pending_cbs.pop_front ();
504+
505+ if (cb.opt_in_cb ) {
506+ Variant ret;
507+ Callable::CallError ce;
508+ const Variant *args[4 ] = { &cb.status , &cb.files , &cb.index , &cb.options };
509+
510+ cb.callback .callp (args, 4 , ret, ce);
511+ if (ce.error != Callable::CallError::CALL_OK) {
512+ ERR_PRINT (vformat (" Failed to execute file dialog callback: %s." , Variant::get_callable_error_text (cb.callback , args, 4 , ce)));
513+ }
514+ } else {
515+ Variant ret;
516+ Callable::CallError ce;
517+ const Variant *args[3 ] = { &cb.status , &cb.files , &cb.index };
513518
514- p_callable.callp (args, 3 , ret, ce);
515- if (ce.error != Callable::CallError::CALL_OK) {
516- ERR_PRINT (vformat (" Failed to execute file dialogs callback: %s." , Variant::get_callable_error_text (p_callable, args, 3 , ce)));
519+ cb.callback .callp (args, 3 , ret, ce);
520+ if (ce.error != Callable::CallError::CALL_OK) {
521+ ERR_PRINT (vformat (" Failed to execute file dialog callback: %s." , Variant::get_callable_error_text (cb.callback , args, 3 , ce)));
522+ }
517523 }
518524 }
519525}
@@ -556,7 +562,14 @@ void FreeDesktopPortalDesktop::_thread_monitor(void *p_ud) {
556562 file_chooser_parse_response (&iter, fd.filter_names , cancel, uris, index, options);
557563
558564 if (fd.callback .is_valid ()) {
559- callable_mp (portal, &FreeDesktopPortalDesktop::_file_dialog_callback).call_deferred (fd.callback , !cancel, uris, index, options, fd.opt_in_cb );
565+ FileDialogCallback cb;
566+ cb.callback = fd.callback ;
567+ cb.status = !cancel;
568+ cb.files = uris;
569+ cb.index = index;
570+ cb.options = options;
571+ cb.opt_in_cb = fd.opt_in_cb ;
572+ portal->pending_cbs .push_back (cb);
560573 }
561574 if (fd.prev_focus != DisplayServer::INVALID_WINDOW_ID) {
562575 callable_mp (DisplayServer::get_singleton (), &DisplayServer::window_move_to_foreground).call_deferred (fd.prev_focus );
0 commit comments