@@ -200,6 +200,7 @@ typedef struct _webui_core_t {
200200 webui_mutex_t mutex_receive ;
201201 webui_mutex_t mutex_wait ;
202202 webui_mutex_t mutex_bridge ;
203+ webui_mutex_t mutex_js_run ;
203204 webui_condition_t condition_wait ;
204205 char * default_server_root_path ;
205206 bool ui ;
@@ -468,7 +469,9 @@ bool webui_script(size_t window, const char* script, size_t timeout_second, char
468469
469470 // Initializing pipe
470471 uint16_t run_id = _webui_get_run_id ();
472+ _webui_mutex_lock ( & _webui_core .mutex_js_run );
471473 _webui_core .run_done [run_id ] = false;
474+ _webui_mutex_unlock ( & _webui_core .mutex_js_run );
472475 _webui_core .run_error [run_id ] = false;
473476 _webui_core .run_userBuffer [run_id ] = buffer ;
474477 _webui_core .run_userBufferLen [run_id ] = buffer_length ;
@@ -481,13 +484,18 @@ bool webui_script(size_t window, const char* script, size_t timeout_second, char
481484 // Send the packet
482485 _webui_send (win , win -> token , run_id , WEBUI_CMD_JS , script , js_len );
483486
487+ bool js_status = false;
488+
484489 // Wait for UI response
485490 if (timeout_second < 1 || timeout_second > 86400 ) {
486491
487492 // Wait forever
488493 for (;;) {
489494 _webui_sleep (1 );
490- if (_webui_core .run_done [run_id ])
495+ _webui_mutex_lock ( & _webui_core .mutex_js_run );
496+ js_status = _webui_core .run_done [run_id ];
497+ _webui_mutex_unlock ( & _webui_core .mutex_js_run );
498+ if (js_status )
491499 break ;
492500 }
493501 } else {
@@ -497,14 +505,17 @@ bool webui_script(size_t window, const char* script, size_t timeout_second, char
497505 _webui_timer_start ( & timer );
498506 for (;;) {
499507 _webui_sleep (1 );
500- if (_webui_core .run_done [run_id ])
508+ _webui_mutex_lock ( & _webui_core .mutex_js_run );
509+ js_status = _webui_core .run_done [run_id ];
510+ _webui_mutex_unlock ( & _webui_core .mutex_js_run );
511+ if (js_status )
501512 break ;
502513 if (_webui_timer_is_end ( & timer , (timeout_second * 1000 )))
503514 break ;
504515 }
505516 }
506517
507- if (_webui_core . run_done [ run_id ] ) {
518+ if (js_status ) {
508519
509520 #ifdef WEBUI_LOG
510521 printf (
@@ -2288,6 +2299,23 @@ bool webui_interface_get_bool_at(size_t window, size_t event_number, size_t inde
22882299 return webui_get_bool_at (& e , index );
22892300}
22902301
2302+ size_t webui_interface_get_size_at (size_t window , size_t event_number , size_t index ) {
2303+
2304+ #ifdef WEBUI_LOG
2305+ printf ("[User] webui_interface_get_size_at([%zu], [%zu], [%zu])...\n" , window , event_number , index );
2306+ #endif
2307+
2308+ // New Event
2309+ webui_event_t e ;
2310+ e .window = window ;
2311+ e .event_type = 0 ;
2312+ e .element = NULL ;
2313+ e .event_number = event_number ;
2314+ e .bind_id = 0 ;
2315+
2316+ return webui_get_size_at (& e , index );
2317+ }
2318+
22912319size_t webui_interface_bind (size_t window , const char * element , void ( * func )(size_t , size_t , char * , size_t , size_t )) {
22922320
22932321 #ifdef WEBUI_LOG
@@ -4623,6 +4651,7 @@ static void _webui_clean(void) {
46234651 _webui_mutex_destroy ( & _webui_core .mutex_send );
46244652 _webui_mutex_destroy ( & _webui_core .mutex_receive );
46254653 _webui_mutex_destroy ( & _webui_core .mutex_wait );
4654+ _webui_mutex_destroy ( & _webui_core .mutex_js_run );
46264655 _webui_condition_destroy ( & _webui_core .condition_wait );
46274656
46284657 #ifdef WEBUI_LOG
@@ -6028,6 +6057,7 @@ static void _webui_init(void) {
60286057 _webui_mutex_init ( & _webui_core .mutex_receive );
60296058 _webui_mutex_init ( & _webui_core .mutex_wait );
60306059 _webui_mutex_init ( & _webui_core .mutex_bridge );
6060+ _webui_mutex_init ( & _webui_core .mutex_js_run );
60316061 _webui_condition_init ( & _webui_core .condition_wait );
60326062
60336063 // // Determine whether the current device
@@ -7131,7 +7161,9 @@ static WEBUI_THREAD_RECEIVE {
71317161
71327162 if (_webui_core .run_userBuffer [packet_id ] != NULL ) {
71337163
7164+ _webui_mutex_lock ( & _webui_core .mutex_js_run );
71347165 _webui_core .run_done [packet_id ] = false;
7166+ _webui_mutex_unlock ( & _webui_core .mutex_js_run );
71357167
71367168 // Get js-error
71377169 bool error = true;
@@ -7195,7 +7227,9 @@ static WEBUI_THREAD_RECEIVE {
71957227 }
71967228
71977229 // Send ready signal to webui_script()
7230+ _webui_mutex_lock ( & _webui_core .mutex_js_run );
71987231 _webui_core .run_done [packet_id ] = true;
7232+ _webui_mutex_unlock ( & _webui_core .mutex_js_run );
71997233 }
72007234 }
72017235 } else if ((unsigned char ) packet [WEBUI_PROTOCOL_CMD ] == WEBUI_CMD_NAVIGATION ) {
0 commit comments