Skip to content

Commit 1d8644b

Browse files
committed
Merge branch 'main' of https://github.com/webui-dev/webui
2 parents 527fc4d + d6128b9 commit 1d8644b

File tree

1 file changed

+48
-10
lines changed

1 file changed

+48
-10
lines changed

src/webui.c

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ typedef struct webui_event_inf_t {
264264
void* gtk_win;
265265
void* gtk_wv;
266266
bool open;
267+
bool in_show;
267268
// WebUI Window
268269
char* url;
269270
bool navigate;
@@ -275,6 +276,7 @@ typedef struct webui_event_inf_t {
275276
unsigned int y;
276277
bool stop;
277278
} _webui_wv_linux_t;
279+
278280
#else
279281
extern bool _webui_macos_wv_new(int index, bool frameless, bool resizable);
280282
extern void _webui_macos_wv_new_thread_safe(int index, bool frameless, bool resizable);
@@ -11849,6 +11851,15 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) {
1184911851
#define GTK_RUNTIME_ARR { "libgtk-3.so.0" } // TODO: Add GTK v4 APIs "libgtk-4.so.1"
1185011852
#define WEBKIT_RUNTIME_ARR { "libwebkit2gtk-4.1.so.0", "libwebkit2gtk-4.0.so.37" }
1185111853

11854+
// Decision Event
11855+
#define WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION 0
11856+
#define WEBKIT_NAVIGATION_TYPE_LINK_CLICKED 0
11857+
#define WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED 1
11858+
#define WEBKIT_NAVIGATION_TYPE_BACK_FORWARD 2
11859+
#define WEBKIT_NAVIGATION_TYPE_RELOAD 3
11860+
#define WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED 4
11861+
#define WEBKIT_NAVIGATION_TYPE_OTHER 5
11862+
1185211863
// Title Event
1185311864
static void _webui_wv_event_title(void *web_view, void *pspec, void *arg) {
1185411865
#ifdef WEBUI_LOG
@@ -11865,22 +11876,40 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) {
1186511876
}
1186611877
}
1186711878

11868-
// Decision Event
11869-
#define WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION 0
11870-
#define WEBKIT_NAVIGATION_TYPE_LINK_CLICKED 0
11871-
#define WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED 1
11872-
#define WEBKIT_NAVIGATION_TYPE_BACK_FORWARD 2
11873-
#define WEBKIT_NAVIGATION_TYPE_RELOAD 3
11874-
#define WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED 4
11875-
#define WEBKIT_NAVIGATION_TYPE_OTHER 5
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+
}
1187611895

1187711896
static bool _webui_wv_event_decision(void *widget, void *decision, int decision_type, void *user_data) {
1187811897
switch(decision_type) {
1187911898
case WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION: {
1188011899

11881-
webkit_policy_decision_ignore(decision);
11882-
1188311900
_webui_window_t* win = _webui_dereference_win_ptr(user_data);
11901+
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);
11908+
return false;
11909+
}
11910+
11911+
webkit_policy_decision_ignore(decision);
11912+
1188411913
int navigation_type = webkit_navigation_policy_decision_get_navigation_type(decision);
1188511914
void *uri_request = webkit_navigation_policy_decision_get_request(decision);
1188611915
const char *webkit_uri = webkit_uri_request_get_uri(uri_request);
@@ -12108,6 +12137,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) {
1210812137
}
1210912138

1211012139
// Show
12140+
_webui_wv_gtk_set_show(win, true); // TODO: Check if we need this here because we are about to load a URI
1211112141
webkit_web_view_load_uri(win->webView->gtk_wv, win->webView->url);
1211212142
gtk_widget_show_all(win->webView->gtk_win);
1211312143
win->webView->open = true;
@@ -12399,6 +12429,14 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) {
1239912429
}
1240012430
}
1240112431

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+
1240212440
#ifdef WEBUI_LOG
1240312441
_webui_log_debug("[Core]\t\t_webui_wv_show() -> Return [%d]\n", (_webui.is_webview == true));
1240412442
#endif

0 commit comments

Comments
 (0)