@@ -264,7 +264,6 @@ typedef struct webui_event_inf_t {
264264 void * gtk_win ;
265265 void * gtk_wv ;
266266 bool open ;
267- bool in_show ;
268267 // WebUI Window
269268 char * url ;
270269 bool navigate ;
@@ -277,6 +276,8 @@ typedef struct webui_event_inf_t {
277276 bool stop ;
278277 } _webui_wv_linux_t ;
279278
279+ #define GTK_WEBVIEW_SET_IN_SHOW (win , status ) if (win && win->has_all_events) { win->in_show = status; }
280+
280281#else
281282 extern bool _webui_macos_wv_new (int index , bool frameless , bool resizable );
282283 extern void _webui_macos_wv_new_thread_safe (int index , bool frameless , bool resizable );
@@ -387,6 +388,7 @@ typedef struct _webui_window_t {
387388 #ifdef _WIN32
388389 _webui_wv_win32_t * webView ;
389390 #elif __linux__
391+ bool in_show ;
390392 _webui_wv_linux_t * webView ;
391393 #else
392394 _webui_wv_macos_t * webView ;
@@ -8190,6 +8192,10 @@ static bool _webui_show_window(_webui_window_t* win, struct mg_connection* clien
81908192 _webui_log_debug ("[Core]\t\t_webui_show_window(FILE, [%zu])\n" , browser );
81918193 #endif
81928194
8195+ #if __linux__
8196+ GTK_WEBVIEW_SET_IN_SHOW (win , true)
8197+ #endif
8198+
81938199 #ifdef WEBUI_TLS
81948200 // TLS
81958201 if (_webui_is_empty (_webui .ssl_cert ) || _webui_is_empty (_webui .ssl_key )) {
@@ -8841,11 +8847,19 @@ static void _webui_print_hex(const char* data, size_t len) {
88418847 }
88428848}
88438849static void _webui_print_ascii (const char * data , size_t len ) {
8850+ // This function is used to print the protocol binary packets. the packet
8851+ // may have ASCII and `0x00` inside text, as well as other non-ascii bytes
88448852 for (size_t i = 0 ; i < len ; i ++ ) {
8845- if ((unsigned char )* data == 0x00 )
8846- _webui_log_debug ("%c" , 0xCF );
8847- else
8848- _webui_log_debug ("%c" , (unsigned char )* data );
8853+ register unsigned char c = (unsigned char )* data ;
8854+ if (c == 0x00 ) {
8855+ _webui_log_debug ("%c" , 0xCF ); // Print `¤` | TODO: Maybe we can simply print a blank space?
8856+ } else {
8857+ if (c < 32 || c > 126 ) {
8858+ _webui_log_debug ("[0x%02X]" , c );
8859+ } else {
8860+ _webui_log_debug ("%c" , c );
8861+ }
8862+ }
88498863 data ++ ;
88508864 }
88518865}
@@ -11876,35 +11890,19 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) {
1187611890 }
1187711891 }
1187811892
11879- static inline void _webui_wv_gtk_set_show (_webui_window_t * win , bool status ) {
11880- if (win ) {
11881- if (win -> webView && win -> has_all_events ) {
11882- win -> webView -> in_show = status ;
11883- }
11884- }
11885- }
11886-
11887- static inline bool _webui_wv_gtk_is_show (_webui_window_t * win ) {
11888- if (win ) {
11889- if (win -> webView && win -> has_all_events ) {
11890- return win -> webView -> in_show ;
11891- }
11892- }
11893- return true;
11894- }
11895-
1189611893 static bool _webui_wv_event_decision (void * widget , void * decision , int decision_type , void * user_data ) {
1189711894 switch (decision_type ) {
1189811895 case WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION : {
1189911896
1190011897 _webui_window_t * win = _webui_dereference_win_ptr (user_data );
1190111898
11902- if (!win -> has_all_events ) {
11903- return false;
11904- }
11905-
11906- if (_webui_wv_gtk_is_show (win )) {
11907- _webui_wv_gtk_set_show (win , false);
11899+ // If all events are handled, check in_show
11900+ if (win -> has_all_events ) {
11901+ if (win -> in_show ) { // Don't catch navigation event
11902+ GTK_WEBVIEW_SET_IN_SHOW (win , false)
11903+ return false;
11904+ }
11905+ } else { // Don't catch navigation event
1190811906 return false;
1190911907 }
1191011908
@@ -12137,7 +12135,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) {
1213712135 }
1213812136
1213912137 // Show
12140- _webui_wv_gtk_set_show ( win , true); // TODO: Check if we need this here because we are about to load a URI
12138+
1214112139 webkit_web_view_load_uri (win -> webView -> gtk_wv , win -> webView -> url );
1214212140 gtk_widget_show_all (win -> webView -> gtk_win );
1214312141 win -> webView -> open = true;
@@ -12429,14 +12427,6 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) {
1242912427 }
1243012428 }
1243112429
12432- if (_webui .is_webview ) {
12433- // We have a Linux WebKitGTK WebView running
12434- _webui_wv_gtk_set_show (win , true);
12435- } else {
12436- // Failed to start the Linux WebKitGTK
12437- _webui_wv_gtk_set_show (win , false);
12438- }
12439-
1244012430 #ifdef WEBUI_LOG
1244112431 _webui_log_debug ("[Core]\t\t_webui_wv_show() -> Return [%d]\n" , (_webui .is_webview == true));
1244212432 #endif
0 commit comments