@@ -8623,25 +8623,34 @@ static bool _webui_show_window(_webui_window_t* win, struct mg_connection* clien
86238623 _webui_mutex_win_is_exit_now (win , WEBUI_MUTEX_SET_FALSE );
86248624
86258625 // Wait for server threads to stop
8626- _webui_timer_t timer ;
8627- _webui_timer_start (& timer );
8628- for (;;) {
8629- #ifdef WEBUI_LOG
8630- _webui_log_debug ("[Core]\t\t_webui_show_window() -> Waiting for server thread to stop...\n" );
8631- #endif
8632- _webui_sleep (100 );
8633- if (!_webui_mutex_is_server_running (win , WEBUI_MUTEX_GET_STATUS )) {
8634- #ifdef WEBUI_LOG
8635- _webui_log_debug ("[Core]\t\t_webui_show_window() -> Server thread stopped.\n" );
8636- #endif
8637- break ;
8638- }
8639- if (_webui_timer_is_end (& timer , 1500 )) {
8626+ if (!_webui_mutex_is_connected (win , WEBUI_MUTEX_GET_STATUS ) &&
8627+ _webui_mutex_is_server_running (win , WEBUI_MUTEX_GET_STATUS )) {
8628+ // This is not a UI reload. The server thread is still running,
8629+ // wait for it to stop before starting a new one.
8630+ _webui_timer_t timer ;
8631+ _webui_timer_start (& timer );
8632+ for (;;) {
86408633 #ifdef WEBUI_LOG
8641- _webui_log_debug ("[Core]\t\t_webui_show_window() -> Server thread did not stop in time .\n" );
8634+ _webui_log_debug ("[Core]\t\t_webui_show_window() -> Waiting for server thread to stop.. .\n" );
86428635 #endif
8643- break ;
8636+ _webui_sleep (100 );
8637+ if (!_webui_mutex_is_server_running (win , WEBUI_MUTEX_GET_STATUS )) {
8638+ #ifdef WEBUI_LOG
8639+ _webui_log_debug ("[Core]\t\t_webui_show_window() -> Server thread stopped.\n" );
8640+ #endif
8641+ break ;
8642+ }
8643+ if (_webui_timer_is_end (& timer , 1500 )) {
8644+ #ifdef WEBUI_LOG
8645+ _webui_log_debug ("[Core]\t\t_webui_show_window() -> Server thread did not stop in time.\n" );
8646+ #endif
8647+ break ;
8648+ }
86448649 }
8650+ } else {
8651+ #ifdef WEBUI_LOG
8652+ _webui_log_debug ("[Core]\t\t_webui_show_window() -> This is UI reload, reusing the same server thread.\n" );
8653+ #endif
86458654 }
86468655
86478656 // Initialization
0 commit comments