Skip to content

Commit

Permalink
Merge pull request #636 from evo-lua/webview-update-latest
Browse files Browse the repository at this point in the history
Update webview to the latest HEAD
  • Loading branch information
rdw-software authored Jan 10, 2025
2 parents d9cb11e + c4316c6 commit f0d0612
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 111 deletions.
2 changes: 1 addition & 1 deletion BuildTools/Targets/EvoBuildTarget.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
46 changes: 33 additions & 13 deletions Runtime/Bindings/FFI/webview/webview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 21 additions & 1 deletion Runtime/Bindings/FFI/webview/webview_aliases.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,24 @@ typedef struct {
char version_number[32];
char pre_release[48];
char build_metadata[48];
} webview_version_info_t;
} 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;
26 changes: 13 additions & 13 deletions Runtime/Bindings/FFI/webview/webview_exports.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
85 changes: 9 additions & 76 deletions Runtime/Bindings/FFI/webview/webview_ffi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -25,86 +34,10 @@ namespace webview_ffi {
return static_cast<WebviewBrowserEngine*>(w)->step(blocking);
}

webview_t webview_create(bool debug, void* wnd) {
auto w = new WebviewBrowserEngine(debug, wnd);
if(!w->window()) {
delete w;
return nullptr;
}
return w;
}

void webview_destroy(webview_t w) {
delete static_cast<WebviewBrowserEngine*>(w);
}

void webview_toggle_fullscreen(webview_t w) {
static_cast<WebviewBrowserEngine*>(w)->toggleFullScreen();
}

void webview_run(webview_t w) {
static_cast<WebviewBrowserEngine*>(w)->run();
}

void webview_terminate(webview_t w) {
static_cast<WebviewBrowserEngine*>(w)->terminate();
}

void webview_dispatch(webview_t w, void (*fn)(webview_t, void*),
void* arg) {
static_cast<WebviewBrowserEngine*>(w)->dispatch([=]() { fn(w, arg); });
}

void* webview_get_window(webview_t w) {
return static_cast<WebviewBrowserEngine*>(w)->window();
}

void webview_set_title(webview_t w, const char* title) {
static_cast<WebviewBrowserEngine*>(w)->set_title(title);
}

void webview_set_size(webview_t w, int width, int height,
webview_hint_t hints) {
static_cast<WebviewBrowserEngine*>(w)->set_size(width, height, hints);
}

void webview_navigate(webview_t w, const char* url) {
static_cast<WebviewBrowserEngine*>(w)->navigate(url);
}

void webview_set_html(webview_t w, const char* html) {
static_cast<WebviewBrowserEngine*>(w)->set_html(html);
}

void webview_init(webview_t w, const char* js) {
static_cast<WebviewBrowserEngine*>(w)->init(js);
}

void webview_eval(webview_t w, const char* js) {
static_cast<WebviewBrowserEngine*>(w)->eval(js);
}

void webview_bind(webview_t w, const char* name,
void (*fn)(const char* seq, const char* req,
void* arg),
void* arg) {
static_cast<WebviewBrowserEngine*>(w)->bind(
name,
[=](const std::string& seq, const std::string& req, void* arg) {
fn(seq.c_str(), req.c_str(), arg);
},
arg);
}

void webview_unbind(webview_t w, const char* name) {
static_cast<WebviewBrowserEngine*>(w)->unbind(name);
}

void webview_return(webview_t w, const char* seq, int status,
const char* result) {
static_cast<WebviewBrowserEngine*>(w)->resolve(seq, status, result);
}

bool webview_set_icon(webview_t w, const char* file_path) {
return static_cast<WebviewBrowserEngine*>(w)->setAppIcon(file_path);
}
Expand Down
4 changes: 2 additions & 2 deletions Runtime/Bindings/FFI/webview/webview_mac.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions Runtime/Bindings/FFI/webview/webview_unix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions Runtime/Bindings/FFI/webview/webview_windows.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion deps/webview/webview
Submodule webview updated 110 files

0 comments on commit f0d0612

Please sign in to comment.