mirror of
https://github.com/webui-dev/webui.git
synced 2024-09-11 14:06:09 +03:00
Public get_new_window_id
# New * `webui_get_new_window_id` is now public * Updating C++ examples
This commit is contained in:
parent
71eeb25453
commit
bc5e5b2a56
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -145,6 +145,8 @@ typedef struct webui_event_t {
|
||||
WEBUI_EXPORT size_t webui_new_window(void);
|
||||
// Create a new webui window object.
|
||||
WEBUI_EXPORT void webui_new_window_id(size_t window_number);
|
||||
// Get a free window ID that can be used with `webui_new_window_id()`
|
||||
WEBUI_EXPORT size_t webui_get_new_window_id(void);
|
||||
// Bind a specific html element click event with a function. Empty element means all events.
|
||||
WEBUI_EXPORT size_t webui_bind(size_t window, const char* element, void (*func)(webui_event_t* e));
|
||||
// Show a window using a embedded HTML, or a file. If the window is already opened then it will be refreshed.
|
||||
|
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.
@ -145,6 +145,8 @@ typedef struct webui_event_t {
|
||||
WEBUI_EXPORT size_t webui_new_window(void);
|
||||
// Create a new webui window object.
|
||||
WEBUI_EXPORT void webui_new_window_id(size_t window_number);
|
||||
// Get a free window ID that can be used with `webui_new_window_id()`
|
||||
WEBUI_EXPORT size_t webui_get_new_window_id(void);
|
||||
// Bind a specific html element click event with a function. Empty element means all events.
|
||||
WEBUI_EXPORT size_t webui_bind(size_t window, const char* element, void (*func)(webui_event_t* e));
|
||||
// Show a window using a embedded HTML, or a file. If the window is already opened then it will be refreshed.
|
||||
|
@ -153,8 +153,8 @@ namespace webui {
|
||||
|
||||
// -- JavaScript ----------------------
|
||||
// Quickly run a JavaScript (no response waiting).
|
||||
bool run(std::string script) {
|
||||
return webui_run(this->webui_window, script.c_str());
|
||||
void run(std::string script) {
|
||||
webui_run(this->webui_window, script.c_str());
|
||||
}
|
||||
|
||||
// Run a JavaScript, and get the response back (Make sure your local buffer can hold the response).
|
||||
@ -227,6 +227,23 @@ namespace webui {
|
||||
void set_timeout(unsigned int second) {
|
||||
webui_set_timeout(second);
|
||||
}
|
||||
|
||||
// Base64 encoding. Use this to safely send text based data to the UI. If it fails it will return NULL.
|
||||
std::string encode(std::string str) {
|
||||
std::string ret = std::string(webui_encode(str.c_str()));
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Base64 decoding. Use this to safely decode received Base64 text from the UI. If it fails it will return NULL.
|
||||
std::string decode(std::string str) {
|
||||
std::string ret = std::string(webui_decode(str.c_str()));
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Safely free a buffer allocated by WebUI, for example when using webui_encode().
|
||||
void free(void* ptr) {
|
||||
webui_free(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* _WEBUI_HPP */
|
||||
|
Binary file not shown.
@ -145,6 +145,8 @@ typedef struct webui_event_t {
|
||||
WEBUI_EXPORT size_t webui_new_window(void);
|
||||
// Create a new webui window object.
|
||||
WEBUI_EXPORT void webui_new_window_id(size_t window_number);
|
||||
// Get a free window ID that can be used with `webui_new_window_id()`
|
||||
WEBUI_EXPORT size_t webui_get_new_window_id(void);
|
||||
// Bind a specific html element click event with a function. Empty element means all events.
|
||||
WEBUI_EXPORT size_t webui_bind(size_t window, const char* element, void (*func)(webui_event_t* e));
|
||||
// Show a window using a embedded HTML, or a file. If the window is already opened then it will be refreshed.
|
||||
|
@ -153,8 +153,8 @@ namespace webui {
|
||||
|
||||
// -- JavaScript ----------------------
|
||||
// Quickly run a JavaScript (no response waiting).
|
||||
bool run(std::string script) {
|
||||
return webui_run(this->webui_window, script.c_str());
|
||||
void run(std::string script) {
|
||||
webui_run(this->webui_window, script.c_str());
|
||||
}
|
||||
|
||||
// Run a JavaScript, and get the response back (Make sure your local buffer can hold the response).
|
||||
@ -227,6 +227,23 @@ namespace webui {
|
||||
void set_timeout(unsigned int second) {
|
||||
webui_set_timeout(second);
|
||||
}
|
||||
|
||||
// Base64 encoding. Use this to safely send text based data to the UI. If it fails it will return NULL.
|
||||
std::string encode(std::string str) {
|
||||
std::string ret = std::string(webui_encode(str.c_str()));
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Base64 decoding. Use this to safely decode received Base64 text from the UI. If it fails it will return NULL.
|
||||
std::string decode(std::string str) {
|
||||
std::string ret = std::string(webui_decode(str.c_str()));
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Safely free a buffer allocated by WebUI, for example when using webui_encode().
|
||||
void free(void* ptr) {
|
||||
webui_free(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* _WEBUI_HPP */
|
||||
|
Binary file not shown.
@ -145,6 +145,8 @@ typedef struct webui_event_t {
|
||||
WEBUI_EXPORT size_t webui_new_window(void);
|
||||
// Create a new webui window object.
|
||||
WEBUI_EXPORT void webui_new_window_id(size_t window_number);
|
||||
// Get a free window ID that can be used with `webui_new_window_id()`
|
||||
WEBUI_EXPORT size_t webui_get_new_window_id(void);
|
||||
// Bind a specific html element click event with a function. Empty element means all events.
|
||||
WEBUI_EXPORT size_t webui_bind(size_t window, const char* element, void (*func)(webui_event_t* e));
|
||||
// Show a window using a embedded HTML, or a file. If the window is already opened then it will be refreshed.
|
||||
|
Binary file not shown.
@ -145,6 +145,8 @@ typedef struct webui_event_t {
|
||||
WEBUI_EXPORT size_t webui_new_window(void);
|
||||
// Create a new webui window object.
|
||||
WEBUI_EXPORT void webui_new_window_id(size_t window_number);
|
||||
// Get a free window ID that can be used with `webui_new_window_id()`
|
||||
WEBUI_EXPORT size_t webui_get_new_window_id(void);
|
||||
// Bind a specific html element click event with a function. Empty element means all events.
|
||||
WEBUI_EXPORT size_t webui_bind(size_t window, const char* element, void (*func)(webui_event_t* e));
|
||||
// Show a window using a embedded HTML, or a file. If the window is already opened then it will be refreshed.
|
||||
|
Binary file not shown.
Binary file not shown.
@ -145,6 +145,8 @@ typedef struct webui_event_t {
|
||||
WEBUI_EXPORT size_t webui_new_window(void);
|
||||
// Create a new webui window object.
|
||||
WEBUI_EXPORT void webui_new_window_id(size_t window_number);
|
||||
// Get a free window ID that can be used with `webui_new_window_id()`
|
||||
WEBUI_EXPORT size_t webui_get_new_window_id(void);
|
||||
// Bind a specific html element click event with a function. Empty element means all events.
|
||||
WEBUI_EXPORT size_t webui_bind(size_t window, const char* element, void (*func)(webui_event_t* e));
|
||||
// Show a window using a embedded HTML, or a file. If the window is already opened then it will be refreshed.
|
||||
|
@ -153,8 +153,8 @@ namespace webui {
|
||||
|
||||
// -- JavaScript ----------------------
|
||||
// Quickly run a JavaScript (no response waiting).
|
||||
bool run(std::string script) {
|
||||
return webui_run(this->webui_window, script.c_str());
|
||||
void run(std::string script) {
|
||||
webui_run(this->webui_window, script.c_str());
|
||||
}
|
||||
|
||||
// Run a JavaScript, and get the response back (Make sure your local buffer can hold the response).
|
||||
@ -227,6 +227,23 @@ namespace webui {
|
||||
void set_timeout(unsigned int second) {
|
||||
webui_set_timeout(second);
|
||||
}
|
||||
|
||||
// Base64 encoding. Use this to safely send text based data to the UI. If it fails it will return NULL.
|
||||
std::string encode(std::string str) {
|
||||
std::string ret = std::string(webui_encode(str.c_str()));
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Base64 decoding. Use this to safely decode received Base64 text from the UI. If it fails it will return NULL.
|
||||
std::string decode(std::string str) {
|
||||
std::string ret = std::string(webui_decode(str.c_str()));
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Safely free a buffer allocated by WebUI, for example when using webui_encode().
|
||||
void free(void* ptr) {
|
||||
webui_free(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* _WEBUI_HPP */
|
||||
|
36
src/webui.c
36
src/webui.c
@ -110,7 +110,7 @@ static const char* webui_javascript_bridge =
|
||||
" } else if(buffer8[1] === WEBUI_HEADER_SWITCH) { \n"
|
||||
" _webui_close(WEBUI_HEADER_SWITCH, data8utf8); \n"
|
||||
" } else if(buffer8[1] === WEBUI_HEADER_CLOSE) { \n"
|
||||
" _webui_close(WEBUI_HEADER_CLOSE); \n"
|
||||
" window.close(); \n"
|
||||
" } else if(buffer8[1] === WEBUI_HEADER_JS_QUICK || buffer8[1] === WEBUI_HEADER_JS) { \n"
|
||||
" data8utf8 = data8utf8.replace(/(?:\\r\\n|\\r|\\n)/g, \"\\\\n\"); \n"
|
||||
" if(_webui_log) \n"
|
||||
@ -445,7 +445,7 @@ size_t webui_new_window(void) {
|
||||
|
||||
// Get a new window number
|
||||
// starting from 1.
|
||||
size_t window_number = _webui_get_new_window_number();
|
||||
size_t window_number = webui_get_new_window_id();
|
||||
if(_webui_core.wins[window_number] != NULL)
|
||||
_webui_panic();
|
||||
|
||||
@ -467,6 +467,22 @@ size_t webui_new_window(void) {
|
||||
return (size_t)window_number;
|
||||
}
|
||||
|
||||
size_t webui_get_new_window_id(void) {
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
printf("[User] webui_get_new_window_id()...\n");
|
||||
#endif
|
||||
|
||||
for(size_t i = 1; i < WEBUI_MAX_ARRAY; i++) {
|
||||
if(_webui_core.wins[i] == NULL)
|
||||
return i;
|
||||
}
|
||||
|
||||
// We should never reach here
|
||||
_webui_panic();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void webui_new_window_id(size_t window_number) {
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
@ -4061,22 +4077,6 @@ static void _webui_wait_for_startup(void) {
|
||||
#endif
|
||||
}
|
||||
|
||||
static size_t _webui_get_new_window_number(void) {
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
printf("[Core]\t\t_webui_get_new_window_number()...\n");
|
||||
#endif
|
||||
|
||||
for(size_t i = 1; i < WEBUI_MAX_ARRAY; i++) {
|
||||
if(_webui_core.wins[i] == NULL)
|
||||
return i;
|
||||
}
|
||||
|
||||
// We should never reach here
|
||||
_webui_panic();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static size_t _webui_get_free_port(void) {
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
|
@ -138,7 +138,6 @@ static bool _webui_show(_webui_window_t* win, const char* content, size_t browse
|
||||
static size_t _webui_get_cb_index(char* webui_internal_id);
|
||||
static size_t _webui_set_cb_index(char* webui_internal_id);
|
||||
static size_t _webui_get_free_port(void);
|
||||
static size_t _webui_get_new_window_number(void);
|
||||
static void _webui_wait_for_startup(void);
|
||||
static void _webui_free_port(size_t port);
|
||||
static char* _webui_get_current_path(void);
|
||||
|
Loading…
Reference in New Issue
Block a user