mirror of
https://github.com/webui-dev/webui.git
synced 2024-09-11 14:06:09 +03:00
Event Struct Improvement
* In webui_event_t `type` changed to `event_type`. This is because some wrapper's language does not support using _type_ as a variable name. * In webui_event_t `char* response` changed to `unsigned int event_number`. * Now `webui_interface_set_response()` use a simple `unsigned int event_number` instead of `char* response`.
This commit is contained in:
parent
93f815422b
commit
866796c8d2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -52,7 +52,9 @@
|
||||
#include <direct.h>
|
||||
#include <io.h>
|
||||
#include <tchar.h>
|
||||
#include <tlhelp32.h>
|
||||
#ifndef WEBUI_NO_TLHELPER32
|
||||
#include <tlhelp32.h>
|
||||
#endif
|
||||
#define WEBUI_GET_CURRENT_DIR _getcwd
|
||||
#define WEBUI_FILE_EXIST _access
|
||||
#define WEBUI_POPEN _popen
|
||||
@ -131,10 +133,10 @@ enum webui_events {
|
||||
// -- Structs -------------------------
|
||||
typedef struct webui_event_t {
|
||||
void* window; // Pointer to the window object
|
||||
unsigned int type; // Event type
|
||||
char* element; // HTML element ID
|
||||
unsigned int event_type; // Event type
|
||||
char* element; // HTML element ID
|
||||
char* data; // JavaScript data
|
||||
char* response; // Callback response
|
||||
unsigned int event_number; // Internal WebUI
|
||||
} webui_event_t;
|
||||
|
||||
// -- Definitions ---------------------
|
||||
@ -159,7 +161,7 @@ WEBUI_EXPORT bool webui_is_shown(void* window);
|
||||
// Set the maximum time in seconds to wait for browser to start
|
||||
WEBUI_EXPORT void webui_set_timeout(unsigned int second);
|
||||
// Set the default embedded HTML favicon
|
||||
WEBUI_EXPORT void webui_set_icon(void* window, const char* icon, const char* type);
|
||||
WEBUI_EXPORT void webui_set_icon(void* window, const char* icon, const char* icon_type);
|
||||
// Allow the window URL to be re-used in normal web browsers
|
||||
WEBUI_EXPORT void webui_set_multi_access(void* window, bool status);
|
||||
|
||||
@ -184,10 +186,10 @@ WEBUI_EXPORT void webui_return_string(webui_event_t* e, char* s);
|
||||
WEBUI_EXPORT void webui_return_bool(webui_event_t* e, bool b);
|
||||
|
||||
// -- Interface -----------------------
|
||||
// Bind a specific html element click event with a function. Empty element means all events. This replace webui_bind(). The func is (Window, EventType, Element, Data, Response)
|
||||
WEBUI_EXPORT unsigned int webui_interface_bind(void* window, const char* element, void (*func)(void*, unsigned int, char*, char*, char*));
|
||||
// When using `webui_interface_bind()` you need this function to easily set your callback response.
|
||||
WEBUI_EXPORT void webui_interface_set_response(char* ptr, const char* response);
|
||||
// Bind a specific html element click event with a function. Empty element means all events. This replace webui_bind(). The func is (Window, EventType, Element, Data, EventNumber)
|
||||
WEBUI_EXPORT unsigned int webui_interface_bind(void* window, const char* element, void (*func)(void*, unsigned int, char*, char*, unsigned int));
|
||||
// When using `webui_interface_bind()` you may need this function to easily set your callback response.
|
||||
WEBUI_EXPORT void webui_interface_set_response(void* window, unsigned int event_number, const char* response);
|
||||
// Check if the app still running or not. This replace webui_wait().
|
||||
WEBUI_EXPORT bool webui_interface_is_app_running(void);
|
||||
// Get window unique ID
|
||||
|
148
Release/Linux/include/webui.hpp
Normal file
148
Release/Linux/include/webui.hpp
Normal file
@ -0,0 +1,148 @@
|
||||
/*
|
||||
WebUI Library 2.2.0
|
||||
http://webui.me
|
||||
https://github.com/alifcommunity/webui
|
||||
Copyright (c) 2020-2023 Hassan Draga.
|
||||
Licensed under GNU General Public License v2.0.
|
||||
All rights reserved.
|
||||
Canada.
|
||||
*/
|
||||
|
||||
#ifndef _WEBUI_HPP
|
||||
#define _WEBUI_HPP
|
||||
|
||||
// C++ STD
|
||||
#include <string>
|
||||
|
||||
// WebUI C Header
|
||||
extern "C" {
|
||||
#include "webui.h"
|
||||
}
|
||||
|
||||
namespace webui {
|
||||
|
||||
// Create a new webui window object.
|
||||
void* new_window(void) {
|
||||
return webui_new_window();
|
||||
}
|
||||
|
||||
// Bind a specific html element click event with a function. Empty element means all events.
|
||||
unsigned int bind(void* window, std::string element, void (*func)(webui_event_t* e)) {
|
||||
return webui_bind(window, element.c_str(), func);
|
||||
}
|
||||
|
||||
// Show a window using a embedded HTML, or a file. If the window is already opened then it will be refreshed.
|
||||
bool show(void* window, std::string content) {
|
||||
return webui_show(window, content.c_str());
|
||||
}
|
||||
|
||||
// Same as show(). But with a specific web browser.
|
||||
bool show_browser(void* window, std::string content, unsigned int browser) {
|
||||
return webui_show_browser(window, content.c_str(), browser);
|
||||
}
|
||||
|
||||
// Wait until all opened windows get closed.
|
||||
void wait(void) {
|
||||
webui_wait();
|
||||
}
|
||||
|
||||
// Close a specific window.
|
||||
void close(void* window) {
|
||||
webui_close(window);
|
||||
}
|
||||
|
||||
// Close all opened windows. wait() will break.
|
||||
void exit(void) {
|
||||
webui_exit();
|
||||
}
|
||||
|
||||
// -- Other ---------------------------
|
||||
// Check a specific window if it's still running
|
||||
bool is_shown(void* window) {
|
||||
return webui_is_shown(window);
|
||||
}
|
||||
|
||||
// Set the maximum time in seconds to wait for browser to start
|
||||
void set_timeout(unsigned int second) {
|
||||
webui_set_timeout(second);
|
||||
}
|
||||
|
||||
// Set the default embedded HTML favicon
|
||||
void set_icon(void* window, std::string icon, std::string icon_type) {
|
||||
webui_set_icon(window, icon.c_str(), icon_type.c_str());
|
||||
}
|
||||
|
||||
// Allow the window URL to be re-used in normal web browsers
|
||||
void set_multi_access(void* window, bool status) {
|
||||
webui_set_multi_access(window, status);
|
||||
}
|
||||
|
||||
// -- JavaScript ----------------------
|
||||
// Quickly run a JavaScript (no response waiting).
|
||||
bool run(void* window, std::string script) {
|
||||
return webui_run(window, script.c_str());
|
||||
}
|
||||
|
||||
// Run a JavaScript, and get the response back (Make sure your local buffer can hold the response).
|
||||
bool script(void* window, std::string script, unsigned int timeout, char* buffer, size_t buffer_length) {
|
||||
return webui_script(window, script.c_str(), timeout, buffer, buffer_length);
|
||||
}
|
||||
|
||||
// Chose between Deno and Nodejs runtime for .js and .ts files.
|
||||
void set_runtime(void* window, unsigned int runtime) {
|
||||
webui_set_runtime(window, runtime);
|
||||
}
|
||||
|
||||
// Parse argument as integer.
|
||||
long long int get_int(webui_event_t* e) {
|
||||
return webui_get_int(e);
|
||||
}
|
||||
|
||||
// Parse argument as string.
|
||||
std::string get_string(webui_event_t* e) {
|
||||
return std::string(webui_get_string(e));
|
||||
}
|
||||
|
||||
// Parse argument as boolean.
|
||||
bool get_bool(webui_event_t* e) {
|
||||
return webui_get_bool(e);
|
||||
}
|
||||
|
||||
// Return the response to JavaScript as integer.
|
||||
void return_int(webui_event_t* e, long long int n) {
|
||||
webui_return_int(e, n);
|
||||
}
|
||||
|
||||
// Return the response to JavaScript as string.
|
||||
void return_string(webui_event_t* e, std::string s) {
|
||||
webui_return_string(e, &s[0]);
|
||||
}
|
||||
|
||||
// Return the response to JavaScript as boolean.
|
||||
void return_bool(webui_event_t* e, bool b) {
|
||||
webui_return_bool(e, b);
|
||||
}
|
||||
|
||||
// -- Interface -----------------------
|
||||
// Bind a specific html element click event with a function. Empty element means all events. This replace bind(). The func is (Window, EventType, Element, Data, Response)
|
||||
unsigned int interface_bind(void* window, std::string element, void (*func)(void*, unsigned int, char*, char*, unsigned int)) {
|
||||
return webui_interface_bind(window, element.c_str(), func);
|
||||
}
|
||||
|
||||
// When using `interface_bind()` you need this function to easily set your callback response.
|
||||
void interface_set_response(void *window, webui_event_t* e, std::string response) {
|
||||
webui_interface_set_response(window, e->event_number, response.c_str());
|
||||
}
|
||||
|
||||
// Check if the app still running or not. This replace wait().
|
||||
bool interface_is_app_running(void) {
|
||||
return webui_interface_is_app_running();
|
||||
}
|
||||
|
||||
// Get window unique ID
|
||||
unsigned int interface_get_window_id(void* window) {
|
||||
return webui_interface_get_window_id(window);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* _WEBUI_HPP */
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -133,10 +133,10 @@ enum webui_events {
|
||||
// -- Structs -------------------------
|
||||
typedef struct webui_event_t {
|
||||
void* window; // Pointer to the window object
|
||||
unsigned int type; // Event type
|
||||
char* element; // HTML element ID
|
||||
unsigned int event_type; // Event type
|
||||
char* element; // HTML element ID
|
||||
char* data; // JavaScript data
|
||||
char* response; // Callback response
|
||||
unsigned int event_number; // Internal WebUI
|
||||
} webui_event_t;
|
||||
|
||||
// -- Definitions ---------------------
|
||||
@ -161,7 +161,7 @@ WEBUI_EXPORT bool webui_is_shown(void* window);
|
||||
// Set the maximum time in seconds to wait for browser to start
|
||||
WEBUI_EXPORT void webui_set_timeout(unsigned int second);
|
||||
// Set the default embedded HTML favicon
|
||||
WEBUI_EXPORT void webui_set_icon(void* window, const char* icon, const char* type);
|
||||
WEBUI_EXPORT void webui_set_icon(void* window, const char* icon, const char* icon_type);
|
||||
// Allow the window URL to be re-used in normal web browsers
|
||||
WEBUI_EXPORT void webui_set_multi_access(void* window, bool status);
|
||||
|
||||
@ -186,10 +186,10 @@ WEBUI_EXPORT void webui_return_string(webui_event_t* e, char* s);
|
||||
WEBUI_EXPORT void webui_return_bool(webui_event_t* e, bool b);
|
||||
|
||||
// -- Interface -----------------------
|
||||
// Bind a specific html element click event with a function. Empty element means all events. This replace webui_bind(). The func is (Window, EventType, Element, Data, Response)
|
||||
WEBUI_EXPORT unsigned int webui_interface_bind(void* window, const char* element, void (*func)(void*, unsigned int, char*, char*, char*));
|
||||
// When using `webui_interface_bind()` you need this function to easily set your callback response.
|
||||
WEBUI_EXPORT void webui_interface_set_response(char* ptr, const char* response);
|
||||
// Bind a specific html element click event with a function. Empty element means all events. This replace webui_bind(). The func is (Window, EventType, Element, Data, EventNumber)
|
||||
WEBUI_EXPORT unsigned int webui_interface_bind(void* window, const char* element, void (*func)(void*, unsigned int, char*, char*, unsigned int));
|
||||
// When using `webui_interface_bind()` you may need this function to easily set your callback response.
|
||||
WEBUI_EXPORT void webui_interface_set_response(void* window, unsigned int event_number, const char* response);
|
||||
// Check if the app still running or not. This replace webui_wait().
|
||||
WEBUI_EXPORT bool webui_interface_is_app_running(void);
|
||||
// Get window unique ID
|
||||
|
Binary file not shown.
Binary file not shown.
@ -52,7 +52,9 @@
|
||||
#include <direct.h>
|
||||
#include <io.h>
|
||||
#include <tchar.h>
|
||||
#include <tlhelp32.h>
|
||||
#ifndef WEBUI_NO_TLHELPER32
|
||||
#include <tlhelp32.h>
|
||||
#endif
|
||||
#define WEBUI_GET_CURRENT_DIR _getcwd
|
||||
#define WEBUI_FILE_EXIST _access
|
||||
#define WEBUI_POPEN _popen
|
||||
@ -131,10 +133,10 @@ enum webui_events {
|
||||
// -- Structs -------------------------
|
||||
typedef struct webui_event_t {
|
||||
void* window; // Pointer to the window object
|
||||
unsigned int type; // Event type
|
||||
char* element; // HTML element ID
|
||||
unsigned int event_type; // Event type
|
||||
char* element; // HTML element ID
|
||||
char* data; // JavaScript data
|
||||
char* response; // Callback response
|
||||
unsigned int event_number; // Internal WebUI
|
||||
} webui_event_t;
|
||||
|
||||
// -- Definitions ---------------------
|
||||
@ -159,7 +161,7 @@ WEBUI_EXPORT bool webui_is_shown(void* window);
|
||||
// Set the maximum time in seconds to wait for browser to start
|
||||
WEBUI_EXPORT void webui_set_timeout(unsigned int second);
|
||||
// Set the default embedded HTML favicon
|
||||
WEBUI_EXPORT void webui_set_icon(void* window, const char* icon, const char* type);
|
||||
WEBUI_EXPORT void webui_set_icon(void* window, const char* icon, const char* icon_type);
|
||||
// Allow the window URL to be re-used in normal web browsers
|
||||
WEBUI_EXPORT void webui_set_multi_access(void* window, bool status);
|
||||
|
||||
@ -184,10 +186,10 @@ WEBUI_EXPORT void webui_return_string(webui_event_t* e, char* s);
|
||||
WEBUI_EXPORT void webui_return_bool(webui_event_t* e, bool b);
|
||||
|
||||
// -- Interface -----------------------
|
||||
// Bind a specific html element click event with a function. Empty element means all events. This replace webui_bind(). The func is (Window, EventType, Element, Data, Response)
|
||||
WEBUI_EXPORT unsigned int webui_interface_bind(void* window, const char* element, void (*func)(void*, unsigned int, char*, char*, char*));
|
||||
// When using `webui_interface_bind()` you need this function to easily set your callback response.
|
||||
WEBUI_EXPORT void webui_interface_set_response(char* ptr, const char* response);
|
||||
// Bind a specific html element click event with a function. Empty element means all events. This replace webui_bind(). The func is (Window, EventType, Element, Data, EventNumber)
|
||||
WEBUI_EXPORT unsigned int webui_interface_bind(void* window, const char* element, void (*func)(void*, unsigned int, char*, char*, unsigned int));
|
||||
// When using `webui_interface_bind()` you may need this function to easily set your callback response.
|
||||
WEBUI_EXPORT void webui_interface_set_response(void* window, unsigned int event_number, const char* response);
|
||||
// Check if the app still running or not. This replace webui_wait().
|
||||
WEBUI_EXPORT bool webui_interface_is_app_running(void);
|
||||
// Get window unique ID
|
||||
|
148
Release/macOS/include/webui.hpp
Normal file
148
Release/macOS/include/webui.hpp
Normal file
@ -0,0 +1,148 @@
|
||||
/*
|
||||
WebUI Library 2.2.0
|
||||
http://webui.me
|
||||
https://github.com/alifcommunity/webui
|
||||
Copyright (c) 2020-2023 Hassan Draga.
|
||||
Licensed under GNU General Public License v2.0.
|
||||
All rights reserved.
|
||||
Canada.
|
||||
*/
|
||||
|
||||
#ifndef _WEBUI_HPP
|
||||
#define _WEBUI_HPP
|
||||
|
||||
// C++ STD
|
||||
#include <string>
|
||||
|
||||
// WebUI C Header
|
||||
extern "C" {
|
||||
#include "webui.h"
|
||||
}
|
||||
|
||||
namespace webui {
|
||||
|
||||
// Create a new webui window object.
|
||||
void* new_window(void) {
|
||||
return webui_new_window();
|
||||
}
|
||||
|
||||
// Bind a specific html element click event with a function. Empty element means all events.
|
||||
unsigned int bind(void* window, std::string element, void (*func)(webui_event_t* e)) {
|
||||
return webui_bind(window, element.c_str(), func);
|
||||
}
|
||||
|
||||
// Show a window using a embedded HTML, or a file. If the window is already opened then it will be refreshed.
|
||||
bool show(void* window, std::string content) {
|
||||
return webui_show(window, content.c_str());
|
||||
}
|
||||
|
||||
// Same as show(). But with a specific web browser.
|
||||
bool show_browser(void* window, std::string content, unsigned int browser) {
|
||||
return webui_show_browser(window, content.c_str(), browser);
|
||||
}
|
||||
|
||||
// Wait until all opened windows get closed.
|
||||
void wait(void) {
|
||||
webui_wait();
|
||||
}
|
||||
|
||||
// Close a specific window.
|
||||
void close(void* window) {
|
||||
webui_close(window);
|
||||
}
|
||||
|
||||
// Close all opened windows. wait() will break.
|
||||
void exit(void) {
|
||||
webui_exit();
|
||||
}
|
||||
|
||||
// -- Other ---------------------------
|
||||
// Check a specific window if it's still running
|
||||
bool is_shown(void* window) {
|
||||
return webui_is_shown(window);
|
||||
}
|
||||
|
||||
// Set the maximum time in seconds to wait for browser to start
|
||||
void set_timeout(unsigned int second) {
|
||||
webui_set_timeout(second);
|
||||
}
|
||||
|
||||
// Set the default embedded HTML favicon
|
||||
void set_icon(void* window, std::string icon, std::string icon_type) {
|
||||
webui_set_icon(window, icon.c_str(), icon_type.c_str());
|
||||
}
|
||||
|
||||
// Allow the window URL to be re-used in normal web browsers
|
||||
void set_multi_access(void* window, bool status) {
|
||||
webui_set_multi_access(window, status);
|
||||
}
|
||||
|
||||
// -- JavaScript ----------------------
|
||||
// Quickly run a JavaScript (no response waiting).
|
||||
bool run(void* window, std::string script) {
|
||||
return webui_run(window, script.c_str());
|
||||
}
|
||||
|
||||
// Run a JavaScript, and get the response back (Make sure your local buffer can hold the response).
|
||||
bool script(void* window, std::string script, unsigned int timeout, char* buffer, size_t buffer_length) {
|
||||
return webui_script(window, script.c_str(), timeout, buffer, buffer_length);
|
||||
}
|
||||
|
||||
// Chose between Deno and Nodejs runtime for .js and .ts files.
|
||||
void set_runtime(void* window, unsigned int runtime) {
|
||||
webui_set_runtime(window, runtime);
|
||||
}
|
||||
|
||||
// Parse argument as integer.
|
||||
long long int get_int(webui_event_t* e) {
|
||||
return webui_get_int(e);
|
||||
}
|
||||
|
||||
// Parse argument as string.
|
||||
std::string get_string(webui_event_t* e) {
|
||||
return std::string(webui_get_string(e));
|
||||
}
|
||||
|
||||
// Parse argument as boolean.
|
||||
bool get_bool(webui_event_t* e) {
|
||||
return webui_get_bool(e);
|
||||
}
|
||||
|
||||
// Return the response to JavaScript as integer.
|
||||
void return_int(webui_event_t* e, long long int n) {
|
||||
webui_return_int(e, n);
|
||||
}
|
||||
|
||||
// Return the response to JavaScript as string.
|
||||
void return_string(webui_event_t* e, std::string s) {
|
||||
webui_return_string(e, &s[0]);
|
||||
}
|
||||
|
||||
// Return the response to JavaScript as boolean.
|
||||
void return_bool(webui_event_t* e, bool b) {
|
||||
webui_return_bool(e, b);
|
||||
}
|
||||
|
||||
// -- Interface -----------------------
|
||||
// Bind a specific html element click event with a function. Empty element means all events. This replace bind(). The func is (Window, EventType, Element, Data, Response)
|
||||
unsigned int interface_bind(void* window, std::string element, void (*func)(void*, unsigned int, char*, char*, unsigned int)) {
|
||||
return webui_interface_bind(window, element.c_str(), func);
|
||||
}
|
||||
|
||||
// When using `interface_bind()` you need this function to easily set your callback response.
|
||||
void interface_set_response(void *window, webui_event_t* e, std::string response) {
|
||||
webui_interface_set_response(window, e->event_number, response.c_str());
|
||||
}
|
||||
|
||||
// Check if the app still running or not. This replace wait().
|
||||
bool interface_is_app_running(void) {
|
||||
return webui_interface_is_app_running();
|
||||
}
|
||||
|
||||
// Get window unique ID
|
||||
unsigned int interface_get_window_id(void* window) {
|
||||
return webui_interface_get_window_id(window);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* _WEBUI_HPP */
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -33,13 +33,13 @@ class MyClass {
|
||||
// it's get bind with an empty HTML ID.
|
||||
void events(webui_event_t* e) {
|
||||
|
||||
if (e->type == WEBUI_EVENT_CONNECTED)
|
||||
if (e->event_type == WEBUI_EVENT_CONNECTED)
|
||||
std::cout << "Window Connected." << std::endl;
|
||||
else if (e->type == WEBUI_EVENT_DISCONNECTED)
|
||||
else if (e->event_type == WEBUI_EVENT_DISCONNECTED)
|
||||
std::cout << "Window Disconnected." << std::endl;
|
||||
else if (e->type == WEBUI_EVENT_MOUSE_CLICK)
|
||||
else if (e->event_type == WEBUI_EVENT_MOUSE_CLICK)
|
||||
std::cout << "Click on element: " << e->element << std::endl;
|
||||
else if (e->type == WEBUI_EVENT_NAVIGATION)
|
||||
else if (e->event_type == WEBUI_EVENT_NAVIGATION)
|
||||
std::cout << "Starting navigation to: " << e->data << std::endl;
|
||||
}
|
||||
|
||||
|
Binary file not shown.
@ -133,10 +133,10 @@ enum webui_events {
|
||||
// -- Structs -------------------------
|
||||
typedef struct webui_event_t {
|
||||
void* window; // Pointer to the window object
|
||||
unsigned int type; // Event type
|
||||
char* element; // HTML element ID
|
||||
unsigned int event_type; // Event type
|
||||
char* element; // HTML element ID
|
||||
char* data; // JavaScript data
|
||||
char* response; // Callback response
|
||||
unsigned int event_number; // Internal WebUI
|
||||
} webui_event_t;
|
||||
|
||||
// -- Definitions ---------------------
|
||||
@ -161,7 +161,7 @@ WEBUI_EXPORT bool webui_is_shown(void* window);
|
||||
// Set the maximum time in seconds to wait for browser to start
|
||||
WEBUI_EXPORT void webui_set_timeout(unsigned int second);
|
||||
// Set the default embedded HTML favicon
|
||||
WEBUI_EXPORT void webui_set_icon(void* window, const char* icon, const char* type);
|
||||
WEBUI_EXPORT void webui_set_icon(void* window, const char* icon, const char* icon_type);
|
||||
// Allow the window URL to be re-used in normal web browsers
|
||||
WEBUI_EXPORT void webui_set_multi_access(void* window, bool status);
|
||||
|
||||
@ -186,10 +186,10 @@ WEBUI_EXPORT void webui_return_string(webui_event_t* e, char* s);
|
||||
WEBUI_EXPORT void webui_return_bool(webui_event_t* e, bool b);
|
||||
|
||||
// -- Interface -----------------------
|
||||
// Bind a specific html element click event with a function. Empty element means all events. This replace webui_bind(). The func is (Window, EventType, Element, Data, Response)
|
||||
WEBUI_EXPORT unsigned int webui_interface_bind(void* window, const char* element, void (*func)(void*, unsigned int, char*, char*, char*));
|
||||
// When using `webui_interface_bind()` you need this function to easily set your callback response.
|
||||
WEBUI_EXPORT void webui_interface_set_response(char* ptr, const char* response);
|
||||
// Bind a specific html element click event with a function. Empty element means all events. This replace webui_bind(). The func is (Window, EventType, Element, Data, EventNumber)
|
||||
WEBUI_EXPORT unsigned int webui_interface_bind(void* window, const char* element, void (*func)(void*, unsigned int, char*, char*, unsigned int));
|
||||
// When using `webui_interface_bind()` you may need this function to easily set your callback response.
|
||||
WEBUI_EXPORT void webui_interface_set_response(void* window, unsigned int event_number, const char* response);
|
||||
// Check if the app still running or not. This replace webui_wait().
|
||||
WEBUI_EXPORT bool webui_interface_is_app_running(void);
|
||||
// Get window unique ID
|
||||
|
@ -68,8 +68,8 @@ namespace webui {
|
||||
}
|
||||
|
||||
// Set the default embedded HTML favicon
|
||||
void set_icon(void* window, std::string icon, std::string type) {
|
||||
webui_set_icon(window, icon.c_str(), type.c_str());
|
||||
void set_icon(void* window, std::string icon, std::string icon_type) {
|
||||
webui_set_icon(window, icon.c_str(), icon_type.c_str());
|
||||
}
|
||||
|
||||
// Allow the window URL to be re-used in normal web browsers
|
||||
@ -125,13 +125,13 @@ namespace webui {
|
||||
|
||||
// -- Interface -----------------------
|
||||
// Bind a specific html element click event with a function. Empty element means all events. This replace bind(). The func is (Window, EventType, Element, Data, Response)
|
||||
unsigned int interface_bind(void* window, std::string element, void (*func)(void*, unsigned int, char*, char*, char*)) {
|
||||
unsigned int interface_bind(void* window, std::string element, void (*func)(void*, unsigned int, char*, char*, unsigned int)) {
|
||||
return webui_interface_bind(window, element.c_str(), func);
|
||||
}
|
||||
|
||||
// When using `interface_bind()` you need this function to easily set your callback response.
|
||||
void interface_set_response(std::string ptr, std::string response) {
|
||||
webui_interface_set_response(&ptr[0], response.c_str());
|
||||
void interface_set_response(void *window, webui_event_t* e, std::string response) {
|
||||
webui_interface_set_response(window, e->event_number, response.c_str());
|
||||
}
|
||||
|
||||
// Check if the app still running or not. This replace wait().
|
||||
|
@ -33,13 +33,13 @@ class MyClass {
|
||||
// it's get bind with an empty HTML ID.
|
||||
void events(webui_event_t* e) {
|
||||
|
||||
if (e->type == WEBUI_EVENT_CONNECTED)
|
||||
if (e->event_type == WEBUI_EVENT_CONNECTED)
|
||||
std::cout << "Window Connected." << std::endl;
|
||||
else if (e->type == WEBUI_EVENT_DISCONNECTED)
|
||||
else if (e->event_type == WEBUI_EVENT_DISCONNECTED)
|
||||
std::cout << "Window Disconnected." << std::endl;
|
||||
else if (e->type == WEBUI_EVENT_MOUSE_CLICK)
|
||||
else if (e->event_type == WEBUI_EVENT_MOUSE_CLICK)
|
||||
std::cout << "Click on element: " << e->element << std::endl;
|
||||
else if (e->type == WEBUI_EVENT_NAVIGATION)
|
||||
else if (e->event_type == WEBUI_EVENT_NAVIGATION)
|
||||
std::cout << "Starting navigation to: " << e->data << std::endl;
|
||||
}
|
||||
|
||||
|
Binary file not shown.
@ -133,10 +133,10 @@ enum webui_events {
|
||||
// -- Structs -------------------------
|
||||
typedef struct webui_event_t {
|
||||
void* window; // Pointer to the window object
|
||||
unsigned int type; // Event type
|
||||
char* element; // HTML element ID
|
||||
unsigned int event_type; // Event type
|
||||
char* element; // HTML element ID
|
||||
char* data; // JavaScript data
|
||||
char* response; // Callback response
|
||||
unsigned int event_number; // Internal WebUI
|
||||
} webui_event_t;
|
||||
|
||||
// -- Definitions ---------------------
|
||||
@ -161,7 +161,7 @@ WEBUI_EXPORT bool webui_is_shown(void* window);
|
||||
// Set the maximum time in seconds to wait for browser to start
|
||||
WEBUI_EXPORT void webui_set_timeout(unsigned int second);
|
||||
// Set the default embedded HTML favicon
|
||||
WEBUI_EXPORT void webui_set_icon(void* window, const char* icon, const char* type);
|
||||
WEBUI_EXPORT void webui_set_icon(void* window, const char* icon, const char* icon_type);
|
||||
// Allow the window URL to be re-used in normal web browsers
|
||||
WEBUI_EXPORT void webui_set_multi_access(void* window, bool status);
|
||||
|
||||
@ -186,10 +186,10 @@ WEBUI_EXPORT void webui_return_string(webui_event_t* e, char* s);
|
||||
WEBUI_EXPORT void webui_return_bool(webui_event_t* e, bool b);
|
||||
|
||||
// -- Interface -----------------------
|
||||
// Bind a specific html element click event with a function. Empty element means all events. This replace webui_bind(). The func is (Window, EventType, Element, Data, Response)
|
||||
WEBUI_EXPORT unsigned int webui_interface_bind(void* window, const char* element, void (*func)(void*, unsigned int, char*, char*, char*));
|
||||
// When using `webui_interface_bind()` you need this function to easily set your callback response.
|
||||
WEBUI_EXPORT void webui_interface_set_response(char* ptr, const char* response);
|
||||
// Bind a specific html element click event with a function. Empty element means all events. This replace webui_bind(). The func is (Window, EventType, Element, Data, EventNumber)
|
||||
WEBUI_EXPORT unsigned int webui_interface_bind(void* window, const char* element, void (*func)(void*, unsigned int, char*, char*, unsigned int));
|
||||
// When using `webui_interface_bind()` you may need this function to easily set your callback response.
|
||||
WEBUI_EXPORT void webui_interface_set_response(void* window, unsigned int event_number, const char* response);
|
||||
// Check if the app still running or not. This replace webui_wait().
|
||||
WEBUI_EXPORT bool webui_interface_is_app_running(void);
|
||||
// Get window unique ID
|
||||
|
@ -68,8 +68,8 @@ namespace webui {
|
||||
}
|
||||
|
||||
// Set the default embedded HTML favicon
|
||||
void set_icon(void* window, std::string icon, std::string type) {
|
||||
webui_set_icon(window, icon.c_str(), type.c_str());
|
||||
void set_icon(void* window, std::string icon, std::string icon_type) {
|
||||
webui_set_icon(window, icon.c_str(), icon_type.c_str());
|
||||
}
|
||||
|
||||
// Allow the window URL to be re-used in normal web browsers
|
||||
@ -125,13 +125,13 @@ namespace webui {
|
||||
|
||||
// -- Interface -----------------------
|
||||
// Bind a specific html element click event with a function. Empty element means all events. This replace bind(). The func is (Window, EventType, Element, Data, Response)
|
||||
unsigned int interface_bind(void* window, std::string element, void (*func)(void*, unsigned int, char*, char*, char*)) {
|
||||
unsigned int interface_bind(void* window, std::string element, void (*func)(void*, unsigned int, char*, char*, unsigned int)) {
|
||||
return webui_interface_bind(window, element.c_str(), func);
|
||||
}
|
||||
|
||||
// When using `interface_bind()` you need this function to easily set your callback response.
|
||||
void interface_set_response(std::string ptr, std::string response) {
|
||||
webui_interface_set_response(&ptr[0], response.c_str());
|
||||
void interface_set_response(void *window, webui_event_t* e, std::string response) {
|
||||
webui_interface_set_response(window, e->event_number, response.c_str());
|
||||
}
|
||||
|
||||
// Check if the app still running or not. This replace wait().
|
||||
|
Binary file not shown.
@ -68,8 +68,8 @@ namespace webui {
|
||||
}
|
||||
|
||||
// Set the default embedded HTML favicon
|
||||
void set_icon(void* window, std::string icon, std::string type) {
|
||||
webui_set_icon(window, icon.c_str(), type.c_str());
|
||||
void set_icon(void* window, std::string icon, std::string icon_type) {
|
||||
webui_set_icon(window, icon.c_str(), icon_type.c_str());
|
||||
}
|
||||
|
||||
// Allow the window URL to be re-used in normal web browsers
|
||||
@ -125,13 +125,13 @@ namespace webui {
|
||||
|
||||
// -- Interface -----------------------
|
||||
// Bind a specific html element click event with a function. Empty element means all events. This replace bind(). The func is (Window, EventType, Element, Data, Response)
|
||||
unsigned int interface_bind(void* window, std::string element, void (*func)(void*, unsigned int, char*, char*, char*)) {
|
||||
unsigned int interface_bind(void* window, std::string element, void (*func)(void*, unsigned int, char*, char*, unsigned int)) {
|
||||
return webui_interface_bind(window, element.c_str(), func);
|
||||
}
|
||||
|
||||
// When using `interface_bind()` you need this function to easily set your callback response.
|
||||
void interface_set_response(std::string ptr, std::string response) {
|
||||
webui_interface_set_response(&ptr[0], response.c_str());
|
||||
void interface_set_response(void *window, webui_event_t* e, std::string response) {
|
||||
webui_interface_set_response(window, e->event_number, response.c_str());
|
||||
}
|
||||
|
||||
// Check if the app still running or not. This replace wait().
|
||||
|
BIN
examples/C++/serve_a_folder/Windows/MSVC/main.lib
Normal file
BIN
examples/C++/serve_a_folder/Windows/MSVC/main.lib
Normal file
Binary file not shown.
@ -33,13 +33,13 @@ class MyClass {
|
||||
// it's get bind with an empty HTML ID.
|
||||
void events(webui_event_t* e) {
|
||||
|
||||
if (e->type == WEBUI_EVENT_CONNECTED)
|
||||
if (e->event_type == WEBUI_EVENT_CONNECTED)
|
||||
std::cout << "Window Connected." << std::endl;
|
||||
else if (e->type == WEBUI_EVENT_DISCONNECTED)
|
||||
else if (e->event_type == WEBUI_EVENT_DISCONNECTED)
|
||||
std::cout << "Window Disconnected." << std::endl;
|
||||
else if (e->type == WEBUI_EVENT_MOUSE_CLICK)
|
||||
else if (e->event_type == WEBUI_EVENT_MOUSE_CLICK)
|
||||
std::cout << "Click on element: " << e->element << std::endl;
|
||||
else if (e->type == WEBUI_EVENT_NAVIGATION)
|
||||
else if (e->event_type == WEBUI_EVENT_NAVIGATION)
|
||||
std::cout << "Starting navigation to: " << e->data << std::endl;
|
||||
}
|
||||
|
||||
|
BIN
examples/C/call_c_from_js/Windows/MSVC/main.lib
Normal file
BIN
examples/C/call_c_from_js/Windows/MSVC/main.lib
Normal file
Binary file not shown.
BIN
examples/C/minimal/Windows/MSVC/main.lib
Normal file
BIN
examples/C/minimal/Windows/MSVC/main.lib
Normal file
Binary file not shown.
BIN
examples/C/serve_a_folder/Windows/MSVC/main.lib
Normal file
BIN
examples/C/serve_a_folder/Windows/MSVC/main.lib
Normal file
Binary file not shown.
BIN
examples/C/serve_a_folder/macOS/Clang/main
Normal file
BIN
examples/C/serve_a_folder/macOS/Clang/main
Normal file
Binary file not shown.
BIN
examples/C/serve_a_folder/macOS/Clang/main-dyn
Normal file
BIN
examples/C/serve_a_folder/macOS/Clang/main-dyn
Normal file
Binary file not shown.
@ -16,13 +16,13 @@ void events(webui_event_t* e) {
|
||||
// This function gets called every time
|
||||
// there is an event
|
||||
|
||||
if(e->type == WEBUI_EVENT_CONNECTED)
|
||||
if(e->event_type == WEBUI_EVENT_CONNECTED)
|
||||
printf("Connected. \n");
|
||||
else if(e->type == WEBUI_EVENT_DISCONNECTED)
|
||||
else if(e->event_type == WEBUI_EVENT_DISCONNECTED)
|
||||
printf("Disconnected. \n");
|
||||
else if(e->type == WEBUI_EVENT_MOUSE_CLICK)
|
||||
else if(e->event_type == WEBUI_EVENT_MOUSE_CLICK)
|
||||
printf("Click. \n");
|
||||
else if(e->type == WEBUI_EVENT_NAVIGATION)
|
||||
else if(e->event_type == WEBUI_EVENT_NAVIGATION)
|
||||
printf("Starting navigation to: %s \n", (char *)e->data);
|
||||
}
|
||||
|
||||
|
Binary file not shown.
@ -16,9 +16,9 @@ package webui
|
||||
#cgo darwin LDFLAGS: -L ./ -lwebui-2-static-x64 -lpthread -lm
|
||||
#cgo linux LDFLAGS: -L ./ -lwebui-2-static-x64 -lpthread -lm
|
||||
#include <webui.h>
|
||||
extern void GoWebuiEvent(void* _window, unsigned int _event_type, char* _element, char* _data, char* _response);
|
||||
extern void GoWebuiEvent(void* _window, unsigned int _event_type, char* _element, char* _data, unsigned int _event_number);
|
||||
static void GoWebuiEvents_handler(webui_event_t* e) {
|
||||
GoWebuiEvent(e->window, e->type, e->element, e->data, (char*)&e->response);
|
||||
GoWebuiEvent(e->window, e->event_type, e->element, e->data, e->event_number);
|
||||
}
|
||||
static void go_webui_bind(void* win, const char* element) {
|
||||
webui_bind(win, element, GoWebuiEvents_handler);
|
||||
@ -92,7 +92,7 @@ func Ini() {
|
||||
// This function receives all events
|
||||
//
|
||||
//export GoWebuiEvent
|
||||
func GoWebuiEvent(window unsafe.Pointer, _event_type C.uint, _element *C.char, _data *C.char, _response *C.char) {
|
||||
func GoWebuiEvent(window unsafe.Pointer, _event_type C.uint, _element *C.char, _data *C.char, _event_number C.uint) {
|
||||
Ini()
|
||||
|
||||
// Create a new event struct
|
||||
@ -114,7 +114,7 @@ func GoWebuiEvent(window unsafe.Pointer, _event_type C.uint, _element *C.char, _
|
||||
// Set the response back
|
||||
if len(response) > 0 {
|
||||
c_response := C.CString(response)
|
||||
C.webui_interface_set_response(_response, c_response)
|
||||
C.webui_interface_set_response(window, _event_number, c_response)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,10 +133,10 @@ enum webui_events {
|
||||
// -- Structs -------------------------
|
||||
typedef struct webui_event_t {
|
||||
void* window; // Pointer to the window object
|
||||
unsigned int type; // Event type
|
||||
char* element; // HTML element ID
|
||||
unsigned int event_type; // Event type
|
||||
char* element; // HTML element ID
|
||||
char* data; // JavaScript data
|
||||
char* response; // Callback response
|
||||
unsigned int event_number; // Internal WebUI
|
||||
} webui_event_t;
|
||||
|
||||
// -- Definitions ---------------------
|
||||
@ -161,7 +161,7 @@ WEBUI_EXPORT bool webui_is_shown(void* window);
|
||||
// Set the maximum time in seconds to wait for browser to start
|
||||
WEBUI_EXPORT void webui_set_timeout(unsigned int second);
|
||||
// Set the default embedded HTML favicon
|
||||
WEBUI_EXPORT void webui_set_icon(void* window, const char* icon, const char* type);
|
||||
WEBUI_EXPORT void webui_set_icon(void* window, const char* icon, const char* icon_type);
|
||||
// Allow the window URL to be re-used in normal web browsers
|
||||
WEBUI_EXPORT void webui_set_multi_access(void* window, bool status);
|
||||
|
||||
@ -186,10 +186,10 @@ WEBUI_EXPORT void webui_return_string(webui_event_t* e, char* s);
|
||||
WEBUI_EXPORT void webui_return_bool(webui_event_t* e, bool b);
|
||||
|
||||
// -- Interface -----------------------
|
||||
// Bind a specific html element click event with a function. Empty element means all events. This replace webui_bind(). The func is (Window, EventType, Element, Data, Response)
|
||||
WEBUI_EXPORT unsigned int webui_interface_bind(void* window, const char* element, void (*func)(void*, unsigned int, char*, char*, char*));
|
||||
// When using `webui_interface_bind()` you need this function to easily set your callback response.
|
||||
WEBUI_EXPORT void webui_interface_set_response(char* ptr, const char* response);
|
||||
// Bind a specific html element click event with a function. Empty element means all events. This replace webui_bind(). The func is (Window, EventType, Element, Data, EventNumber)
|
||||
WEBUI_EXPORT unsigned int webui_interface_bind(void* window, const char* element, void (*func)(void*, unsigned int, char*, char*, unsigned int));
|
||||
// When using `webui_interface_bind()` you may need this function to easily set your callback response.
|
||||
WEBUI_EXPORT void webui_interface_set_response(void* window, unsigned int event_number, const char* response);
|
||||
// Check if the app still running or not. This replace webui_wait().
|
||||
WEBUI_EXPORT bool webui_interface_is_app_running(void);
|
||||
// Get window unique ID
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -40,7 +40,7 @@ class browser:
|
||||
# event
|
||||
class event:
|
||||
window = None
|
||||
type = 0
|
||||
event_type = 0
|
||||
element = ""
|
||||
data = ""
|
||||
|
||||
@ -91,10 +91,10 @@ class window:
|
||||
py_fun = ctypes.CFUNCTYPE(
|
||||
ctypes.c_void_p, # RESERVED
|
||||
ctypes.c_void_p, # window
|
||||
ctypes.c_uint, # type
|
||||
ctypes.c_uint, # event type
|
||||
ctypes.c_char_p, # element
|
||||
ctypes.c_char_p, # data
|
||||
PTR_CHAR) # response
|
||||
ctypes.c_uint) # event number
|
||||
self.c_events = py_fun(self._events)
|
||||
except OSError as e:
|
||||
print(
|
||||
@ -112,7 +112,7 @@ class window:
|
||||
event_type: ctypes.c_uint,
|
||||
_element: ctypes.c_char_p,
|
||||
data: ctypes.c_char_p,
|
||||
response_ptr: PTR_CHAR):
|
||||
event_number: ctypes.c_uint):
|
||||
element = _element.decode('utf-8')
|
||||
func_id = self.window_id + element
|
||||
if self.cb_fun_list[func_id] is None:
|
||||
@ -121,16 +121,19 @@ class window:
|
||||
# Create event
|
||||
e = event()
|
||||
e.window = self
|
||||
e.type = int(event_type)
|
||||
e.event_type = int(event_type)
|
||||
e.element = element
|
||||
e.data = data.decode('utf-8')
|
||||
if data is not None:
|
||||
e.data = data.decode('utf-8')
|
||||
else:
|
||||
e.data = ''
|
||||
# User callback
|
||||
cb_result = self.cb_fun_list[func_id](e)
|
||||
if cb_result is not None:
|
||||
cb_result_str = str(cb_result)
|
||||
cb_result_encode = cb_result_str.encode('utf-8')
|
||||
# Set the response
|
||||
webui_lib.webui_interface_set_response(response_ptr, cb_result_encode)
|
||||
webui_lib.webui_interface_set_response(self.window, event_number, cb_result_encode)
|
||||
|
||||
|
||||
# Bind a specific html element click event with a function. Empty element means all events.
|
||||
|
@ -53,13 +53,13 @@ html = """
|
||||
def all_events(e : webui.event):
|
||||
print('Function: all_events()')
|
||||
print('Element: ' + e.element)
|
||||
print('Type: ' + str(e.type))
|
||||
print('Type: ' + str(e.event_type))
|
||||
print('Data: ' + e.data)
|
||||
|
||||
def python_to_js(e : webui.event):
|
||||
print('Function: python_to_js()')
|
||||
print('Element: ' + e.element)
|
||||
print('Type: ' + str(e.type))
|
||||
print('Type: ' + str(e.event_type))
|
||||
print('Data: ' + e.data)
|
||||
# Run JavaScript to get the password
|
||||
res = e.window.script("return document.getElementById('MyInput').value;")
|
||||
@ -74,7 +74,7 @@ def python_to_js(e : webui.event):
|
||||
def js_to_python(e : webui.event):
|
||||
print('Function: js_to_python()')
|
||||
print('Element: ' + e.element)
|
||||
print('Type: ' + str(e.type))
|
||||
print('Type: ' + str(e.event_type))
|
||||
print('Data: ' + e.data)
|
||||
v = int(e.data)
|
||||
v = v * 2
|
||||
@ -82,9 +82,9 @@ def js_to_python(e : webui.event):
|
||||
|
||||
def exit(e : webui.event):
|
||||
print('Function: exit()')
|
||||
print('element: ' + e.element)
|
||||
print('type: ' + str(e.type))
|
||||
print('data: ' + e.data)
|
||||
print('Element: ' + e.element)
|
||||
print('Type: ' + str(e.event_type))
|
||||
print('Data: ' + e.data)
|
||||
webui.exit()
|
||||
|
||||
def main():
|
||||
|
@ -1,6 +1,3 @@
|
||||
|
||||
|
||||
|
||||
# Install WebUI
|
||||
# pip install --upgrade webui2
|
||||
|
||||
|
BIN
examples/Rust/NON_COMPLETE_RUST_WRAPPER.zip
Normal file
BIN
examples/Rust/NON_COMPLETE_RUST_WRAPPER.zip
Normal file
Binary file not shown.
@ -1,13 +0,0 @@
|
||||
# WebUI Examples - Rust
|
||||
|
||||
# NOTICE:
|
||||
|
||||
## The Rust wrapper still needs to be completed. You can finish it and submit the patch as PR. Or, if you prefer to maintain it in your repo, you can create a new issue and submit the link to your Rust wrapper repo. Thank you.
|
||||
|
||||
```sh
|
||||
git clone https://github.com/alifcommunity/webui.git
|
||||
cd webui\examples\Rust\hello_world
|
||||
cargo clean
|
||||
cargo build
|
||||
cargo run
|
||||
```
|
@ -1,8 +0,0 @@
|
||||
[package]
|
||||
name = "my-webui-application"
|
||||
version = "0.1.0"
|
||||
build = "build.rs"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
lazy_static = "1.4.0"
|
@ -1,9 +0,0 @@
|
||||
# WebUI Examples - Rust
|
||||
|
||||
```sh
|
||||
git clone https://github.com/alifcommunity/webui.git
|
||||
cd webui\examples\Rust\hello_world
|
||||
cargo clean
|
||||
cargo build
|
||||
cargo run
|
||||
```
|
@ -1,14 +0,0 @@
|
||||
|
||||
|
||||
fn main() {
|
||||
|
||||
// Path to prebuilt WebUI static library
|
||||
println!("cargo:rustc-link-search=../../../build/Windows/MSVC/");
|
||||
|
||||
// Path to WebUI include folder (Optional)
|
||||
println!("cargo:rustc-link-search=../../../include/");
|
||||
|
||||
// WebUI static library name
|
||||
println!("cargo:rustc-link-lib=webui-2-static-x64");
|
||||
println!("cargo:rustc-link-lib=user32");
|
||||
}
|
@ -1,377 +0,0 @@
|
||||
/*
|
||||
WebUI Library 2.2.0
|
||||
http://_webui_core.me
|
||||
https://github.com/alifcommunity/webui
|
||||
Copyright (c) 2020-2023 Hassan Draga.
|
||||
Licensed under GNU General Public License v2.0.
|
||||
All rights reserved.
|
||||
Canada.
|
||||
*/
|
||||
|
||||
// Flags
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(unsafe_code)]
|
||||
#![allow(dead_code)]
|
||||
#![allow(non_snake_case)]
|
||||
#![allow(improper_ctypes)]
|
||||
#![allow(non_upper_case_globals)]
|
||||
|
||||
// Modules
|
||||
use std::os::raw::c_char;
|
||||
use std::ffi::CString;
|
||||
use std::ffi::CStr;
|
||||
use std::collections::HashMap;
|
||||
use lazy_static::lazy_static;
|
||||
use std::sync::Mutex;
|
||||
|
||||
// Consts
|
||||
pub const true_: u32 = 1;
|
||||
pub const false_: u32 = 0;
|
||||
pub const __bool_true_false_are_defined: u32 = 1;
|
||||
pub type size_t = ::std::os::raw::c_ulong;
|
||||
pub type wchar_t = ::std::os::raw::c_int;
|
||||
|
||||
// Event struct
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct webui_event_t {
|
||||
pub window: *mut ::std::os::raw::c_void,
|
||||
pub type_: ::std::os::raw::c_uint,
|
||||
pub element: *mut ::std::os::raw::c_char,
|
||||
pub data: *mut ::std::os::raw::c_char,
|
||||
pub response: *mut ::std::os::raw::c_char,
|
||||
}
|
||||
|
||||
// References
|
||||
|
||||
extern "C" {
|
||||
pub fn webui_new_window() -> *mut ::std::os::raw::c_void;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn webui_bind(
|
||||
window: *mut ::std::os::raw::c_void,
|
||||
element: *const ::std::os::raw::c_char,
|
||||
func: ::std::option::Option<unsafe extern "C" fn(e: *mut webui_event_t)>
|
||||
) -> ::std::os::raw::c_uint;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn webui_show(
|
||||
window: *mut ::std::os::raw::c_void,
|
||||
content: *const ::std::os::raw::c_char
|
||||
) -> bool;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn webui_show_browser(
|
||||
window: *mut ::std::os::raw::c_void,
|
||||
content: *const ::std::os::raw::c_char,
|
||||
browser: ::std::os::raw::c_uint
|
||||
) -> bool;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn webui_wait();
|
||||
}
|
||||
extern "C" {
|
||||
pub fn webui_close(window: *mut ::std::os::raw::c_void);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn webui_exit();
|
||||
}
|
||||
extern "C" {
|
||||
pub fn webui_is_shown(window: *mut ::std::os::raw::c_void) -> bool;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn webui_set_timeout(second: ::std::os::raw::c_uint);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn webui_set_icon(
|
||||
window: *mut ::std::os::raw::c_void,
|
||||
icon: *const ::std::os::raw::c_char,
|
||||
type_: *const ::std::os::raw::c_char
|
||||
);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn webui_set_multi_access(window: *mut ::std::os::raw::c_void, status: bool);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn webui_run(
|
||||
window: *mut ::std::os::raw::c_void,
|
||||
script: *const ::std::os::raw::c_char
|
||||
) -> bool;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn webui_script(
|
||||
window: *mut ::std::os::raw::c_void,
|
||||
script: *const ::std::os::raw::c_char,
|
||||
timeout: ::std::os::raw::c_uint,
|
||||
buffer: *mut ::std::os::raw::c_char,
|
||||
buffer_length: size_t
|
||||
) -> bool;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn webui_set_runtime(window: *mut ::std::os::raw::c_void, runtime: ::std::os::raw::c_uint);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn webui_get_int(e: *mut webui_event_t) -> ::std::os::raw::c_longlong;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn webui_get_string(e: *mut webui_event_t) -> *const ::std::os::raw::c_char;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn webui_get_bool(e: *mut webui_event_t) -> bool;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn webui_return_int(e: *mut webui_event_t, n: ::std::os::raw::c_longlong);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn webui_return_string(e: *mut webui_event_t, s: *mut ::std::os::raw::c_char);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn webui_return_bool(e: *mut webui_event_t, b: bool);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn webui_interface_bind(
|
||||
window: *mut ::std::os::raw::c_void,
|
||||
element: *const ::std::os::raw::c_char,
|
||||
func: ::std::option::Option<
|
||||
unsafe fn(
|
||||
arg1: *mut ::std::os::raw::c_void,
|
||||
arg2: ::std::os::raw::c_uint,
|
||||
arg3: *mut ::std::os::raw::c_char,
|
||||
arg4: *mut ::std::os::raw::c_char,
|
||||
arg5: *mut ::std::os::raw::c_char
|
||||
)
|
||||
>
|
||||
) -> ::std::os::raw::c_uint;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn webui_interface_set_response(
|
||||
ptr: *mut ::std::os::raw::c_char,
|
||||
response: *const ::std::os::raw::c_char
|
||||
);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn webui_interface_is_app_running() -> bool;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn webui_interface_get_window_id(
|
||||
window: *mut ::std::os::raw::c_void
|
||||
) -> ::std::os::raw::c_uint;
|
||||
}
|
||||
|
||||
// --[Wrapper]-------------------------
|
||||
|
||||
// Browsers
|
||||
pub const AnyBrowser: u32 = 0;
|
||||
pub const Chrome: u32 = 1;
|
||||
pub const Firefox: u32 = 2;
|
||||
pub const Edge: u32 = 3;
|
||||
pub const Safari: u32 = 4;
|
||||
pub const Chromium: u32 = 5;
|
||||
pub const Opera: u32 = 6;
|
||||
pub const Brave: u32 = 7;
|
||||
pub const Vivaldi: u32 = 8;
|
||||
pub const Epic: u32 = 9;
|
||||
pub const Yandex: u32 = 10;
|
||||
|
||||
// Runtimes
|
||||
pub const None: u32 = 0;
|
||||
pub const Deno: u32 = 1;
|
||||
pub const NodeJS: u32 = 2;
|
||||
|
||||
// Events
|
||||
pub const WEBUI_EVENT_DISCONNECTED: u32 = 0;
|
||||
pub const WEBUI_EVENT_CONNECTED: u32 = 1;
|
||||
pub const WEBUI_EVENT_MULTI_CONNECTION: u32 = 2;
|
||||
pub const WEBUI_EVENT_UNWANTED_CONNECTION: u32 = 3;
|
||||
pub const WEBUI_EVENT_MOUSE_CLICK: u32 = 4;
|
||||
pub const WEBUI_EVENT_NAVIGATION: u32 = 5;
|
||||
pub const WEBUI_EVENT_CALLBACK: u32 = 6;
|
||||
|
||||
pub struct JavaScript {
|
||||
pub timeout: u32,
|
||||
pub script: String,
|
||||
pub error: bool,
|
||||
pub data: String,
|
||||
}
|
||||
|
||||
pub struct Event {
|
||||
pub Window: *mut ::std::os::raw::c_void,
|
||||
pub EventType: u32,
|
||||
pub Element: String,
|
||||
pub Data: String,
|
||||
}
|
||||
|
||||
// List of Rust user functions (2-dimensional array)
|
||||
// static mut func_list: [[Option::<fn(e: Event) -> ()>; 64]; 64] = [[64; 64]; 64];
|
||||
// static mut func_array: Vec<Vec<fn(Event)>> = vec![vec![]; 1024];
|
||||
// static mut elements_map = HashMap::<String, usize>::new();
|
||||
// static mut elements_map: HashMap::new();
|
||||
|
||||
type FunctionType = fn(Event);
|
||||
const ROWS: usize = 64;
|
||||
const COLS: usize = 64;
|
||||
static mut GLOBAL_ARRAY: Option<[[Option<FunctionType>; COLS]; ROWS]> = None;
|
||||
|
||||
lazy_static! {
|
||||
static ref elements_map: HashMap<String, usize> = HashMap::new();
|
||||
// static mut func_array: Vec<Vec<fn(Event)>> = vec![vec![]; 1024];
|
||||
}
|
||||
|
||||
// Save a string in the map and return its index
|
||||
fn save_string(map: &mut HashMap<String, usize>, s: &str) -> usize {
|
||||
// Check if the string already exists in the map
|
||||
if let Some(&index) = map.get(s) {
|
||||
return index;
|
||||
}
|
||||
|
||||
// If the string does not exist, add it to the map and return the new index
|
||||
let index = map.len();
|
||||
map.insert(s.to_owned(), index);
|
||||
index
|
||||
}
|
||||
|
||||
// Search for a string in the map and return its index if found, or -1 if not found
|
||||
fn find_string(map: &HashMap<String, usize>, s: &str) -> isize {
|
||||
if let Some(&index) = map.get(s) {
|
||||
index as isize
|
||||
} else {
|
||||
-1
|
||||
}
|
||||
}
|
||||
|
||||
fn char_to_string(c: *const i8) -> String {
|
||||
let cstr = unsafe { CStr::from_ptr(c) };
|
||||
let s: String = String::from_utf8_lossy(cstr.to_bytes()).to_string();
|
||||
return s;
|
||||
}
|
||||
|
||||
fn cstr_to_string(c: CString) -> String {
|
||||
let s: String = String::from_utf8_lossy(c.to_bytes()).to_string();
|
||||
return s;
|
||||
}
|
||||
|
||||
pub fn RunJavaScript(win: *mut ::std::os::raw::c_void, js: &mut JavaScript) {
|
||||
unsafe {
|
||||
// Script String to i8/u8
|
||||
let script_cpy = String::from(js.script.clone());
|
||||
let script_c_str = CString::new(script_cpy).unwrap();
|
||||
let script_c_char: *const c_char = script_c_str.as_ptr() as *const c_char;
|
||||
|
||||
let script: webui_script_interface_t = webui_script_interface_t {
|
||||
timeout: js.timeout,
|
||||
script: script_c_char as *mut i8,
|
||||
data: script_c_char,
|
||||
error: false,
|
||||
length: 0,
|
||||
};
|
||||
|
||||
// deprecated
|
||||
webui_script_interface_struct(win, &script);
|
||||
// TODO: `webui_script_interface_struct` is deprecated. use `webui_script` instead.
|
||||
|
||||
js.error = script.error;
|
||||
js.data = char_to_string(script.data);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn NewWindow() -> *mut ::std::os::raw::c_void {
|
||||
unsafe {
|
||||
GLOBAL_ARRAY = Some([[None; COLS]; ROWS]);
|
||||
return webui_new_window();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn Wait() {
|
||||
unsafe {
|
||||
webui_wait();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn Exit() {
|
||||
unsafe {
|
||||
webui_exit();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn Show(win: *mut ::std::os::raw::c_void, content: &str) -> bool {
|
||||
unsafe {
|
||||
// Content String to i8/u8
|
||||
let content_c_str = CString::new(content).unwrap();
|
||||
let content_c_char: *const c_char = content_c_str.as_ptr() as *const c_char;
|
||||
|
||||
return webui_show(win, content_c_char);
|
||||
}
|
||||
}
|
||||
|
||||
fn events_handler(
|
||||
_window: *mut ::std::os::raw::c_void,
|
||||
_event_type: ::std::os::raw::c_uint,
|
||||
_element: *mut ::std::os::raw::c_char,
|
||||
_data: *mut ::std::os::raw::c_char,
|
||||
_response: *mut ::std::os::raw::c_char
|
||||
) {
|
||||
let Window: *mut ::std::os::raw::c_void = _window;
|
||||
let EventType: u32 = _event_type;
|
||||
let Element: String = char_to_string(_element);
|
||||
let Data: String = char_to_string(_data);
|
||||
|
||||
let element_index = find_string(&elements_map, &Element);
|
||||
if element_index < 0 {
|
||||
return;
|
||||
}
|
||||
|
||||
let E = Event {
|
||||
Window: Window,
|
||||
EventType: EventType,
|
||||
Element: Element,
|
||||
Data: Data,
|
||||
};
|
||||
|
||||
// Call the Rust user function
|
||||
let window_id = webui_interface_get_window_id(_window);
|
||||
let window_id_64 = window_id as usize;
|
||||
let element_index_64 = element_index as usize;
|
||||
unsafe {
|
||||
// func_list[window_id_64][element_index_64].expect("non-null function pointer")(E);
|
||||
// func_array[window_id_64][element_index_64](E);
|
||||
// if let Some(func) = GLOBAL_ARRAY[window_id_64][element_index_64] {
|
||||
// func(E.clone());
|
||||
// }
|
||||
if let Some(func) = GLOBAL_ARRAY.as_ref().unwrap()[window_id_64][element_index_64] {
|
||||
func(E);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn Bind(win: *mut ::std::os::raw::c_void, element: &str, func: fn(Event)) {
|
||||
// Element String to i8/u8
|
||||
let element_c_str = CString::new(element).unwrap();
|
||||
let element_c_char: *const c_char = element_c_str.as_ptr() as *const c_char;
|
||||
|
||||
// Bind
|
||||
unsafe {
|
||||
let f: Option<
|
||||
unsafe fn(
|
||||
_window: *mut ::std::os::raw::c_void,
|
||||
_event_type: ::std::os::raw::c_uint,
|
||||
_element: *mut ::std::os::raw::c_char,
|
||||
_data: *mut ::std::os::raw::c_char,
|
||||
_response: *mut ::std::os::raw::c_char
|
||||
)
|
||||
> = Some(events_handler);
|
||||
|
||||
let element_index = save_string(&mut elements_map, element);
|
||||
let window_id = webui_interface_get_window_id(win);
|
||||
let window_id_64 = window_id as usize;
|
||||
let element_index_64 = element_index as usize;
|
||||
|
||||
webui_interface_bind(win, element_c_char, f);
|
||||
|
||||
// Add the Rust user function to the list
|
||||
// let user_cb: Option<fn(e: Event)> = Some(func);
|
||||
// func_list[window_id_64][element_index_64] = user_cb;
|
||||
// func_array[window_id_64][element_index_64] = func;
|
||||
// GLOBAL_ARRAY[window_id_64][element_index_64] = Some(func as FunctionType);
|
||||
GLOBAL_ARRAY.as_mut().unwrap()[window_id_64][element_index_64] = Some(func as FunctionType);
|
||||
}
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
mod Webui;
|
||||
|
||||
fn close_the_application (_e: Webui::Event) {
|
||||
|
||||
Webui::Exit();
|
||||
}
|
||||
|
||||
fn check_the_password (e: Webui::Event) {
|
||||
|
||||
// Script to get the text value
|
||||
let mut js = Webui::JavaScript {
|
||||
timeout: 10,
|
||||
script: "return document.getElementById(\"MyInput\").value;".to_string(),
|
||||
data: "".to_string(),
|
||||
error: false,
|
||||
};
|
||||
|
||||
// Run the script
|
||||
Webui::RunJavaScript(e.Window, &mut js);
|
||||
|
||||
// Check if any error
|
||||
if !js.error {
|
||||
|
||||
// Check the password
|
||||
println!("Password: {}", js.data);
|
||||
if js.data == "123456" {
|
||||
|
||||
// Password is correct
|
||||
js.script = "alert('Good. The password is correct');".to_string();
|
||||
Webui::RunJavaScript(e.Window, &mut js);
|
||||
}
|
||||
else {
|
||||
|
||||
// Wrong password
|
||||
js.script = "alert('Sorry. Wrong password');".to_string();
|
||||
Webui::RunJavaScript(e.Window, &mut js);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
// There is an error in our script
|
||||
println!("JavaScript Error: {}", js.data);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
// UI HTML
|
||||
let my_html = "<!DOCTYPE html>
|
||||
<html><head><title>WebUI 2 - Rust Example</title>
|
||||
<style>body{color: white; background: #0F2027;
|
||||
background: -webkit-linear-gradient(to right, #2a4c4c, #0b181c, #020f14);
|
||||
background: linear-gradient(to right, #2a4c4c, #0b181c, #020f14);
|
||||
text-align:center; font-size: 18px; font-family: sans-serif;}</style></head><body>
|
||||
<h1>WebUI 2 - Rust Example</h1><br>
|
||||
<input type=\"password\" id=\"MyInput\"><br><br>
|
||||
<button id=\"MyButton1\">Check Password</button> - <button id=\"MyButton2\">Exit</button>
|
||||
</body></html>";
|
||||
|
||||
// Create new window
|
||||
let my_window = Webui::NewWindow();
|
||||
|
||||
// Bind an HTML element with a function
|
||||
Webui::Bind(my_window, "MyButton1", check_the_password);
|
||||
Webui::Bind(my_window, "MyButton2", close_the_application);
|
||||
|
||||
// Show the window
|
||||
Webui::Show(my_window, my_html);
|
||||
|
||||
// Wait until all windows get closed
|
||||
Webui::Wait();
|
||||
|
||||
println!("Thank you.");
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
This is an example of how to use the WebUI dynamic library in Deno to create an HTML5 based user interface.
|
||||
|
||||
|
||||
Tested using Deno v1.32.4.
|
||||
Tested using Deno v1.33.1.
|
||||
|
||||
### Deno Hello World
|
||||
|
||||
@ -20,4 +20,4 @@ Folder structure example:
|
||||
* deno
|
||||
* hello_world.ts
|
||||
* webui.ts
|
||||
* webui-2-x64 dynamic library
|
||||
* webui-2-x64 (Dynamic library)
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -35,7 +35,7 @@ export const browser = {
|
||||
|
||||
export interface event {
|
||||
win: Deno.Pointer,
|
||||
type: number,
|
||||
event_type: number,
|
||||
element: string,
|
||||
data: string,
|
||||
}
|
||||
@ -148,7 +148,7 @@ function load_lib() {
|
||||
nonblocking: false,
|
||||
},
|
||||
webui_interface_bind: {
|
||||
// unsigned int webui_interface_bind(void* window, const char* element, void (*func)(void*, int, char*, char*, char*))
|
||||
// unsigned int webui_interface_bind(void* window, const char* element, void (*func)(void*, unsigned int, char*, char*, unsigned int))
|
||||
parameters: ['pointer', 'buffer', 'function'],
|
||||
result: 'u32',
|
||||
nonblocking: false,
|
||||
@ -237,27 +237,29 @@ export function bind(win: Deno.Pointer, element: string, func: Function) {
|
||||
load_lib();
|
||||
const callbackResource = new Deno.UnsafeCallback(
|
||||
{
|
||||
parameters: ['pointer', 'u32', 'pointer', 'pointer', 'pointer'],
|
||||
// unsigned int webui_interface_bind(..., void (*func)(void*, unsigned int, char*, char*, unsigned int))
|
||||
parameters: ['pointer', 'u32', 'pointer', 'pointer', 'u32'],
|
||||
result: 'void',
|
||||
} as const,
|
||||
(
|
||||
param_window: Deno.Pointer,
|
||||
param_type: Deno.u32,
|
||||
param_event_type: Deno.u32,
|
||||
param_element: Deno.Pointer,
|
||||
param_data: Deno.Pointer,
|
||||
param_response: Deno.Pointer
|
||||
param_event_number: Deno.u32
|
||||
) => {
|
||||
|
||||
// Create elements
|
||||
const win = param_window;
|
||||
const type = parseInt(param_type);
|
||||
const element = new Deno.UnsafePointerView(param_element).getCString();
|
||||
const data = new Deno.UnsafePointerView(param_data).getCString();
|
||||
const event_type = parseInt(param_event_type);
|
||||
const element = (param_element != null ? (new Deno.UnsafePointerView(param_element).getCString()) : "");
|
||||
const data = (param_data != null ? (new Deno.UnsafePointerView(param_data).getCString()) : "");
|
||||
const event_number = parseInt(param_event_number);
|
||||
|
||||
// Create struct
|
||||
const e: event = {
|
||||
win: win,
|
||||
type: type,
|
||||
event_type: event_type,
|
||||
element: element,
|
||||
data: data,
|
||||
};
|
||||
@ -266,7 +268,7 @@ export function bind(win: Deno.Pointer, element: string, func: Function) {
|
||||
const result = String(func(e));
|
||||
|
||||
// Send back the response
|
||||
webui_lib.symbols.webui_interface_set_response(param_response, string_to_uint8array(result));
|
||||
webui_lib.symbols.webui_interface_set_response(win, event_number, string_to_uint8array(result));
|
||||
},
|
||||
);
|
||||
|
||||
|
@ -133,10 +133,10 @@ enum webui_events {
|
||||
// -- Structs -------------------------
|
||||
typedef struct webui_event_t {
|
||||
void* window; // Pointer to the window object
|
||||
unsigned int type; // Event type
|
||||
char* element; // HTML element ID
|
||||
unsigned int event_type; // Event type
|
||||
char* element; // HTML element ID
|
||||
char* data; // JavaScript data
|
||||
char* response; // Callback response
|
||||
unsigned int event_number; // Internal WebUI
|
||||
} webui_event_t;
|
||||
|
||||
// -- Definitions ---------------------
|
||||
@ -161,7 +161,7 @@ WEBUI_EXPORT bool webui_is_shown(void* window);
|
||||
// Set the maximum time in seconds to wait for browser to start
|
||||
WEBUI_EXPORT void webui_set_timeout(unsigned int second);
|
||||
// Set the default embedded HTML favicon
|
||||
WEBUI_EXPORT void webui_set_icon(void* window, const char* icon, const char* type);
|
||||
WEBUI_EXPORT void webui_set_icon(void* window, const char* icon, const char* icon_type);
|
||||
// Allow the window URL to be re-used in normal web browsers
|
||||
WEBUI_EXPORT void webui_set_multi_access(void* window, bool status);
|
||||
|
||||
@ -186,10 +186,10 @@ WEBUI_EXPORT void webui_return_string(webui_event_t* e, char* s);
|
||||
WEBUI_EXPORT void webui_return_bool(webui_event_t* e, bool b);
|
||||
|
||||
// -- Interface -----------------------
|
||||
// Bind a specific html element click event with a function. Empty element means all events. This replace webui_bind(). The func is (Window, EventType, Element, Data, Response)
|
||||
WEBUI_EXPORT unsigned int webui_interface_bind(void* window, const char* element, void (*func)(void*, unsigned int, char*, char*, char*));
|
||||
// When using `webui_interface_bind()` you need this function to easily set your callback response.
|
||||
WEBUI_EXPORT void webui_interface_set_response(char* ptr, const char* response);
|
||||
// Bind a specific html element click event with a function. Empty element means all events. This replace webui_bind(). The func is (Window, EventType, Element, Data, EventNumber)
|
||||
WEBUI_EXPORT unsigned int webui_interface_bind(void* window, const char* element, void (*func)(void*, unsigned int, char*, char*, unsigned int));
|
||||
// When using `webui_interface_bind()` you may need this function to easily set your callback response.
|
||||
WEBUI_EXPORT void webui_interface_set_response(void* window, unsigned int event_number, const char* response);
|
||||
// Check if the app still running or not. This replace webui_wait().
|
||||
WEBUI_EXPORT bool webui_interface_is_app_running(void);
|
||||
// Get window unique ID
|
||||
|
@ -68,8 +68,8 @@ namespace webui {
|
||||
}
|
||||
|
||||
// Set the default embedded HTML favicon
|
||||
void set_icon(void* window, std::string icon, std::string type) {
|
||||
webui_set_icon(window, icon.c_str(), type.c_str());
|
||||
void set_icon(void* window, std::string icon, std::string icon_type) {
|
||||
webui_set_icon(window, icon.c_str(), icon_type.c_str());
|
||||
}
|
||||
|
||||
// Allow the window URL to be re-used in normal web browsers
|
||||
@ -125,13 +125,13 @@ namespace webui {
|
||||
|
||||
// -- Interface -----------------------
|
||||
// Bind a specific html element click event with a function. Empty element means all events. This replace bind(). The func is (Window, EventType, Element, Data, Response)
|
||||
unsigned int interface_bind(void* window, std::string element, void (*func)(void*, unsigned int, char*, char*, char*)) {
|
||||
unsigned int interface_bind(void* window, std::string element, void (*func)(void*, unsigned int, char*, char*, unsigned int)) {
|
||||
return webui_interface_bind(window, element.c_str(), func);
|
||||
}
|
||||
|
||||
// When using `interface_bind()` you need this function to easily set your callback response.
|
||||
void interface_set_response(std::string ptr, std::string response) {
|
||||
webui_interface_set_response(&ptr[0], response.c_str());
|
||||
void interface_set_response(void *window, webui_event_t* e, std::string response) {
|
||||
webui_interface_set_response(window, e->event_number, response.c_str());
|
||||
}
|
||||
|
||||
// Check if the app still running or not. This replace wait().
|
||||
|
309
src/webui.c
309
src/webui.c
@ -39,7 +39,6 @@ static const char* webui_javascript_bridge =
|
||||
"const _WEBUI_CLICK = 252; \n"
|
||||
"const _WEBUI_SWITCH = 251; \n"
|
||||
"const _WEBUI_CLOSE = 250; \n"
|
||||
"const _WEBUI_FUNCTION = 249; \n"
|
||||
"function _webui_close(reason = 0, value = 0) { \n"
|
||||
" _webui_send_event_navigation(value); \n"
|
||||
" _webui_ws_status = false; \n"
|
||||
@ -469,17 +468,17 @@ void webui_set_multi_access(void* window, bool status) {
|
||||
win->multi_access = status;
|
||||
}
|
||||
|
||||
void webui_set_icon(void* window, const char* icon, const char* type) {
|
||||
void webui_set_icon(void* window, const char* icon, const char* icon_type) {
|
||||
|
||||
// Dereference
|
||||
_webui_window_t* win = (_webui_window_t*)window;
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
printf("[User] webui_set_icon([%s], [%s])... \n", icon, type);
|
||||
printf("[User] webui_set_icon([%s], [%s])... \n", icon, icon_type);
|
||||
#endif
|
||||
|
||||
win->icon = icon;
|
||||
win->icon_type = type;
|
||||
win->icon_type = icon_type;
|
||||
}
|
||||
|
||||
bool webui_show(void* window, const char* content) {
|
||||
@ -605,9 +604,17 @@ void webui_return_int(webui_event_t* e, long long int n) {
|
||||
printf("[User] webui_return_int([%lld])... \n", n);
|
||||
#endif
|
||||
|
||||
// Dereference
|
||||
_webui_window_t* win = (_webui_window_t*)e->window;
|
||||
|
||||
// Get buffer
|
||||
if(win->event_core[e->event_number] == NULL)
|
||||
return;
|
||||
char** response = &win->event_core[e->event_number]->response;
|
||||
|
||||
// Free
|
||||
if(e->response != NULL)
|
||||
_webui_free_mem(e->response);
|
||||
if(*response != NULL)
|
||||
_webui_free_mem((void*)*response);
|
||||
|
||||
// Int to Str
|
||||
// 64-bit max is -9,223,372,036,854,775,808 (20 character)
|
||||
@ -615,7 +622,7 @@ void webui_return_int(webui_event_t* e, long long int n) {
|
||||
sprintf(buf, "%lld", n);
|
||||
|
||||
// Set response
|
||||
e->response = buf;
|
||||
*response = buf;
|
||||
}
|
||||
|
||||
void webui_return_string(webui_event_t* e, char* s) {
|
||||
@ -626,10 +633,18 @@ void webui_return_string(webui_event_t* e, char* s) {
|
||||
|
||||
if(_webui_is_empty(s))
|
||||
return;
|
||||
|
||||
// Dereference
|
||||
_webui_window_t* win = (_webui_window_t*)e->window;
|
||||
|
||||
// Get buffer
|
||||
if(win->event_core[e->event_number] == NULL)
|
||||
return;
|
||||
char** response = &win->event_core[e->event_number]->response;
|
||||
|
||||
// Free
|
||||
if(e->response != NULL)
|
||||
_webui_free_mem(e->response);
|
||||
if(*response != NULL)
|
||||
_webui_free_mem((void*)*response);
|
||||
|
||||
// Copy Str
|
||||
int len = strlen(s);
|
||||
@ -637,7 +652,7 @@ void webui_return_string(webui_event_t* e, char* s) {
|
||||
memcpy(buf, s, len);
|
||||
|
||||
// Set response
|
||||
e->response = buf;
|
||||
*response = buf;
|
||||
}
|
||||
|
||||
void webui_return_bool(webui_event_t* e, bool b) {
|
||||
@ -646,9 +661,17 @@ void webui_return_bool(webui_event_t* e, bool b) {
|
||||
printf("[User] webui_return_bool([%d])... \n", b);
|
||||
#endif
|
||||
|
||||
// Dereference
|
||||
_webui_window_t* win = (_webui_window_t*)e->window;
|
||||
|
||||
// Get buffer
|
||||
if(win->event_core[e->event_number] == NULL)
|
||||
return;
|
||||
char** response = &win->event_core[e->event_number]->response;
|
||||
|
||||
// Free
|
||||
if(e->response != NULL)
|
||||
_webui_free_mem(e->response);
|
||||
if(*response != NULL)
|
||||
_webui_free_mem((void*)*response);
|
||||
|
||||
// Bool to Str
|
||||
int len = 1;
|
||||
@ -656,7 +679,7 @@ void webui_return_bool(webui_event_t* e, bool b) {
|
||||
sprintf(buf, "%d", b);
|
||||
|
||||
// Set response
|
||||
e->response = buf;
|
||||
*response = buf;
|
||||
}
|
||||
|
||||
void webui_exit(void) {
|
||||
@ -762,30 +785,40 @@ void _webui_interface_bind_handler(webui_event_t* e) {
|
||||
char* webui_internal_id = _webui_generate_internal_id(e->window, e->element);
|
||||
unsigned int cb_index = _webui_get_cb_index(webui_internal_id);
|
||||
|
||||
// void* window; // Pointer to the window object
|
||||
// unsigned int event_type; // Event type
|
||||
// char* element; // HTML element ID
|
||||
// char* data; // JavaScript data
|
||||
// unsigned int event_number; // Internal WebUI
|
||||
|
||||
if(cb_index > 0 && _webui_core.cb_interface[cb_index] != NULL) {
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
printf("[Core]\t\t_webui_interface_bind_handler() -> User callback @ 0x%p\n", _webui_core.cb_interface[cb_index]);
|
||||
printf("[Core]\t\t_webui_interface_bind_handler() -> Response set @ 0x%p\n", (char*)&e->response);
|
||||
printf("[Core]\t\t_webui_interface_bind_handler() -> type [%u]\n", e->type);
|
||||
printf("[Core]\t\t_webui_interface_bind_handler() -> data [%s]\n", e->data);
|
||||
printf("[Core]\t\t_webui_interface_bind_handler() -> element [%s]\n", e->element);
|
||||
printf("[Core]\t\t_webui_interface_bind_handler() -> e->event_type [%u]\n", e->event_type);
|
||||
printf("[Core]\t\t_webui_interface_bind_handler() -> e->element [%s]\n", e->element);
|
||||
printf("[Core]\t\t_webui_interface_bind_handler() -> e->data [%s]\n", e->data);
|
||||
printf("[Core]\t\t_webui_interface_bind_handler() -> e->event_number %d\n", e->event_number);
|
||||
#endif
|
||||
_webui_core.cb_interface[cb_index](e->window, e->type, e->element, e->data, (char*)&e->response);
|
||||
|
||||
// Call cb
|
||||
_webui_core.cb_interface[cb_index](e->window, e->event_type, e->element, e->data, e->event_number);
|
||||
}
|
||||
|
||||
if(_webui_is_empty((const char *)e->response))
|
||||
e->response = (char*)webui_empty_string;
|
||||
|
||||
|
||||
// Free
|
||||
_webui_free_mem((void*)webui_internal_id);
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
printf("[Core]\t\t_webui_interface_bind_handler() -> user-callback response [%s] @ 0x%p\n", (const char *)e->response, e->response);
|
||||
// Print cb response
|
||||
char* response = NULL;
|
||||
_webui_window_t* win = (_webui_window_t*)e->window;
|
||||
if(win->event_core[e->event_number] != NULL)
|
||||
response = *(&win->event_core[e->event_number]->response);
|
||||
printf("[Core]\t\t_webui_interface_bind_handler() -> user-callback response [%s]\n", response);
|
||||
#endif
|
||||
}
|
||||
|
||||
unsigned int webui_interface_bind(void* window, const char* element, void (*func)(void*, unsigned int, char*, char*, char*)) {
|
||||
unsigned int webui_interface_bind(void* window, const char* element, void (*func)(void*, unsigned int, char*, char*, unsigned int)) {
|
||||
|
||||
// Dereference
|
||||
_webui_window_t* win = (_webui_window_t*)window;
|
||||
@ -800,28 +833,32 @@ unsigned int webui_interface_bind(void* window, const char* element, void (*func
|
||||
return cb_index;
|
||||
}
|
||||
|
||||
void webui_interface_set_response(char* ptr, const char* response) {
|
||||
void webui_interface_set_response(void* window, unsigned int event_number, const char* response) {
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
printf("[User] webui_interface_set_response()... \n");
|
||||
printf("[User] webui_interface_set_response() -> Pointer @ 0x%p \n", ptr);
|
||||
printf("[User] webui_interface_set_response() -> event_number %d \n", event_number);
|
||||
printf("[User] webui_interface_set_response() -> Response [%s] \n", response);
|
||||
#endif
|
||||
|
||||
size_t len = strlen(response);
|
||||
// Dereference
|
||||
_webui_window_t* win = (_webui_window_t*)window;
|
||||
|
||||
if(len < 1)
|
||||
return;
|
||||
// Get internal response buffer
|
||||
if(win->event_core[event_number] != NULL) {
|
||||
|
||||
char* buf = (char*) _webui_malloc(len);
|
||||
char** _ptr = (char**)ptr;
|
||||
*_ptr = buf;
|
||||
strcpy(*_ptr, response);
|
||||
char** buffer = NULL;
|
||||
buffer = &win->event_core[event_number]->response;
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
printf("[User] webui_interface_set_response() -> Internal buffer @ 0x%p \n", (*_ptr));
|
||||
printf("[User] webui_interface_set_response() -> Internal buffer [%s] \n", (*_ptr));
|
||||
#endif
|
||||
// Set the response
|
||||
size_t len = strlen(response);
|
||||
*buffer = (char*) _webui_malloc(len);
|
||||
strcpy(*buffer, response);
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
printf("[User] webui_interface_set_response() -> Internal buffer [%s] \n", *buffer);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
bool webui_interface_is_app_running(void) {
|
||||
@ -1056,6 +1093,22 @@ void* _webui_malloc(int size) {
|
||||
return block;
|
||||
}
|
||||
|
||||
unsigned int _webui_get_free_event_core_pos(_webui_window_t* win) {
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
printf("[Core]\t\t_webui_get_free_event_core_pos()... \n");
|
||||
#endif
|
||||
|
||||
for(unsigned int i = 1; i < WEBUI_MAX_ARRAY; i++) {
|
||||
if(win->event_core[i] == NULL)
|
||||
return i;
|
||||
}
|
||||
|
||||
// Fatal. No free pos found
|
||||
// let's use the first pos
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void _webui_sleep(long unsigned int ms) {
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
@ -1419,9 +1472,9 @@ static void _webui_interpret_file(_webui_window_t* win, struct mg_connection *c,
|
||||
// [disable coloring][file]
|
||||
char* cmd = (char*) _webui_malloc(64 + strlen(full_path));
|
||||
#ifdef _WIN32
|
||||
sprintf(cmd, "Set NO_COLOR=1 & Set DENO_NO_UPDATE_CHECK=1 & deno run --allow-all --unstable \"%s\" \"%s\"", full_path, query);
|
||||
sprintf(cmd, "Set NO_COLOR=1 & Set DENO_NO_UPDATE_CHECK=1 & deno run --quiet --allow-all --unstable \"%s\" \"%s\"", full_path, query);
|
||||
#else
|
||||
sprintf(cmd, "NO_COLOR=1 & DENO_NO_UPDATE_CHECK=1 & deno run --allow-all --unstable \"%s\" \"%s\"", full_path, query);
|
||||
sprintf(cmd, "NO_COLOR=1; DENO_NO_UPDATE_CHECK=1; deno run --quiet --allow-all --unstable \"%s\" \"%s\"", full_path, query);
|
||||
#endif
|
||||
|
||||
// Run command
|
||||
@ -1636,41 +1689,48 @@ static void _webui_server_event_handler(struct mg_connection *c, int ev, void *e
|
||||
// Generate WebUI internal id
|
||||
char* webui_internal_id = _webui_generate_internal_id(win, element);
|
||||
|
||||
// Call user function
|
||||
// Create new event core to hold the response
|
||||
webui_event_core_t* event_core = (webui_event_core_t*) _webui_malloc(sizeof(webui_event_core_t));
|
||||
unsigned int event_core_pos = _webui_get_free_event_core_pos(win);
|
||||
win->event_core[event_core_pos] = event_core;
|
||||
char** response = &win->event_core[event_core_pos]->response;
|
||||
|
||||
// Create new event
|
||||
webui_event_t e;
|
||||
e.element = element;
|
||||
e.window = win;
|
||||
e.event_type = WEBUI_EVENT_CALLBACK;
|
||||
e.element = element;
|
||||
e.data = data;
|
||||
e.response = NULL;
|
||||
e.type = WEBUI_EVENT_CALLBACK;
|
||||
e.event_number = event_core_pos;
|
||||
|
||||
// Call user function
|
||||
unsigned int cb_index = _webui_get_cb_index(webui_internal_id);
|
||||
|
||||
// Check for bind
|
||||
if(cb_index > 0 && _webui_core.cb[cb_index] != NULL) {
|
||||
|
||||
// Call user cb
|
||||
_webui_core.cb[cb_index](&e);
|
||||
}
|
||||
|
||||
if(_webui_is_empty(e.response))
|
||||
e.response = (char*)webui_empty_string;
|
||||
// Check the response
|
||||
if(_webui_is_empty(*response))
|
||||
*response = (char*)webui_empty_string;
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
printf("[Core]\t\t_webui_server_event_handler()... user-callback response [%s]\n", (const char*)e.response);
|
||||
printf("[Core]\t\t_webui_server_event_handler()... user-callback response [%s]\n", *response);
|
||||
#endif
|
||||
|
||||
// Send response
|
||||
mg_http_reply(
|
||||
c, 200,
|
||||
"",
|
||||
e.response
|
||||
*response
|
||||
);
|
||||
|
||||
// Free
|
||||
_webui_free_mem((void*)packet);
|
||||
_webui_free_mem((void*)webui_internal_id);
|
||||
_webui_free_mem((void*)e.response);
|
||||
_webui_free_mem((void*)*response);
|
||||
_webui_free_mem((void*)event_core);
|
||||
}
|
||||
else if(mg_http_match_uri(hm, "/")) {
|
||||
|
||||
@ -1903,19 +1963,19 @@ static void _webui_server_event_handler(struct mg_connection *c, int ev, void *e
|
||||
}
|
||||
}
|
||||
|
||||
// Events
|
||||
// New Event
|
||||
if(win->has_events) {
|
||||
|
||||
// Generate WebUI internal id
|
||||
char* webui_internal_id = _webui_generate_internal_id(win, "");
|
||||
|
||||
_webui_window_event(
|
||||
win, // Window
|
||||
webui_internal_id, // WebUI Internal ID
|
||||
"", // User HTML ID
|
||||
NULL, // User Custom Data
|
||||
0, // User Data Len
|
||||
event_type // Type of this event
|
||||
win, // Event -> Window
|
||||
event_type, // Event -> Type of this event
|
||||
"", // Event -> HTML Element
|
||||
NULL, // Event -> User Custom Data
|
||||
0, // Event -> Event Number
|
||||
webui_internal_id // Extras -> WebUI Internal ID
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1949,12 +2009,12 @@ static void _webui_server_event_handler(struct mg_connection *c, int ev, void *e
|
||||
char* webui_internal_id = _webui_generate_internal_id(win, "");
|
||||
|
||||
_webui_window_event(
|
||||
win, // Window
|
||||
webui_internal_id, // WebUI Internal ID
|
||||
"", // User HTML ID
|
||||
NULL, // User Custom Data
|
||||
0, // User Data Len
|
||||
WEBUI_EVENT_DISCONNECTED // Type of this event
|
||||
win, // Event -> Window
|
||||
WEBUI_EVENT_DISCONNECTED, // Event -> Type of this event
|
||||
"", // Event -> HTML Element
|
||||
NULL, // Event -> User Custom Data
|
||||
0, // Event -> Event Number
|
||||
webui_internal_id // Extras -> WebUI Internal ID
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -3481,27 +3541,29 @@ bool _webui_show_window(_webui_window_t* win, const char* content, bool is_embed
|
||||
return true;
|
||||
}
|
||||
|
||||
static void _webui_window_event(_webui_window_t* win, char* webui_internal_id, char* element, void* data, unsigned int data_len, int event_type) {
|
||||
static void _webui_window_event(_webui_window_t* win, int event_type, char* element, char* data, unsigned int event_number, char* webui_internal_id) {
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
printf("[Core]\t\t_webui_window_event([%s], [%s])... \n", webui_internal_id, element);
|
||||
#endif
|
||||
|
||||
// Create a thread, and call the used cb function
|
||||
_webui_cb_t* arg = (_webui_cb_t*) _webui_malloc(sizeof(_webui_cb_t));
|
||||
arg->win = win;
|
||||
arg->webui_internal_id = webui_internal_id;
|
||||
arg->element_name = element;
|
||||
arg->event_type = event_type;
|
||||
if(data != NULL) {
|
||||
arg->data = data;
|
||||
arg->data_len = data_len;
|
||||
}
|
||||
else {
|
||||
arg->data = (void*) webui_empty_string;
|
||||
arg->data_len = 0;
|
||||
}
|
||||
// no need to wait for the response. This is fire
|
||||
// and forget.
|
||||
|
||||
// Create a new CB args struct
|
||||
_webui_cb_arg_t* arg = (_webui_cb_arg_t*) _webui_malloc(sizeof(_webui_cb_arg_t));
|
||||
|
||||
// Event
|
||||
arg->window = win;
|
||||
arg->event_type = event_type;
|
||||
arg->element = element;
|
||||
arg->data = data;
|
||||
arg->event_number = event_number;
|
||||
// Extras
|
||||
arg->webui_internal_id = webui_internal_id;
|
||||
|
||||
// fire and forget.
|
||||
#ifdef _WIN32
|
||||
HANDLE user_fun_thread = CreateThread(NULL, 0, _webui_cb, (void*) arg, 0, NULL);
|
||||
if(user_fun_thread != NULL)
|
||||
@ -3616,12 +3678,12 @@ static void _webui_window_receive(_webui_window_t* win, const char* packet, size
|
||||
char* webui_internal_id = _webui_generate_internal_id(win, element);
|
||||
|
||||
_webui_window_event(
|
||||
win, // Window
|
||||
webui_internal_id, // WebUI Internal ID
|
||||
element, // User HTML ID
|
||||
NULL, // User Custom Data
|
||||
0, // User Data Len
|
||||
WEBUI_EVENT_MOUSE_CLICK // Type of this event
|
||||
win, // Event -> Window
|
||||
WEBUI_EVENT_MOUSE_CLICK, // Event -> Type of this event
|
||||
element, // Event -> HTML Element
|
||||
NULL, // Event -> User Custom Data
|
||||
0, // Event -> Event Number
|
||||
webui_internal_id // Extras -> WebUI Internal ID
|
||||
);
|
||||
}
|
||||
else if((unsigned char) packet[1] == WEBUI_HEADER_JS) {
|
||||
@ -3682,45 +3744,6 @@ static void _webui_window_receive(_webui_window_t* win, const char* packet, size
|
||||
// Send ready signal to webui_script()
|
||||
_webui_core.run_done[run_id] = true;
|
||||
}
|
||||
else if((unsigned char) packet[1] == WEBUI_HEADER_CALL_FUNC) {
|
||||
|
||||
// Function Call (No response)
|
||||
|
||||
// 0: [Signature]
|
||||
// 1: [Type]
|
||||
// 2:
|
||||
// 3: [ID, Null, Data]
|
||||
|
||||
// Get html element id
|
||||
char* element;
|
||||
size_t element_len;
|
||||
if(!_webui_get_data(packet, len, 3, &element_len, &element))
|
||||
return;
|
||||
|
||||
// Get data
|
||||
void* data;
|
||||
size_t data_len;
|
||||
if(!_webui_get_data(packet, len, (3 + element_len + 1), &data_len, (char **) &data))
|
||||
return;
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
printf("[Core]\t\t_webui_window_receive() -> WEBUI_HEADER_CALL_FUNC \n");
|
||||
printf("[Core]\t\t_webui_window_receive() -> %d bytes \n", (int)element_len);
|
||||
printf("[Core]\t\t_webui_window_receive() -> [%s] \n", element);
|
||||
#endif
|
||||
|
||||
// Generate WebUI internal id
|
||||
char* webui_internal_id = _webui_generate_internal_id(win, element);
|
||||
|
||||
_webui_window_event(
|
||||
win, // Window
|
||||
webui_internal_id, // WebUI Internal ID
|
||||
element, // User HTML ID
|
||||
data, // User Custom Data
|
||||
data_len, // User Data Len
|
||||
WEBUI_EVENT_CALLBACK // Type of this event
|
||||
);
|
||||
}
|
||||
else if((unsigned char) packet[1] == WEBUI_HEADER_SWITCH) {
|
||||
|
||||
// Navigation Event
|
||||
@ -3749,12 +3772,12 @@ static void _webui_window_receive(_webui_window_t* win, const char* packet, size
|
||||
char* webui_internal_id = _webui_generate_internal_id(win, "");
|
||||
|
||||
_webui_window_event(
|
||||
win, // Window
|
||||
webui_internal_id, // WebUI Internal ID
|
||||
"", // HTML ID
|
||||
url, // URL
|
||||
url_len, // URL Len
|
||||
WEBUI_EVENT_NAVIGATION // Type of this event
|
||||
win, // Event -> Window
|
||||
WEBUI_EVENT_NAVIGATION, // Event -> Type of this event
|
||||
"", // Event -> HTML Element
|
||||
url, // Event -> User Custom Data
|
||||
0, // Event -> Event Number
|
||||
webui_internal_id // Extras -> WebUI Internal ID
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -4104,23 +4127,24 @@ WEBUI_SERVER_START
|
||||
|
||||
WEBUI_CB
|
||||
{
|
||||
_webui_cb_t* arg = (_webui_cb_t*) _arg;
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
printf("[Core]\t\t[Thread] _webui_cb()... \n");
|
||||
#endif
|
||||
|
||||
_webui_cb_arg_t* arg = (_webui_cb_arg_t*) _arg;
|
||||
|
||||
// Event
|
||||
webui_event_t e;
|
||||
e.element = arg->element_name;
|
||||
e.window = arg->win;
|
||||
e.window = arg->window;
|
||||
e.event_type = arg->event_type;
|
||||
e.element = arg->element;
|
||||
e.data = arg->data;
|
||||
e.response = NULL;
|
||||
e.type = arg->event_type;
|
||||
e.event_number = arg->event_number;
|
||||
|
||||
// Check for all events-binded function
|
||||
if(arg->win->has_events) {
|
||||
// Check for all events-bind functions
|
||||
if(arg->window->has_events) {
|
||||
|
||||
char* events_id = _webui_generate_internal_id(arg->win, "");
|
||||
char* events_id = _webui_generate_internal_id(arg->window, "");
|
||||
unsigned int events_cb_index = _webui_get_cb_index(events_id);
|
||||
_webui_free_mem((void*)events_id);
|
||||
|
||||
@ -4131,8 +4155,8 @@ WEBUI_CB
|
||||
}
|
||||
}
|
||||
|
||||
// Check for the binded function
|
||||
if(arg->element_name != NULL && !_webui_is_empty(arg->element_name)) {
|
||||
// Check for the regular bind functions
|
||||
if(arg->element != NULL && !_webui_is_empty(arg->element)) {
|
||||
|
||||
unsigned int cb_index = _webui_get_cb_index(arg->webui_internal_id);
|
||||
if(cb_index > 0 && _webui_core.cb[cb_index] != NULL) {
|
||||
@ -4146,10 +4170,11 @@ WEBUI_CB
|
||||
printf("[Core]\t\t[Thread] _webui_cb()... Stop.\n");
|
||||
#endif
|
||||
|
||||
// Free
|
||||
_webui_free_mem((void*)e.response);
|
||||
// Free event
|
||||
_webui_free_mem((void*)arg->element);
|
||||
_webui_free_mem((void*)arg->data);
|
||||
// Free event extras
|
||||
_webui_free_mem((void*)arg->webui_internal_id);
|
||||
_webui_free_mem((void*)arg->element_name);
|
||||
_webui_free_mem((void*)arg);
|
||||
|
||||
THREAD_RETURN
|
||||
|
@ -19,7 +19,6 @@
|
||||
#define WEBUI_HEADER_CLICK 0xFC // Click event
|
||||
#define WEBUI_HEADER_SWITCH 0xFB // Frontend refresh
|
||||
#define WEBUI_HEADER_CLOSE 0xFA // Close window
|
||||
#define WEBUI_HEADER_CALL_FUNC 0xF9 // Call a backend function
|
||||
#define WEBUI_MAX_ARRAY (512) // Max threads, servers, windows, pointers..
|
||||
#define WEBUI_MIN_PORT (10000) // Minimum socket port
|
||||
#define WEBUI_MAX_PORT (65500) // Should be less than 65535
|
||||
@ -34,6 +33,10 @@ typedef struct _webui_timer_t {
|
||||
struct timespec now;
|
||||
} _webui_timer_t;
|
||||
|
||||
typedef struct webui_event_core_t {
|
||||
char* response; // Callback response
|
||||
} webui_event_core_t;
|
||||
|
||||
typedef struct _webui_window_t {
|
||||
unsigned int window_number;
|
||||
bool server_running;
|
||||
@ -53,6 +56,7 @@ typedef struct _webui_window_t {
|
||||
unsigned int runtime;
|
||||
bool has_events;
|
||||
char* server_root_path;
|
||||
webui_event_core_t* event_core[WEBUI_MAX_ARRAY];
|
||||
#ifdef _WIN32
|
||||
HANDLE server_thread;
|
||||
#else
|
||||
@ -76,7 +80,7 @@ typedef struct _webui_core_t {
|
||||
struct mg_connection* mg_connections[WEBUI_MAX_ARRAY];
|
||||
bool initialized;
|
||||
void (*cb[WEBUI_MAX_ARRAY])(webui_event_t* e);
|
||||
void (*cb_interface[WEBUI_MAX_ARRAY])(void*, unsigned int, char*, char*, char*);
|
||||
void (*cb_interface[WEBUI_MAX_ARRAY])(void*, unsigned int, char*, char*, unsigned int);
|
||||
char* executable_path;
|
||||
void *ptr_list[WEBUI_MAX_ARRAY];
|
||||
unsigned int ptr_position;
|
||||
@ -84,14 +88,16 @@ typedef struct _webui_core_t {
|
||||
unsigned int current_browser;
|
||||
} _webui_core_t;
|
||||
|
||||
typedef struct _webui_cb_t {
|
||||
_webui_window_t* win;
|
||||
typedef struct _webui_cb_arg_t {
|
||||
// Event
|
||||
_webui_window_t* window;
|
||||
unsigned int event_type;
|
||||
char* element;
|
||||
char* data;
|
||||
unsigned int event_number;
|
||||
// Extras
|
||||
char* webui_internal_id;
|
||||
char* element_name;
|
||||
void* data;
|
||||
unsigned int data_len;
|
||||
int event_type;
|
||||
} _webui_cb_t;
|
||||
} _webui_cb_arg_t;
|
||||
|
||||
typedef struct _webui_mg_handler_t {
|
||||
struct mg_connection* c;
|
||||
@ -139,7 +145,7 @@ static void _webui_free_port(unsigned int port);
|
||||
char* _webui_get_current_path(void);
|
||||
static void _webui_window_receive(_webui_window_t* win, const char* packet, size_t len);
|
||||
static void _webui_window_send(_webui_window_t* win, char* packet, size_t packets_size);
|
||||
static void _webui_window_event(_webui_window_t* win, char* element_id, char* element, void* data, unsigned int data_len, int event_type);
|
||||
static void _webui_window_event(_webui_window_t* win, int event_type, char* element, char* data, unsigned int event_number, char* webui_internal_id);
|
||||
unsigned int _webui_window_get_number(_webui_window_t* win);
|
||||
static void _webui_window_open(_webui_window_t* win, char* link, unsigned int browser);
|
||||
int _webui_cmd_sync(char* cmd, bool show);
|
||||
@ -178,6 +184,7 @@ void* _webui_malloc(int size);
|
||||
static void _webui_sleep(long unsigned int ms);
|
||||
unsigned int _webui_find_the_best_browser(_webui_window_t* win);
|
||||
bool _webui_is_process_running(const char* process_name);
|
||||
unsigned int _webui_get_free_event_core_pos(_webui_window_t* win);
|
||||
|
||||
WEBUI_SERVER_START;
|
||||
WEBUI_CB;
|
||||
|
@ -267,7 +267,7 @@ The *e* corresponds to the word _Event_. `e` is a struct that has these elements
|
||||
|
||||
```c
|
||||
void* window; // Pointer to the window struct.
|
||||
unsigned int type; // Event type (WEBUI_EVENT_MOUSE_CLICK, WEBUI_EVENT_NAVIGATION...).
|
||||
unsigned int event_type; // Event type (WEBUI_EVENT_MOUSE_CLICK, WEBUI_EVENT_NAVIGATION...).
|
||||
char* element; // HTML element ID.
|
||||
char* data; // The data are coming from JavaScript, if any.
|
||||
char* response; // Internally used by webui_return_xxx().
|
||||
@ -278,13 +278,13 @@ void my_function(webui_event_t* e){
|
||||
|
||||
printf("Hi!, You clicked on %s element\n", e.element);
|
||||
|
||||
if(e->type == WEBUI_EVENT_CONNECTED)
|
||||
if(e->event_type == WEBUI_EVENT_CONNECTED)
|
||||
printf("Connected. \n");
|
||||
else if(e->type == WEBUI_EVENT_DISCONNECTED)
|
||||
else if(e->event_type == WEBUI_EVENT_DISCONNECTED)
|
||||
printf("Disconnected. \n");
|
||||
else if(e->type == WEBUI_EVENT_MOUSE_CLICK)
|
||||
else if(e->event_type == WEBUI_EVENT_MOUSE_CLICK)
|
||||
printf("Click. \n");
|
||||
else if(e->type == WEBUI_EVENT_NAVIGATION)
|
||||
else if(e->event_type == WEBUI_EVENT_NAVIGATION)
|
||||
printf("Starting navigation to: %s \n", (char *)e->data);
|
||||
|
||||
// Send back a response to JavaScript
|
||||
|
@ -287,7 +287,7 @@ The *e* corresponds to the word _Event_. `e` is a struct that has these elements
|
||||
|
||||
```cpp
|
||||
void* window; // Pointer to the window struct.
|
||||
unsigned int type; // Event type (WEBUI_EVENT_MOUSE_CLICK, WEBUI_EVENT_NAVIGATION...).
|
||||
unsigned int event_type; // Event type (WEBUI_EVENT_MOUSE_CLICK, WEBUI_EVENT_NAVIGATION...).
|
||||
char* element; // HTML element ID.
|
||||
char* data; // The data are coming from JavaScript, if any.
|
||||
char* response; // Internally used by webui::return_xxx().
|
||||
@ -298,13 +298,13 @@ void my_function(webui_event_t* e){
|
||||
|
||||
std::cout << "Hi!, You clicked on " << e.element << std::endl;
|
||||
|
||||
if (e->type == WEBUI_EVENT_CONNECTED)
|
||||
if (e->event_type == WEBUI_EVENT_CONNECTED)
|
||||
std::cout << "Connected." << std::endl;
|
||||
else if (e->type == WEBUI_EVENT_DISCONNECTED)
|
||||
else if (e->event_type == WEBUI_EVENT_DISCONNECTED)
|
||||
std::cout << "Disconnected." << std::endl;
|
||||
else if (e->type == WEBUI_EVENT_MOUSE_CLICK)
|
||||
else if (e->event_type == WEBUI_EVENT_MOUSE_CLICK)
|
||||
std::cout << "Click." << std::endl;
|
||||
else if (e->type == WEBUI_EVENT_NAVIGATION)
|
||||
else if (e->event_type == WEBUI_EVENT_NAVIGATION)
|
||||
std::cout << "Starting navigation to: " << e->data << std::endl;
|
||||
|
||||
// Send back a response to JavaScript
|
||||
|
@ -187,7 +187,7 @@ The *e* corresponds to the word _Event_. `e` is a struct that has these elements
|
||||
|
||||
```python
|
||||
window; # The window object.
|
||||
type; # Integer: Event type (EVENT_MOUSE_CLICK, EVENT_NAVIGATION...).
|
||||
event_type; # Integer: Event type (EVENT_MOUSE_CLICK, EVENT_NAVIGATION...).
|
||||
element; # String: HTML element ID.
|
||||
data; # String: The data are coming from JavaScript, if any.
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user