Skip to content

Commit ad3fbc2

Browse files
committed
Fix Reload Delay
1 parent 491320a commit ad3fbc2

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

include/webui.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ namespace webui {
245245
});
246246
}
247247

248-
// Show a window using a embedded HTML, or a file. If the window is already opened
248+
// Show a window (WebView/Browser) using a embedded HTML, or a file. If the window is already opened
249249
// then it will be refreshed.
250250
bool show(const std::string_view content) const {
251251
return webui_show(webui_window, content.data());

src/webui.c

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)