@@ -339,6 +339,9 @@ typedef struct _webui_window_t {
339339 size_t process_id ;
340340 const void * (* files_handler )(const char * filename , int * length );
341341 const void * (* files_handler_window )(size_t window , const char * filename , int * length );
342+ const void * file_handler_async_response ;
343+ int file_handler_async_len ;
344+ bool file_handler_async_done ;
342345 webui_event_inf_t * events [WEBUI_MAX_IDS ];
343346 size_t events_count ;
344347 bool is_public ;
@@ -3675,6 +3678,34 @@ void webui_interface_set_response(size_t window, size_t event_number, const char
36753678 #endif
36763679}
36773680
3681+ void webui_interface_set_response_file_handler (size_t window , const void * response , int length ) {
3682+
3683+ #ifdef WEBUI_LOG
3684+ printf ("[User] webui_interface_set_response_file_handler()\n" );
3685+ printf ("[User] webui_interface_set_response_file_handler() -> window #%zu\n" , window );
3686+ printf ("[User] webui_interface_set_response_file_handler() -> Response %zu bytes\n" , length );
3687+ #endif
3688+
3689+ // Initialization
3690+ _webui_init ();
3691+
3692+ // Dereference
3693+ if (_webui_mutex_is_exit_now (WEBUI_MUTEX_NONE ) || _webui .wins [window ] == NULL )
3694+ return ;
3695+ _webui_window_t * win = _webui .wins [window ];
3696+
3697+ // Set the response
3698+ win -> file_handler_async_response = response ;
3699+ win -> file_handler_async_len = length ;
3700+
3701+ // Async response
3702+ if (_webui .config .asynchronous_response ) {
3703+ _webui_mutex_lock (& _webui .mutex_async_response );
3704+ win -> file_handler_async_done = true;
3705+ _webui_mutex_unlock (& _webui .mutex_async_response );
3706+ }
3707+ }
3708+
36783709bool webui_interface_is_app_running (void ) {
36793710
36803711 #ifdef WEBUI_LOG
@@ -4494,10 +4525,28 @@ static int _webui_external_file_handler(_webui_window_t* win, struct mg_connecti
44944525 printf ("[Call]\n" );
44954526 #endif
44964527
4528+ // Async response ini
4529+ if (_webui .config .asynchronous_response ) {
4530+ win -> file_handler_async_response = NULL ;
4531+ win -> file_handler_async_len = 0 ;
4532+ win -> file_handler_async_done = false;
4533+ }
4534+
44974535 // True if we pass the window num to the handler, false otherwise.
44984536 int is_file_handler_window = win -> files_handler_window != NULL ;
44994537 const void * callback_resp = is_file_handler_window ? win -> files_handler_window (win -> num , url , (int * )& length ) : win -> files_handler (url , (int * )& length );
45004538
4539+ // Async response wait
4540+ if (_webui .config .asynchronous_response ) {
4541+ bool done = false;
4542+ while (!done ) {
4543+ _webui_sleep (10 );
4544+ _webui_mutex_lock (& _webui .mutex_async_response );
4545+ if (win -> file_handler_async_done ) done = true;
4546+ _webui_mutex_unlock (& _webui .mutex_async_response );
4547+ }
4548+ }
4549+
45014550 if (callback_resp != NULL ) {
45024551
45034552 // File content found
0 commit comments