From 6212463543fd4c4c787895356bfc72a0ebaaa542 Mon Sep 17 00:00:00 2001 From: RDW Date: Fri, 10 Jan 2025 01:50:11 +0100 Subject: [PATCH 1/4] Deps: Update webview to the latest HEAD --- deps/webview/webview | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/webview/webview b/deps/webview/webview index 52952dc5c..3b7e27fd3 160000 --- a/deps/webview/webview +++ b/deps/webview/webview @@ -1 +1 @@ -Subproject commit 52952dc5ccfacdfb84bd3bb7cde869cbbaa5439e +Subproject commit 3b7e27fd3ec028e1fafcd46fac994860c204505f From 48972c33ed2377aa7ee0015a70f51ff0e58673f7 Mon Sep 17 00:00:00 2001 From: RDW Date: Fri, 10 Jan 2025 02:14:47 +0100 Subject: [PATCH 2/4] Runtime: Fix build errors due to webview API changes The latest version is v0.12.0, which introduced some breaking changes. --- BuildTools/Targets/EvoBuildTarget.lua | 2 +- Runtime/Bindings/FFI/webview/webview_ffi.cpp | 13 +++++++++++-- Runtime/Bindings/FFI/webview/webview_mac.hpp | 4 ++-- Runtime/Bindings/FFI/webview/webview_unix.hpp | 4 ++-- Runtime/Bindings/FFI/webview/webview_windows.hpp | 4 ++-- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/BuildTools/Targets/EvoBuildTarget.lua b/BuildTools/Targets/EvoBuildTarget.lua index cd21997d8..fce56402a 100644 --- a/BuildTools/Targets/EvoBuildTarget.lua +++ b/BuildTools/Targets/EvoBuildTarget.lua @@ -122,7 +122,6 @@ local EvoBuildTarget = { "deps/luvit/luv/deps/libuv/include", "deps/mariusbancila/stduuid/include", "deps/nothings/stb", - "deps/webview/webview", "deps/openssl/openssl/include", "deps/zhaog/lua-openssl/deps/auxiliar", "deps/zhaog/lua-openssl/src", @@ -133,6 +132,7 @@ local EvoBuildTarget = { "deps/xpol/lua-rapidjson/rapidjson/include", "deps/mikke89/RmlUi/Backends", "deps/mikke89/RmlUi/Include", + "deps/webview/webview/core/include", }, staticLibraries = { "libluajit.a", diff --git a/Runtime/Bindings/FFI/webview/webview_ffi.cpp b/Runtime/Bindings/FFI/webview/webview_ffi.cpp index 8a0522116..799776525 100644 --- a/Runtime/Bindings/FFI/webview/webview_ffi.cpp +++ b/Runtime/Bindings/FFI/webview/webview_ffi.cpp @@ -3,6 +3,15 @@ #include "webview.h" #include "webview_exports.h" +#include "webview_ffi.hpp" + +namespace webview_ffi { + // Note: This is an implementation detail and not part of the public API + auto unwrapResult(auto result) { + result.ensure_ok(); + return result.value(); + } +} #ifdef __unix__ #include "webview_unix.hpp" @@ -27,7 +36,7 @@ namespace webview_ffi { webview_t webview_create(bool debug, void* wnd) { auto w = new WebviewBrowserEngine(debug, wnd); - if(!w->window()) { + if(unwrapResult(w->window())) { delete w; return nullptr; } @@ -56,7 +65,7 @@ namespace webview_ffi { } void* webview_get_window(webview_t w) { - return static_cast(w)->window(); + return unwrapResult(static_cast(w)->window()); } void webview_set_title(webview_t w, const char* title) { diff --git a/Runtime/Bindings/FFI/webview/webview_mac.hpp b/Runtime/Bindings/FFI/webview/webview_mac.hpp index 641a46f8a..d27a2c71b 100644 --- a/Runtime/Bindings/FFI/webview/webview_mac.hpp +++ b/Runtime/Bindings/FFI/webview/webview_mac.hpp @@ -41,7 +41,7 @@ namespace webview_ffi { } void toggleFullScreen() { - id nsWindow = (id)window(); + id nsWindow = (id)unwrapResult(window()); ((void (*)(id, SEL, id))objc_msgSend)(nsWindow, sel_registerName("toggleFullScreen:"), nullptr); } @@ -54,7 +54,7 @@ namespace webview_ffi { if(!iconImage) return false; // 10.13 and earlier: Set icon in the window's title bar (now deprecated) - id nsWindow = (id)window(); + id nsWindow = (id)unwrapResult(window()); if(nsWindow) { id fileURL = ((id(*)(id, SEL, id))objc_msgSend)("NSURL"_cls, "fileURLWithPath:"_sel, iconImagePath); ((void (*)(id, SEL, id))objc_msgSend)(nsWindow, "setRepresentedURL:"_sel, fileURL); diff --git a/Runtime/Bindings/FFI/webview/webview_unix.hpp b/Runtime/Bindings/FFI/webview/webview_unix.hpp index f86587f2c..3af52a224 100644 --- a/Runtime/Bindings/FFI/webview/webview_unix.hpp +++ b/Runtime/Bindings/FFI/webview/webview_unix.hpp @@ -12,7 +12,7 @@ namespace webview_ffi { } void toggleFullScreen() { - GtkWindow* gtkWindow = GTK_WINDOW(window()); + GtkWindow* gtkWindow = GTK_WINDOW(unwrapResult(window())); GdkWindow* gdkWindow = gtk_widget_get_window(GTK_WIDGET(gtkWindow)); GdkWindowState state = gdk_window_get_state(gdkWindow); @@ -25,7 +25,7 @@ namespace webview_ffi { GdkPixbuf* pixelBuffer = gdk_pixbuf_new_from_file(iconPath, &error); if(pixelBuffer != NULL) { - gtk_window_set_icon(GTK_WINDOW(window()), pixelBuffer); + gtk_window_set_icon(GTK_WINDOW(unwrapResult(window())), pixelBuffer); g_object_unref(pixelBuffer); return true; } else { diff --git a/Runtime/Bindings/FFI/webview/webview_windows.hpp b/Runtime/Bindings/FFI/webview/webview_windows.hpp index c588c1cc2..9864ba9d1 100644 --- a/Runtime/Bindings/FFI/webview/webview_windows.hpp +++ b/Runtime/Bindings/FFI/webview/webview_windows.hpp @@ -38,7 +38,7 @@ namespace webview_ffi { } void toggleFullScreen() { - HWND nativeWindowHandle = (HWND)window(); + HWND nativeWindowHandle = (HWND)unwrapResult(window()); DWORD windowStyle = GetWindowLong(nativeWindowHandle, GWL_STYLE); bool isInWindowedMode = (windowStyle & WS_OVERLAPPEDWINDOW); @@ -47,7 +47,7 @@ namespace webview_ffi { } bool setAppIcon(const char* iconPath) { - HWND nativeWindowHandle = (HWND)window(); + HWND nativeWindowHandle = (HWND)unwrapResult(window()); HICON icon = (HICON)LoadImage(nullptr, iconPath, IMAGE_ICON, 0, 0, LR_LOADFROMFILE); if(icon) { SendMessage(nativeWindowHandle, WM_SETICON, ICON_BIG, (LPARAM)icon); From fa317732fe7534750e40a4a9aa04e915271a9d37 Mon Sep 17 00:00:00 2001 From: RDW Date: Fri, 10 Jan 2025 04:25:12 +0100 Subject: [PATCH 3/4] Runtime: Update the webview C API return types Doesn't seem to make much of a difference in practice, but it might in the future enable better error handling. --- Runtime/Bindings/FFI/webview/webview.lua | 46 +++++++++++++------ .../Bindings/FFI/webview/webview_aliases.h | 22 ++++++++- .../Bindings/FFI/webview/webview_exports.h | 26 +++++------ Runtime/Bindings/FFI/webview/webview_ffi.cpp | 24 +++++----- 4 files changed, 79 insertions(+), 39 deletions(-) diff --git a/Runtime/Bindings/FFI/webview/webview.lua b/Runtime/Bindings/FFI/webview/webview.lua index 08b69b153..9ae1e7522 100644 --- a/Runtime/Bindings/FFI/webview/webview.lua +++ b/Runtime/Bindings/FFI/webview/webview.lua @@ -44,27 +44,47 @@ typedef struct { char pre_release[48]; char build_metadata[48]; } webview_version_info_t; + +typedef enum { + /// Missing dependency. + WEBVIEW_ERROR_MISSING_DEPENDENCY = -5, + /// Operation canceled. + WEBVIEW_ERROR_CANCELED = -4, + /// Invalid state detected. + WEBVIEW_ERROR_INVALID_STATE = -3, + /// One or more invalid arguments have been specified e.g. in a function call. + WEBVIEW_ERROR_INVALID_ARGUMENT = -2, + /// An unspecified error occurred. A more specific error code may be needed. + WEBVIEW_ERROR_UNSPECIFIED = -1, + /// OK/Success. Functions that return error codes will typically return this + /// to signify successful operations. + WEBVIEW_ERROR_OK = 0, + /// Signifies that something already exists. + WEBVIEW_ERROR_DUPLICATE = 1, + /// Signifies that something does not exist. + WEBVIEW_ERROR_NOT_FOUND = 2 +} webview_error_t; typedef void (*promise_function_t)(const char* seq, const char* req, void* arg); typedef void (*webview_dispatch_function_t)(webview_t w, void* arg); struct static_webview_exports_table { webview_t (*webview_create)(int debug, void* window); - void (*webview_destroy)(webview_t w); + webview_error_t (*webview_destroy)(webview_t w); void (*webview_toggle_fullscreen)(webview_t w); - void (*webview_run)(webview_t w); + webview_error_t (*webview_run)(webview_t w); int (*webview_run_once)(webview_t w, int blocking); - void (*webview_terminate)(webview_t w); - void (*webview_dispatch)(webview_t w, webview_dispatch_function_t fn, void* arg); + webview_error_t (*webview_terminate)(webview_t w); + webview_error_t (*webview_dispatch)(webview_t w, webview_dispatch_function_t fn, void* arg); void* (*webview_get_window)(webview_t w); - void (*webview_set_title)(webview_t w, const char* title); - void (*webview_set_size)(webview_t w, int width, int height, webview_hint_t hints); - void (*webview_navigate)(webview_t w, const char* url); - void (*webview_set_html)(webview_t w, const char* html); - void (*webview_init)(webview_t w, const char* js); - void (*webview_eval)(webview_t w, const char* js); - void (*webview_bind)(webview_t w, const char* name, promise_function_t fn, void* arg); - void (*webview_unbind)(webview_t w, const char* name); - void (*webview_return)(webview_t w, const char* seq, int status, const char* result); + webview_error_t (*webview_set_title)(webview_t w, const char* title); + webview_error_t (*webview_set_size)(webview_t w, int width, int height, webview_hint_t hints); + webview_error_t (*webview_navigate)(webview_t w, const char* url); + webview_error_t (*webview_set_html)(webview_t w, const char* html); + webview_error_t (*webview_init)(webview_t w, const char* js); + webview_error_t (*webview_eval)(webview_t w, const char* js); + webview_error_t (*webview_bind)(webview_t w, const char* name, promise_function_t fn, void* arg); + webview_error_t (*webview_unbind)(webview_t w, const char* name); + webview_error_t (*webview_return)(webview_t w, const char* seq, int status, const char* result); const webview_version_info_t* (*webview_version)(void); bool (*webview_set_icon)(webview_t w, const char* file_path); void* (*webview_get_native_handle)(webview_t w, webview_native_handle_kind_t kind); diff --git a/Runtime/Bindings/FFI/webview/webview_aliases.h b/Runtime/Bindings/FFI/webview/webview_aliases.h index 0323c588a..091078215 100644 --- a/Runtime/Bindings/FFI/webview/webview_aliases.h +++ b/Runtime/Bindings/FFI/webview/webview_aliases.h @@ -38,4 +38,24 @@ typedef struct { char version_number[32]; char pre_release[48]; char build_metadata[48]; -} webview_version_info_t; \ No newline at end of file +} webview_version_info_t; + +typedef enum { + /// Missing dependency. + WEBVIEW_ERROR_MISSING_DEPENDENCY = -5, + /// Operation canceled. + WEBVIEW_ERROR_CANCELED = -4, + /// Invalid state detected. + WEBVIEW_ERROR_INVALID_STATE = -3, + /// One or more invalid arguments have been specified e.g. in a function call. + WEBVIEW_ERROR_INVALID_ARGUMENT = -2, + /// An unspecified error occurred. A more specific error code may be needed. + WEBVIEW_ERROR_UNSPECIFIED = -1, + /// OK/Success. Functions that return error codes will typically return this + /// to signify successful operations. + WEBVIEW_ERROR_OK = 0, + /// Signifies that something already exists. + WEBVIEW_ERROR_DUPLICATE = 1, + /// Signifies that something does not exist. + WEBVIEW_ERROR_NOT_FOUND = 2 +} webview_error_t; \ No newline at end of file diff --git a/Runtime/Bindings/FFI/webview/webview_exports.h b/Runtime/Bindings/FFI/webview/webview_exports.h index 492154979..87fe0d267 100644 --- a/Runtime/Bindings/FFI/webview/webview_exports.h +++ b/Runtime/Bindings/FFI/webview/webview_exports.h @@ -3,22 +3,22 @@ typedef void (*webview_dispatch_function_t)(webview_t w, void* arg); struct static_webview_exports_table { webview_t (*webview_create)(int debug, void* window); - void (*webview_destroy)(webview_t w); + webview_error_t (*webview_destroy)(webview_t w); void (*webview_toggle_fullscreen)(webview_t w); - void (*webview_run)(webview_t w); + webview_error_t (*webview_run)(webview_t w); int (*webview_run_once)(webview_t w, int blocking); - void (*webview_terminate)(webview_t w); - void (*webview_dispatch)(webview_t w, webview_dispatch_function_t fn, void* arg); + webview_error_t (*webview_terminate)(webview_t w); + webview_error_t (*webview_dispatch)(webview_t w, webview_dispatch_function_t fn, void* arg); void* (*webview_get_window)(webview_t w); - void (*webview_set_title)(webview_t w, const char* title); - void (*webview_set_size)(webview_t w, int width, int height, webview_hint_t hints); - void (*webview_navigate)(webview_t w, const char* url); - void (*webview_set_html)(webview_t w, const char* html); - void (*webview_init)(webview_t w, const char* js); - void (*webview_eval)(webview_t w, const char* js); - void (*webview_bind)(webview_t w, const char* name, promise_function_t fn, void* arg); - void (*webview_unbind)(webview_t w, const char* name); - void (*webview_return)(webview_t w, const char* seq, int status, const char* result); + webview_error_t (*webview_set_title)(webview_t w, const char* title); + webview_error_t (*webview_set_size)(webview_t w, int width, int height, webview_hint_t hints); + webview_error_t (*webview_navigate)(webview_t w, const char* url); + webview_error_t (*webview_set_html)(webview_t w, const char* html); + webview_error_t (*webview_init)(webview_t w, const char* js); + webview_error_t (*webview_eval)(webview_t w, const char* js); + webview_error_t (*webview_bind)(webview_t w, const char* name, promise_function_t fn, void* arg); + webview_error_t (*webview_unbind)(webview_t w, const char* name); + webview_error_t (*webview_return)(webview_t w, const char* seq, int status, const char* result); const webview_version_info_t* (*webview_version)(void); bool (*webview_set_icon)(webview_t w, const char* file_path); void* (*webview_get_native_handle)(webview_t w, webview_native_handle_kind_t kind); diff --git a/Runtime/Bindings/FFI/webview/webview_ffi.cpp b/Runtime/Bindings/FFI/webview/webview_ffi.cpp index 799776525..332f01651 100644 --- a/Runtime/Bindings/FFI/webview/webview_ffi.cpp +++ b/Runtime/Bindings/FFI/webview/webview_ffi.cpp @@ -43,7 +43,7 @@ namespace webview_ffi { return w; } - void webview_destroy(webview_t w) { + webview_error_t webview_destroy(webview_t w) { delete static_cast(w); } @@ -51,11 +51,11 @@ namespace webview_ffi { static_cast(w)->toggleFullScreen(); } - void webview_run(webview_t w) { + webview_error_t webview_run(webview_t w) { static_cast(w)->run(); } - void webview_terminate(webview_t w) { + webview_error_t webview_terminate(webview_t w) { static_cast(w)->terminate(); } @@ -68,32 +68,32 @@ namespace webview_ffi { return unwrapResult(static_cast(w)->window()); } - void webview_set_title(webview_t w, const char* title) { + webview_error_t webview_set_title(webview_t w, const char* title) { static_cast(w)->set_title(title); } - void webview_set_size(webview_t w, int width, int height, + webview_error_t webview_set_size(webview_t w, int width, int height, webview_hint_t hints) { static_cast(w)->set_size(width, height, hints); } - void webview_navigate(webview_t w, const char* url) { + webview_error_t webview_navigate(webview_t w, const char* url) { static_cast(w)->navigate(url); } - void webview_set_html(webview_t w, const char* html) { + webview_error_t webview_set_html(webview_t w, const char* html) { static_cast(w)->set_html(html); } - void webview_init(webview_t w, const char* js) { + webview_error_t webview_init(webview_t w, const char* js) { static_cast(w)->init(js); } - void webview_eval(webview_t w, const char* js) { + webview_error_t webview_eval(webview_t w, const char* js) { static_cast(w)->eval(js); } - void webview_bind(webview_t w, const char* name, + webview_error_t webview_bind(webview_t w, const char* name, void (*fn)(const char* seq, const char* req, void* arg), void* arg) { @@ -105,11 +105,11 @@ namespace webview_ffi { arg); } - void webview_unbind(webview_t w, const char* name) { + webview_error_t webview_unbind(webview_t w, const char* name) { static_cast(w)->unbind(name); } - void webview_return(webview_t w, const char* seq, int status, + webview_error_t webview_return(webview_t w, const char* seq, int status, const char* result) { static_cast(w)->resolve(seq, status, result); } From c4316c6a8f7f5b00ad4a3336360ac7188a0ed4d6 Mon Sep 17 00:00:00 2001 From: RDW Date: Fri, 10 Jan 2025 04:49:42 +0100 Subject: [PATCH 4/4] Cleanup: Remove redundant webview C API wrappers What's the point of these? No matter, this doesn't seem useful and makes returning error types more cumbersome. --- Runtime/Bindings/FFI/webview/webview_ffi.cpp | 76 -------------------- 1 file changed, 76 deletions(-) diff --git a/Runtime/Bindings/FFI/webview/webview_ffi.cpp b/Runtime/Bindings/FFI/webview/webview_ffi.cpp index 332f01651..070fb1e88 100644 --- a/Runtime/Bindings/FFI/webview/webview_ffi.cpp +++ b/Runtime/Bindings/FFI/webview/webview_ffi.cpp @@ -34,86 +34,10 @@ namespace webview_ffi { return static_cast(w)->step(blocking); } - webview_t webview_create(bool debug, void* wnd) { - auto w = new WebviewBrowserEngine(debug, wnd); - if(unwrapResult(w->window())) { - delete w; - return nullptr; - } - return w; - } - - webview_error_t webview_destroy(webview_t w) { - delete static_cast(w); - } - void webview_toggle_fullscreen(webview_t w) { static_cast(w)->toggleFullScreen(); } - webview_error_t webview_run(webview_t w) { - static_cast(w)->run(); - } - - webview_error_t webview_terminate(webview_t w) { - static_cast(w)->terminate(); - } - - void webview_dispatch(webview_t w, void (*fn)(webview_t, void*), - void* arg) { - static_cast(w)->dispatch([=]() { fn(w, arg); }); - } - - void* webview_get_window(webview_t w) { - return unwrapResult(static_cast(w)->window()); - } - - webview_error_t webview_set_title(webview_t w, const char* title) { - static_cast(w)->set_title(title); - } - - webview_error_t webview_set_size(webview_t w, int width, int height, - webview_hint_t hints) { - static_cast(w)->set_size(width, height, hints); - } - - webview_error_t webview_navigate(webview_t w, const char* url) { - static_cast(w)->navigate(url); - } - - webview_error_t webview_set_html(webview_t w, const char* html) { - static_cast(w)->set_html(html); - } - - webview_error_t webview_init(webview_t w, const char* js) { - static_cast(w)->init(js); - } - - webview_error_t webview_eval(webview_t w, const char* js) { - static_cast(w)->eval(js); - } - - webview_error_t webview_bind(webview_t w, const char* name, - void (*fn)(const char* seq, const char* req, - void* arg), - void* arg) { - static_cast(w)->bind( - name, - [=](const std::string& seq, const std::string& req, void* arg) { - fn(seq.c_str(), req.c_str(), arg); - }, - arg); - } - - webview_error_t webview_unbind(webview_t w, const char* name) { - static_cast(w)->unbind(name); - } - - webview_error_t webview_return(webview_t w, const char* seq, int status, - const char* result) { - static_cast(w)->resolve(seq, status, result); - } - bool webview_set_icon(webview_t w, const char* file_path) { return static_cast(w)->setAppIcon(file_path); }