2022-09-25 02:35:56 +03:00
|
|
|
/*
|
2024-06-05 20:15:29 +03:00
|
|
|
WebUI Library
|
2023-04-17 22:43:46 +03:00
|
|
|
http://webui.me
|
2023-05-13 17:47:42 +03:00
|
|
|
https://github.com/webui-dev/webui
|
2024-05-27 03:02:12 +03:00
|
|
|
Copyright (c) 2020-2024 Hassan Draga.
|
2023-05-05 04:41:03 +03:00
|
|
|
Licensed under MIT License.
|
2023-04-17 22:43:46 +03:00
|
|
|
All rights reserved.
|
|
|
|
Canada.
|
2022-09-25 02:35:56 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _WEBUI_H
|
|
|
|
#define _WEBUI_H
|
|
|
|
|
2024-06-25 20:06:30 +03:00
|
|
|
#define WEBUI_VERSION "2.5.0-beta.2"
|
2023-09-12 01:09:42 +03:00
|
|
|
|
|
|
|
// Max windows, servers and threads
|
2023-10-06 03:03:12 +03:00
|
|
|
#define WEBUI_MAX_IDS (256)
|
|
|
|
|
|
|
|
// Max allowed argument's index
|
|
|
|
#define WEBUI_MAX_ARG (16)
|
2023-04-17 22:43:46 +03:00
|
|
|
|
|
|
|
// Dynamic Library Exports
|
2022-09-25 02:35:56 +03:00
|
|
|
#if defined(_MSC_VER) || defined(__TINYC__)
|
2023-10-29 22:51:49 +03:00
|
|
|
#ifndef WEBUI_EXPORT
|
|
|
|
#define WEBUI_EXPORT __declspec(dllexport)
|
|
|
|
#endif
|
2022-09-25 02:35:56 +03:00
|
|
|
#else
|
2023-10-29 22:51:49 +03:00
|
|
|
#ifndef WEBUI_EXPORT
|
|
|
|
#define WEBUI_EXPORT extern
|
|
|
|
#endif
|
2022-09-25 02:35:56 +03:00
|
|
|
#endif
|
|
|
|
|
2024-01-29 05:44:01 +03:00
|
|
|
#if defined(_MSC_VER)
|
|
|
|
#define strdup _strdup
|
|
|
|
#endif
|
|
|
|
|
2022-10-20 02:48:47 +03:00
|
|
|
// -- C STD ---------------------------
|
2022-09-25 02:35:56 +03:00
|
|
|
#include <assert.h>
|
2023-10-08 02:48:44 +03:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
2022-09-25 02:35:56 +03:00
|
|
|
#include <stdint.h>
|
2023-10-08 02:48:44 +03:00
|
|
|
#include <stdio.h>
|
2022-09-25 02:35:56 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2022-10-20 02:48:47 +03:00
|
|
|
// -- Windows -------------------------
|
2022-09-25 02:35:56 +03:00
|
|
|
#ifdef _WIN32
|
2024-05-27 03:02:12 +03:00
|
|
|
#include <winsock2.h>
|
|
|
|
#include <ws2tcpip.h>
|
2023-10-29 22:51:49 +03:00
|
|
|
#ifndef WIN32_LEAN_AND_MEAN
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#endif
|
2024-06-09 23:29:35 +03:00
|
|
|
#ifndef CGO
|
|
|
|
#if defined(__GNUC__) || defined(__TINYC__)
|
|
|
|
#include <dirent.h>
|
|
|
|
#endif
|
2024-06-09 21:47:17 +03:00
|
|
|
#endif
|
2023-10-29 22:51:49 +03:00
|
|
|
#include <windows.h>
|
|
|
|
#include <direct.h>
|
|
|
|
#include <io.h>
|
|
|
|
#include <shellapi.h>
|
|
|
|
#include <tchar.h>
|
|
|
|
#include <tlhelp32.h>
|
|
|
|
#define WEBUI_GET_CURRENT_DIR _getcwd
|
|
|
|
#define WEBUI_FILE_EXIST _access
|
|
|
|
#define WEBUI_POPEN _popen
|
|
|
|
#define WEBUI_PCLOSE _pclose
|
|
|
|
#define WEBUI_MAX_PATH MAX_PATH
|
2022-09-25 02:35:56 +03:00
|
|
|
#endif
|
2023-04-17 22:43:46 +03:00
|
|
|
|
2022-10-20 02:48:47 +03:00
|
|
|
// -- Linux ---------------------------
|
2022-09-25 02:35:56 +03:00
|
|
|
#ifdef __linux__
|
2023-10-29 22:51:49 +03:00
|
|
|
#include <dirent.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <poll.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#define WEBUI_GET_CURRENT_DIR getcwd
|
|
|
|
#define WEBUI_FILE_EXIST access
|
|
|
|
#define WEBUI_POPEN popen
|
|
|
|
#define WEBUI_PCLOSE pclose
|
|
|
|
#define WEBUI_MAX_PATH PATH_MAX
|
2022-09-25 02:35:56 +03:00
|
|
|
#endif
|
2023-04-17 22:43:46 +03:00
|
|
|
|
2023-03-28 23:50:10 +03:00
|
|
|
// -- Apple ---------------------------
|
|
|
|
#ifdef __APPLE__
|
2023-10-29 22:51:49 +03:00
|
|
|
#include <dirent.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <poll.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/syslimits.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#define WEBUI_GET_CURRENT_DIR getcwd
|
|
|
|
#define WEBUI_FILE_EXIST access
|
|
|
|
#define WEBUI_POPEN popen
|
|
|
|
#define WEBUI_PCLOSE pclose
|
|
|
|
#define WEBUI_MAX_PATH PATH_MAX
|
2023-03-28 23:50:10 +03:00
|
|
|
#endif
|
2022-10-19 07:38:54 +03:00
|
|
|
|
2023-04-17 22:43:46 +03:00
|
|
|
// -- Enums ---------------------------
|
2024-06-02 15:45:29 +03:00
|
|
|
enum webui_browser {
|
2023-10-29 22:51:49 +03:00
|
|
|
NoBrowser = 0, // 0. No web browser
|
|
|
|
AnyBrowser = 1, // 1. Default recommended web browser
|
|
|
|
Chrome, // 2. Google Chrome
|
|
|
|
Firefox, // 3. Mozilla Firefox
|
|
|
|
Edge, // 4. Microsoft Edge
|
|
|
|
Safari, // 5. Apple Safari
|
|
|
|
Chromium, // 6. The Chromium Project
|
|
|
|
Opera, // 7. Opera Browser
|
|
|
|
Brave, // 8. The Brave Browser
|
|
|
|
Vivaldi, // 9. The Vivaldi Browser
|
|
|
|
Epic, // 10. The Epic Browser
|
|
|
|
Yandex, // 11. The Yandex Browser
|
|
|
|
ChromiumBased, // 12. Any Chromium based browser
|
2023-04-17 22:43:46 +03:00
|
|
|
};
|
|
|
|
|
2024-06-02 15:45:29 +03:00
|
|
|
enum webui_runtime {
|
2023-10-29 22:51:49 +03:00
|
|
|
None = 0, // 0. Prevent WebUI from using any runtime for .js and .ts files
|
|
|
|
Deno, // 1. Use Deno runtime for .js and .ts files
|
|
|
|
NodeJS, // 2. Use Nodejs runtime for .js files
|
2023-04-17 22:43:46 +03:00
|
|
|
};
|
|
|
|
|
2024-06-02 15:45:29 +03:00
|
|
|
enum webui_event {
|
2023-10-29 22:51:49 +03:00
|
|
|
WEBUI_EVENT_DISCONNECTED = 0, // 0. Window disconnection event
|
|
|
|
WEBUI_EVENT_CONNECTED, // 1. Window connection event
|
|
|
|
WEBUI_EVENT_MOUSE_CLICK, // 2. Mouse click event
|
|
|
|
WEBUI_EVENT_NAVIGATION, // 3. Window navigation event
|
|
|
|
WEBUI_EVENT_CALLBACK, // 4. Function call event
|
2023-04-17 22:43:46 +03:00
|
|
|
};
|
|
|
|
|
2024-05-28 21:28:32 +03:00
|
|
|
typedef enum {
|
2024-06-11 22:27:12 +03:00
|
|
|
// Control if `webui_show()`, `webui_show_browser()` and
|
|
|
|
// `webui_show_wv()` should wait for the window to connect
|
|
|
|
// before returns or not.
|
|
|
|
//
|
2024-05-28 21:28:32 +03:00
|
|
|
// Default: True
|
|
|
|
show_wait_connection = 0,
|
2024-06-11 22:27:12 +03:00
|
|
|
// Control if WebUI should block and process the UI events
|
|
|
|
// one a time in a single thread `True`, or process every
|
|
|
|
// event in a new non-blocking thread `False`. This updates
|
2024-06-13 01:04:29 +03:00
|
|
|
// all windows. You can use `webui_set_event_blocking()` for
|
2024-06-11 22:27:12 +03:00
|
|
|
// a specific single window update.
|
|
|
|
//
|
|
|
|
// Default: False
|
2024-06-13 01:04:29 +03:00
|
|
|
ui_event_blocking,
|
2024-06-02 15:45:29 +03:00
|
|
|
} webui_config;
|
2024-05-28 21:28:32 +03:00
|
|
|
|
2022-10-30 04:41:20 +03:00
|
|
|
// -- Structs -------------------------
|
|
|
|
typedef struct webui_event_t {
|
2023-10-29 22:51:49 +03:00
|
|
|
size_t window; // The window object number
|
|
|
|
size_t event_type; // Event type
|
|
|
|
char* element; // HTML element ID
|
|
|
|
size_t event_number; // Internal WebUI
|
|
|
|
size_t bind_id; // Bind ID
|
2022-10-30 04:41:20 +03:00
|
|
|
} webui_event_t;
|
2022-09-25 02:35:56 +03:00
|
|
|
|
2022-10-20 02:48:47 +03:00
|
|
|
// -- Definitions ---------------------
|
2023-09-12 01:09:42 +03:00
|
|
|
|
|
|
|
/**
|
2023-09-13 22:32:14 +03:00
|
|
|
* @brief Create a new WebUI window object.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-12 01:09:42 +03:00
|
|
|
* @return Returns the window number.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @example size_t myWindow = webui_new_window();
|
2023-09-12 01:09:42 +03:00
|
|
|
*/
|
2023-05-05 04:41:03 +03:00
|
|
|
WEBUI_EXPORT size_t webui_new_window(void);
|
2023-09-12 01:09:42 +03:00
|
|
|
|
|
|
|
/**
|
2023-09-13 22:32:14 +03:00
|
|
|
* @brief Create a new webui window object using a specified window number.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @param window_number The window number (should be > 0, and < WEBUI_MAX_IDS)
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2024-06-21 22:46:59 +03:00
|
|
|
* @return Returns the same window number if success.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @example size_t myWindow = webui_new_window_id(123);
|
2023-09-12 01:09:42 +03:00
|
|
|
*/
|
|
|
|
WEBUI_EXPORT size_t webui_new_window_id(size_t window_number);
|
|
|
|
|
|
|
|
/**
|
2023-10-27 07:26:54 +03:00
|
|
|
* @brief Get a free window number that can be used with
|
|
|
|
* `webui_new_window_id()`.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @return Returns the first available free window number. Starting from 1.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @example size_t myWindowNumber = webui_get_new_window_id();
|
2023-09-12 01:09:42 +03:00
|
|
|
*/
|
2023-05-09 14:48:27 +03:00
|
|
|
WEBUI_EXPORT size_t webui_get_new_window_id(void);
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2023-09-13 22:32:14 +03:00
|
|
|
/**
|
2023-10-27 07:26:54 +03:00
|
|
|
* @brief Bind a specific html element click event with a function. Empty
|
|
|
|
* element means all events.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @param window The window number
|
|
|
|
* @param element The HTML ID
|
|
|
|
* @param func The callback function
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @return Returns a unique bind ID.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @example webui_bind(myWindow, "myID", myFunction);
|
|
|
|
*/
|
2023-05-07 20:54:15 +03:00
|
|
|
WEBUI_EXPORT size_t webui_bind(size_t window, const char* element, void (*func)(webui_event_t* e));
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2024-02-13 11:07:53 +03:00
|
|
|
/**
|
2024-06-01 23:30:52 +03:00
|
|
|
* @brief Get the recommended web browser ID to use. If you
|
|
|
|
* are already using one, this function will return the same ID.
|
2024-02-13 11:07:53 +03:00
|
|
|
*
|
|
|
|
* @param window The window number
|
|
|
|
*
|
2024-06-01 23:30:52 +03:00
|
|
|
* @return Returns a web browser ID.
|
2024-02-13 11:07:53 +03:00
|
|
|
*
|
2024-06-01 23:30:52 +03:00
|
|
|
* @example size_t browserID = webui_get_best_browser(myWindow);
|
2024-02-13 11:07:53 +03:00
|
|
|
*/
|
|
|
|
WEBUI_EXPORT size_t webui_get_best_browser(size_t window);
|
|
|
|
|
2023-09-13 22:32:14 +03:00
|
|
|
/**
|
2023-10-27 07:26:54 +03:00
|
|
|
* @brief Show a window using embedded HTML, or a file. If the window is already
|
|
|
|
* open, it will be refreshed.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @param window The window number
|
2023-10-28 21:37:35 +03:00
|
|
|
* @param content The HTML, URL, Or a local file
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @return Returns True if showing the window is successed.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-10-27 07:26:54 +03:00
|
|
|
* @example webui_show(myWindow, "<html>...</html>"); | webui_show(myWindow,
|
2023-10-28 21:37:35 +03:00
|
|
|
* "index.html"); | webui_show(myWindow, "http://...");
|
2023-09-13 22:32:14 +03:00
|
|
|
*/
|
2023-05-05 04:41:03 +03:00
|
|
|
WEBUI_EXPORT bool webui_show(size_t window, const char* content);
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2023-09-13 22:32:14 +03:00
|
|
|
/**
|
|
|
|
* @brief Same as `webui_show()`. But using a specific web browser.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @param window The window number
|
|
|
|
* @param content The HTML, Or a local file
|
|
|
|
* @param browser The web browser to be used
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @return Returns True if showing the window is successed.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-10-27 07:26:54 +03:00
|
|
|
* @example webui_show_browser(myWindow, "<html>...</html>", Chrome); |
|
|
|
|
* webui_show(myWindow, "index.html", Firefox);
|
2023-09-13 22:32:14 +03:00
|
|
|
*/
|
2023-05-07 20:54:15 +03:00
|
|
|
WEBUI_EXPORT bool webui_show_browser(size_t window, const char* content, size_t browser);
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2024-05-27 03:02:12 +03:00
|
|
|
/**
|
|
|
|
* @brief Show a WebView window using embedded HTML, or a file. If the window is already
|
|
|
|
* open, it will be refreshed. Note: Win32 need `WebView2Loader.dll`.
|
|
|
|
*
|
|
|
|
* @param window The window number
|
|
|
|
* @param content The HTML, URL, Or a local file
|
|
|
|
*
|
|
|
|
* @return Returns True if showing the WebView window is successed.
|
|
|
|
*
|
|
|
|
* @example webui_show_wv(myWindow, "<html>...</html>"); | webui_show_wv(myWindow,
|
|
|
|
* "index.html"); | webui_show_wv(myWindow, "http://...");
|
|
|
|
*/
|
|
|
|
WEBUI_EXPORT bool webui_show_wv(size_t window, const char* content);
|
|
|
|
|
2023-09-13 22:32:14 +03:00
|
|
|
/**
|
2024-06-21 22:46:59 +03:00
|
|
|
* @brief Set the window in Kiosk mode (Full screen).
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @param window The window number
|
|
|
|
* @param status True or False
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @example webui_set_kiosk(myWindow, true);
|
|
|
|
*/
|
2023-05-05 04:41:03 +03:00
|
|
|
WEBUI_EXPORT void webui_set_kiosk(size_t window, bool status);
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2024-06-24 15:27:28 +03:00
|
|
|
/**
|
|
|
|
* @brief Set the window high contrast support. It would be useful when default high contrast support of browser is not working fine or you want to build better high contrast theme by CSS.
|
|
|
|
*
|
|
|
|
* @param window The window number
|
|
|
|
* @param status True or False
|
|
|
|
*
|
|
|
|
* @example webui_set_high_contrast_support(myWindow, true);
|
|
|
|
*/
|
|
|
|
WEBUI_EXPORT void webui_set_high_contrast_support(size_t window, bool status);
|
|
|
|
|
2024-06-24 16:25:53 +03:00
|
|
|
/**
|
|
|
|
* @brief Get user high contrast preference.
|
|
|
|
*
|
|
|
|
* @return Returns True if user is using high contrast theme
|
|
|
|
*
|
|
|
|
* @example webui_user_prefers_high_contrast();
|
|
|
|
*/
|
|
|
|
bool webui_user_prefers_high_contrast();
|
|
|
|
|
2023-09-13 22:32:14 +03:00
|
|
|
/**
|
|
|
|
* @brief Wait until all opened windows get closed.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @example webui_wait();
|
|
|
|
*/
|
2023-04-17 22:43:46 +03:00
|
|
|
WEBUI_EXPORT void webui_wait(void);
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2023-09-13 22:32:14 +03:00
|
|
|
/**
|
|
|
|
* @brief Close a specific window only. The window object will still exist.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @param window The window number
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @example webui_close(myWindow);
|
|
|
|
*/
|
2023-05-05 04:41:03 +03:00
|
|
|
WEBUI_EXPORT void webui_close(size_t window);
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2023-09-13 22:32:14 +03:00
|
|
|
/**
|
|
|
|
* @brief Close a specific window and free all memory resources.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @param window The window number
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @example webui_destroy(myWindow);
|
|
|
|
*/
|
2023-05-07 20:54:15 +03:00
|
|
|
WEBUI_EXPORT void webui_destroy(size_t window);
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2023-09-13 22:32:14 +03:00
|
|
|
/**
|
|
|
|
* @brief Close all open windows. `webui_wait()` will return (Break).
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @example webui_exit();
|
|
|
|
*/
|
2023-04-17 22:43:46 +03:00
|
|
|
WEBUI_EXPORT void webui_exit(void);
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2023-09-13 22:32:14 +03:00
|
|
|
/**
|
|
|
|
* @brief Set the web-server root folder path for a specific window.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @param window The window number
|
|
|
|
* @param path The local folder full path
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @example webui_set_root_folder(myWindow, "/home/Foo/Bar/");
|
|
|
|
*/
|
2023-05-28 03:30:31 +03:00
|
|
|
WEBUI_EXPORT bool webui_set_root_folder(size_t window, const char* path);
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2023-09-13 22:32:14 +03:00
|
|
|
/**
|
2023-10-27 07:26:54 +03:00
|
|
|
* @brief Set the web-server root folder path for all windows. Should be used
|
|
|
|
* before `webui_show()`.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @param path The local folder full path
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @example webui_set_default_root_folder("/home/Foo/Bar/");
|
|
|
|
*/
|
2023-08-25 04:54:13 +03:00
|
|
|
WEBUI_EXPORT bool webui_set_default_root_folder(const char* path);
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2023-09-13 22:32:14 +03:00
|
|
|
/**
|
|
|
|
* @brief Set a custom handler to serve files.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @param window The window number
|
2023-10-27 07:26:54 +03:00
|
|
|
* @param handler The handler function: `void myHandler(const char* filename,
|
|
|
|
* int* length)`
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @example webui_set_file_handler(myWindow, myHandlerFunction);
|
|
|
|
*/
|
2023-06-26 19:11:03 +03:00
|
|
|
WEBUI_EXPORT void webui_set_file_handler(size_t window, const void* (*handler)(const char* filename, int* length));
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2023-09-13 22:32:14 +03:00
|
|
|
/**
|
|
|
|
* @brief Check if the specified window is still running.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @param window The window number
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @example webui_is_shown(myWindow);
|
|
|
|
*/
|
2023-05-05 04:41:03 +03:00
|
|
|
WEBUI_EXPORT bool webui_is_shown(size_t window);
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2023-09-13 22:32:14 +03:00
|
|
|
/**
|
2024-06-21 22:46:59 +03:00
|
|
|
* @brief Set the maximum time in seconds to wait for the window to connect. This effect `show()` and `wait()`.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @param second The timeout in seconds
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @example webui_set_timeout(30);
|
|
|
|
*/
|
2023-05-07 20:54:15 +03:00
|
|
|
WEBUI_EXPORT void webui_set_timeout(size_t second);
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2023-09-13 22:32:14 +03:00
|
|
|
/**
|
|
|
|
* @brief Set the default embedded HTML favicon.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @param window The window number
|
|
|
|
* @param icon The icon as string: `<svg>...</svg>`
|
|
|
|
* @param icon_type The icon type: `image/svg+xml`
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @example webui_set_icon(myWindow, "<svg>...</svg>", "image/svg+xml");
|
|
|
|
*/
|
2023-05-05 04:41:03 +03:00
|
|
|
WEBUI_EXPORT void webui_set_icon(size_t window, const char* icon, const char* icon_type);
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2023-09-13 22:32:14 +03:00
|
|
|
/**
|
2024-06-21 22:46:59 +03:00
|
|
|
* @brief Encode text to Base64. The returned buffer need to be freed.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @param str The string to encode (Should be null terminated)
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2024-06-21 22:46:59 +03:00
|
|
|
* @return Returns the base64 encoded string
|
|
|
|
*
|
|
|
|
* @example char* base64 = webui_encode("Foo Bar");
|
2023-09-13 22:32:14 +03:00
|
|
|
*/
|
2023-09-12 00:18:31 +03:00
|
|
|
WEBUI_EXPORT char* webui_encode(const char* str);
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2023-09-13 22:32:14 +03:00
|
|
|
/**
|
2024-06-21 22:46:59 +03:00
|
|
|
* @brief Decode a Base64 encoded text. The returned buffer need to be freed.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @param str The string to decode (Should be null terminated)
|
2024-06-21 22:46:59 +03:00
|
|
|
*
|
|
|
|
* @return Returns the base64 decoded string
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2024-06-21 22:46:59 +03:00
|
|
|
* @example char* str = webui_decode("SGVsbG8=");
|
2023-09-13 22:32:14 +03:00
|
|
|
*/
|
2023-09-12 00:18:31 +03:00
|
|
|
WEBUI_EXPORT char* webui_decode(const char* str);
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2023-09-13 22:32:14 +03:00
|
|
|
/**
|
|
|
|
* @brief Safely free a buffer allocated by WebUI using `webui_malloc()`.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @param ptr The buffer to be freed
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @example webui_free(myBuffer);
|
|
|
|
*/
|
2023-09-12 00:18:31 +03:00
|
|
|
WEBUI_EXPORT void webui_free(void* ptr);
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2023-09-13 22:32:14 +03:00
|
|
|
/**
|
2023-10-27 07:26:54 +03:00
|
|
|
* @brief Safely allocate memory using the WebUI memory management system. It
|
|
|
|
* can be safely freed using `webui_free()` at any time.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @param size The size of memory in bytes
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-10-29 22:51:49 +03:00
|
|
|
* @example char* myBuffer = (char*)webui_malloc(1024);
|
2023-09-13 22:32:14 +03:00
|
|
|
*/
|
2023-09-12 00:18:31 +03:00
|
|
|
WEBUI_EXPORT void* webui_malloc(size_t size);
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2023-09-13 22:32:14 +03:00
|
|
|
/**
|
|
|
|
* @brief Safely send raw data to the UI.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @param window The window number
|
2023-10-27 07:26:54 +03:00
|
|
|
* @param function The JavaScript function to receive raw data: `function
|
|
|
|
* myFunc(myData){}`
|
2023-09-13 22:32:14 +03:00
|
|
|
* @param raw The raw data buffer
|
|
|
|
* @param size The raw data size in bytes
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @example webui_send_raw(myWindow, "myJavascriptFunction", myBuffer, 64);
|
|
|
|
*/
|
2023-09-12 00:18:31 +03:00
|
|
|
WEBUI_EXPORT void webui_send_raw(size_t window, const char* function, const void* raw, size_t size);
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2023-09-13 22:32:14 +03:00
|
|
|
/**
|
|
|
|
* @brief Set a window in hidden mode. Should be called before `webui_show()`.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @param window The window number
|
|
|
|
* @param status The status: True or False
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @example webui_set_hide(myWindow, True);
|
|
|
|
*/
|
2023-09-12 00:18:31 +03:00
|
|
|
WEBUI_EXPORT void webui_set_hide(size_t window, bool status);
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2023-09-13 22:32:14 +03:00
|
|
|
/**
|
|
|
|
* @brief Set the window size.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @param window The window number
|
|
|
|
* @param width The window width
|
|
|
|
* @param height The window height
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @example webui_set_size(myWindow, 800, 600);
|
|
|
|
*/
|
2023-09-12 00:18:31 +03:00
|
|
|
WEBUI_EXPORT void webui_set_size(size_t window, unsigned int width, unsigned int height);
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2023-09-13 22:32:14 +03:00
|
|
|
/**
|
|
|
|
* @brief Set the window position.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @param window The window number
|
|
|
|
* @param x The window X
|
|
|
|
* @param y The window Y
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-13 22:32:14 +03:00
|
|
|
* @example webui_set_position(myWindow, 100, 100);
|
|
|
|
*/
|
2023-09-12 00:18:31 +03:00
|
|
|
WEBUI_EXPORT void webui_set_position(size_t window, unsigned int x, unsigned int y);
|
WebUI v2.1.0
#New Features
* Supporting more web browsers
* Search for web browsers in Windows Reg.
* Using the same show() function for HTML script, files, and refresh content
* Support Chrome on macOS
#Breaking code
* Switching from `webui_show(win, html, browser);` to `webui_show(win, content);`, and it's used for HTML, files, and reload the window
* Removing `webui_show_cpy()`, `webui_refresh()`, `webui_refresh_cpy()`
2023-03-29 06:00:09 +03:00
|
|
|
|
2023-09-20 02:34:09 +03:00
|
|
|
/**
|
2023-10-27 07:26:54 +03:00
|
|
|
* @brief Set the web browser profile to use. An empty `name` and `path` means
|
|
|
|
* the default user profile. Need to be called before `webui_show()`.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-20 02:34:09 +03:00
|
|
|
* @param window The window number
|
|
|
|
* @param name The web browser profile name
|
|
|
|
* @param path The web browser profile full path
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-10-27 07:26:54 +03:00
|
|
|
* @example webui_set_profile(myWindow, "Bar", "/Home/Foo/Bar"); |
|
|
|
|
* webui_set_profile(myWindow, "", "");
|
2023-09-20 02:34:09 +03:00
|
|
|
*/
|
|
|
|
WEBUI_EXPORT void webui_set_profile(size_t window, const char* name, const char* path);
|
|
|
|
|
2024-01-05 04:16:11 +03:00
|
|
|
/**
|
2024-06-21 22:46:59 +03:00
|
|
|
* @brief Set the web browser proxy server to use. Need to be called before `webui_show()`.
|
2024-01-05 04:16:11 +03:00
|
|
|
*
|
|
|
|
* @param window The window number
|
|
|
|
* @param proxy_server The web browser proxy_server
|
|
|
|
*
|
|
|
|
* @example webui_set_proxy(myWindow, "http://127.0.0.1:8888");
|
|
|
|
*/
|
|
|
|
WEBUI_EXPORT void webui_set_proxy(size_t window, const char* proxy_server);
|
|
|
|
|
2023-09-21 08:21:04 +03:00
|
|
|
/**
|
2024-06-21 22:46:59 +03:00
|
|
|
* @brief Get current URL of a running window.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-21 08:21:04 +03:00
|
|
|
* @param window The window number
|
|
|
|
*
|
2023-09-21 23:36:11 +03:00
|
|
|
* @return Returns the full URL string
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-21 23:36:11 +03:00
|
|
|
* @example const char* url = webui_get_url(myWindow);
|
2023-09-21 08:21:04 +03:00
|
|
|
*/
|
2023-09-21 23:36:11 +03:00
|
|
|
WEBUI_EXPORT const char* webui_get_url(size_t window);
|
2023-09-21 08:21:04 +03:00
|
|
|
|
2023-11-30 02:23:35 +03:00
|
|
|
/**
|
2024-06-21 22:46:59 +03:00
|
|
|
* @brief Allow a specific window address to be accessible from a public network.
|
2023-11-30 02:23:35 +03:00
|
|
|
*
|
|
|
|
* @param window The window number
|
|
|
|
* @param status True or False
|
|
|
|
*
|
|
|
|
* @example webui_set_public(myWindow, true);
|
|
|
|
*/
|
|
|
|
WEBUI_EXPORT void webui_set_public(size_t window, bool status);
|
|
|
|
|
2023-09-27 01:59:25 +03:00
|
|
|
/**
|
2024-06-21 22:46:59 +03:00
|
|
|
* @brief Navigate to a specific URL.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-27 01:59:25 +03:00
|
|
|
* @param window The window number
|
|
|
|
* @param url Full HTTP URL
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-27 01:59:25 +03:00
|
|
|
* @example webui_navigate(myWindow, "http://domain.com");
|
|
|
|
*/
|
|
|
|
WEBUI_EXPORT void webui_navigate(size_t window, const char* url);
|
|
|
|
|
2023-09-30 01:36:57 +03:00
|
|
|
/**
|
2023-09-30 23:26:58 +03:00
|
|
|
* @brief Free all memory resources. Should be called only at the end.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-30 23:26:58 +03:00
|
|
|
* @example
|
|
|
|
* webui_wait();
|
|
|
|
* webui_clean();
|
2023-09-30 01:36:57 +03:00
|
|
|
*/
|
2024-03-23 16:05:59 +03:00
|
|
|
WEBUI_EXPORT void webui_clean(void);
|
2023-09-30 01:36:57 +03:00
|
|
|
|
2023-09-30 23:26:58 +03:00
|
|
|
/**
|
2024-06-21 22:46:59 +03:00
|
|
|
* @brief Delete all local web-browser profiles folder. It should be called at the
|
2023-10-27 07:26:54 +03:00
|
|
|
* end.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-30 23:26:58 +03:00
|
|
|
* @example
|
|
|
|
* webui_wait();
|
|
|
|
* webui_delete_all_profiles();
|
|
|
|
* webui_clean();
|
|
|
|
*/
|
2024-03-23 16:05:59 +03:00
|
|
|
WEBUI_EXPORT void webui_delete_all_profiles(void);
|
2023-09-30 23:26:58 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Delete a specific window web-browser local folder profile.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-30 23:26:58 +03:00
|
|
|
* @param window The window number
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-09-30 23:26:58 +03:00
|
|
|
* @example
|
|
|
|
* webui_wait();
|
|
|
|
* webui_delete_profile(myWindow);
|
|
|
|
* webui_clean();
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-10-27 07:26:54 +03:00
|
|
|
* @note This can break functionality of other windows if using the same
|
|
|
|
* web-browser.
|
2023-09-30 23:26:58 +03:00
|
|
|
*/
|
|
|
|
WEBUI_EXPORT void webui_delete_profile(size_t window);
|
|
|
|
|
2023-10-01 20:31:22 +03:00
|
|
|
/**
|
2023-10-27 07:26:54 +03:00
|
|
|
* @brief Get the ID of the parent process (The web browser may re-create
|
|
|
|
* another new process).
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-10-01 20:31:22 +03:00
|
|
|
* @param window The window number
|
|
|
|
*
|
|
|
|
* @return Returns the the parent process id as integer
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-10-01 20:31:22 +03:00
|
|
|
* @example size_t id = webui_get_parent_process_id(myWindow);
|
|
|
|
*/
|
2023-10-01 12:43:54 +03:00
|
|
|
WEBUI_EXPORT size_t webui_get_parent_process_id(size_t window);
|
|
|
|
|
2023-10-01 20:31:22 +03:00
|
|
|
/**
|
|
|
|
* @brief Get the ID of the last child process.
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-10-01 20:31:22 +03:00
|
|
|
* @param window The window number
|
|
|
|
*
|
|
|
|
* @return Returns the the child process id as integer
|
2023-10-08 02:48:44 +03:00
|
|
|
*
|
2023-10-01 20:31:22 +03:00
|
|
|
* @example size_t id = webui_get_child_process_id(myWindow);
|
|
|
|
*/
|
2023-10-01 12:43:54 +03:00
|
|
|
WEBUI_EXPORT size_t webui_get_child_process_id(size_t window);
|
|
|
|
|
2023-10-28 22:18:55 +03:00
|
|
|
/**
|
2024-06-21 22:46:59 +03:00
|
|
|
* @brief Set a custom web-server/websocket network port to be used by WebUI.
|
2023-10-28 22:18:55 +03:00
|
|
|
* This can be useful to determine the HTTP link of `webui.js` in case
|
2024-06-21 22:46:59 +03:00
|
|
|
* you are trying to use WebUI with an external web-server like NGNIX.
|
2023-10-28 22:18:55 +03:00
|
|
|
*
|
|
|
|
* @param window The window number
|
|
|
|
* @param port The web-server network port WebUI should use
|
|
|
|
*
|
|
|
|
* @return Returns True if the port is free and usable by WebUI
|
|
|
|
*
|
|
|
|
* @example bool ret = webui_set_port(myWindow, 8080);
|
|
|
|
*/
|
|
|
|
WEBUI_EXPORT bool webui_set_port(size_t window, size_t port);
|
|
|
|
|
2024-05-28 21:28:32 +03:00
|
|
|
/**
|
|
|
|
* @brief Control the WebUI behaviour. It's better to call at the beginning.
|
|
|
|
*
|
2024-06-02 15:45:29 +03:00
|
|
|
* @param option The desired option from `webui_config` enum
|
2024-05-28 21:28:32 +03:00
|
|
|
* @param status The status of the option, `true` or `false`
|
|
|
|
*
|
|
|
|
* @example webui_config(show_wait_connection, false);
|
|
|
|
*/
|
2024-06-02 19:31:36 +03:00
|
|
|
WEBUI_EXPORT void webui_set_config(webui_config option, bool status);
|
2024-05-28 21:28:32 +03:00
|
|
|
|
2024-06-11 22:27:12 +03:00
|
|
|
/**
|
|
|
|
* @brief Control if UI events comming from this window should be processed
|
|
|
|
* one a time in a single blocking thread `True`, or process every event in
|
|
|
|
* a new non-blocking thread `False`. This update single window. You can use
|
2024-06-13 01:04:29 +03:00
|
|
|
* `webui_set_config(ui_event_blocking, ...)` to update all windows.
|
2024-06-11 22:27:12 +03:00
|
|
|
*
|
|
|
|
* @param window The window number
|
|
|
|
* @param status The blocking status `true` or `false`
|
|
|
|
*
|
2024-06-13 01:04:29 +03:00
|
|
|
* @example webui_set_event_blocking(myWindow, true);
|
2024-06-11 22:27:12 +03:00
|
|
|
*/
|
2024-06-13 01:04:29 +03:00
|
|
|
WEBUI_EXPORT void webui_set_event_blocking(size_t window, bool status);
|
2024-06-11 22:27:12 +03:00
|
|
|
|
2023-10-27 02:00:56 +03:00
|
|
|
// -- SSL/TLS -------------------------
|
|
|
|
|
|
|
|
/**
|
2023-10-27 07:26:54 +03:00
|
|
|
* @brief Set the SSL/TLS certificate and the private key content, both in PEM
|
|
|
|
* format. This works only with `webui-2-secure` library. If set empty WebUI
|
|
|
|
* will generate a self-signed certificate.
|
2023-10-27 02:00:56 +03:00
|
|
|
*
|
|
|
|
* @param certificate_pem The SSL/TLS certificate content in PEM format
|
|
|
|
* @param private_key_pem The private key content in PEM format
|
|
|
|
*
|
|
|
|
* @return Returns True if the certificate and the key are valid.
|
|
|
|
*
|
2023-10-27 07:26:54 +03:00
|
|
|
* @example bool ret = webui_set_tls_certificate("-----BEGIN
|
|
|
|
* CERTIFICATE-----\n...", "-----BEGIN PRIVATE KEY-----\n...");
|
2023-10-27 02:00:56 +03:00
|
|
|
*/
|
2023-10-22 00:16:46 +03:00
|
|
|
WEBUI_EXPORT bool webui_set_tls_certificate(const char* certificate_pem, const char* private_key_pem);
|
|
|
|
|
2023-04-17 22:43:46 +03:00
|
|
|
// -- JavaScript ----------------------
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2023-10-29 22:51:49 +03:00
|
|
|
/**
|
|
|
|
* @brief Run JavaScript without waiting for the response.
|
|
|
|
*
|
|
|
|
* @param window The window number
|
|
|
|
* @param script The JavaScript to be run
|
|
|
|
*
|
|
|
|
* @example webui_run(myWindow, "alert('Hello');");
|
|
|
|
*/
|
2023-05-09 06:03:41 +03:00
|
|
|
WEBUI_EXPORT void webui_run(size_t window, const char* script);
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2023-10-29 22:51:49 +03:00
|
|
|
/**
|
|
|
|
* @brief Run JavaScript and get the response back.
|
|
|
|
* Make sure your local buffer can hold the response.
|
|
|
|
*
|
|
|
|
* @param window The window number
|
|
|
|
* @param script The JavaScript to be run
|
|
|
|
* @param timeout The execution timeout
|
|
|
|
* @param buffer The local buffer to hold the response
|
|
|
|
* @param buffer_length The local buffer size
|
|
|
|
*
|
|
|
|
* @return Returns True if there is no execution error
|
|
|
|
*
|
|
|
|
* @example bool err = webui_script(myWindow, "return 4 + 6;", 0, myBuffer, myBufferSize);
|
|
|
|
*/
|
|
|
|
WEBUI_EXPORT bool webui_script(size_t window, const char* script, size_t timeout,
|
|
|
|
char* buffer, size_t buffer_length);
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2023-10-29 22:51:49 +03:00
|
|
|
/**
|
|
|
|
* @brief Chose between Deno and Nodejs as runtime for .js and .ts files.
|
|
|
|
*
|
|
|
|
* @param window The window number
|
2024-06-21 22:46:59 +03:00
|
|
|
* @param runtime Deno | Nodejs | None
|
2023-10-29 22:51:49 +03:00
|
|
|
*
|
|
|
|
* @example webui_set_runtime(myWindow, Deno);
|
|
|
|
*/
|
2023-05-07 20:54:15 +03:00
|
|
|
WEBUI_EXPORT void webui_set_runtime(size_t window, size_t runtime);
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2024-05-30 00:44:03 +03:00
|
|
|
/**
|
|
|
|
* @brief Get how many arguments there are in an event.
|
|
|
|
*
|
|
|
|
* @param e The event struct
|
|
|
|
*
|
|
|
|
* @return Returns the arguments count.
|
|
|
|
*
|
|
|
|
* @example size_t count = webui_get_count(e);
|
|
|
|
*/
|
|
|
|
WEBUI_EXPORT size_t webui_get_count(webui_event_t* e);
|
|
|
|
|
2023-10-29 22:51:49 +03:00
|
|
|
/**
|
2024-06-21 22:46:59 +03:00
|
|
|
* @brief Get an argument as integer at a specific index.
|
2023-10-29 22:51:49 +03:00
|
|
|
*
|
|
|
|
* @param e The event struct
|
|
|
|
* @param index The argument position starting from 0
|
|
|
|
*
|
|
|
|
* @return Returns argument as integer
|
|
|
|
*
|
|
|
|
* @example long long int myNum = webui_get_int_at(e, 0);
|
|
|
|
*/
|
2023-10-06 03:03:12 +03:00
|
|
|
WEBUI_EXPORT long long int webui_get_int_at(webui_event_t* e, size_t index);
|
|
|
|
|
2023-10-29 22:51:49 +03:00
|
|
|
/**
|
2024-06-21 22:46:59 +03:00
|
|
|
* @brief Get the first argument as integer.
|
2023-10-29 22:51:49 +03:00
|
|
|
*
|
|
|
|
* @param e The event struct
|
|
|
|
*
|
|
|
|
* @return Returns argument as integer
|
|
|
|
*
|
|
|
|
* @example long long int myNum = webui_get_int(e);
|
|
|
|
*/
|
2023-04-17 22:43:46 +03:00
|
|
|
WEBUI_EXPORT long long int webui_get_int(webui_event_t* e);
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2024-05-30 00:23:19 +03:00
|
|
|
/**
|
2024-06-21 22:46:59 +03:00
|
|
|
* @brief Get an argument as float at a specific index.
|
2024-05-30 00:23:19 +03:00
|
|
|
*
|
|
|
|
* @param e The event struct
|
|
|
|
* @param index The argument position starting from 0
|
|
|
|
*
|
|
|
|
* @return Returns argument as float
|
|
|
|
*
|
|
|
|
* @example double myNum = webui_get_float_at(e, 0);
|
|
|
|
*/
|
|
|
|
WEBUI_EXPORT double webui_get_float_at(webui_event_t* e, size_t index);
|
|
|
|
|
|
|
|
/**
|
2024-06-21 22:46:59 +03:00
|
|
|
* @brief Get the first argument as float.
|
2024-05-30 00:23:19 +03:00
|
|
|
*
|
|
|
|
* @param e The event struct
|
|
|
|
*
|
|
|
|
* @return Returns argument as float
|
|
|
|
*
|
|
|
|
* @example double myNum = webui_get_float(e);
|
|
|
|
*/
|
|
|
|
WEBUI_EXPORT double webui_get_float(webui_event_t* e);
|
|
|
|
|
2023-10-29 22:51:49 +03:00
|
|
|
/**
|
2024-06-21 22:46:59 +03:00
|
|
|
* @brief Get an argument as string at a specific index.
|
2023-10-29 22:51:49 +03:00
|
|
|
*
|
|
|
|
* @param e The event struct
|
|
|
|
* @param index The argument position starting from 0
|
|
|
|
*
|
|
|
|
* @return Returns argument as string
|
|
|
|
*
|
|
|
|
* @example const char* myStr = webui_get_string_at(e, 0);
|
|
|
|
*/
|
2023-10-06 03:03:12 +03:00
|
|
|
WEBUI_EXPORT const char* webui_get_string_at(webui_event_t* e, size_t index);
|
|
|
|
|
2023-10-29 22:51:49 +03:00
|
|
|
/**
|
2024-06-21 22:46:59 +03:00
|
|
|
* @brief Get the first argument as string.
|
2023-10-29 22:51:49 +03:00
|
|
|
*
|
|
|
|
* @param e The event struct
|
|
|
|
*
|
|
|
|
* @return Returns argument as string
|
|
|
|
*
|
|
|
|
* @example const char* myStr = webui_get_string(e);
|
|
|
|
*/
|
2023-04-17 22:43:46 +03:00
|
|
|
WEBUI_EXPORT const char* webui_get_string(webui_event_t* e);
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2023-10-29 22:51:49 +03:00
|
|
|
/**
|
2024-06-21 22:46:59 +03:00
|
|
|
* @brief Get an argument as boolean at a specific index.
|
2023-10-29 22:51:49 +03:00
|
|
|
*
|
|
|
|
* @param e The event struct
|
|
|
|
* @param index The argument position starting from 0
|
|
|
|
*
|
|
|
|
* @return Returns argument as boolean
|
|
|
|
*
|
|
|
|
* @example bool myBool = webui_get_bool_at(e, 0);
|
|
|
|
*/
|
2023-10-06 03:03:12 +03:00
|
|
|
WEBUI_EXPORT bool webui_get_bool_at(webui_event_t* e, size_t index);
|
|
|
|
|
2023-10-29 22:51:49 +03:00
|
|
|
/**
|
2024-06-21 22:46:59 +03:00
|
|
|
* @brief Get the first argument as boolean.
|
2023-10-29 22:51:49 +03:00
|
|
|
*
|
|
|
|
* @param e The event struct
|
|
|
|
*
|
|
|
|
* @return Returns argument as boolean
|
|
|
|
*
|
|
|
|
* @example bool myBool = webui_get_bool(e);
|
|
|
|
*/
|
2023-04-17 22:43:46 +03:00
|
|
|
WEBUI_EXPORT bool webui_get_bool(webui_event_t* e);
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2023-10-29 22:51:49 +03:00
|
|
|
/**
|
2024-06-21 22:46:59 +03:00
|
|
|
* @brief Get the size in bytes of an argument at a specific index.
|
2023-10-29 22:51:49 +03:00
|
|
|
*
|
|
|
|
* @param e The event struct
|
|
|
|
* @param index The argument position starting from 0
|
|
|
|
*
|
|
|
|
* @return Returns size in bytes
|
|
|
|
*
|
|
|
|
* @example size_t argLen = webui_get_size_at(e, 0);
|
|
|
|
*/
|
2023-10-06 03:03:12 +03:00
|
|
|
WEBUI_EXPORT size_t webui_get_size_at(webui_event_t* e, size_t index);
|
|
|
|
|
2023-10-29 22:51:49 +03:00
|
|
|
/**
|
2024-06-21 22:46:59 +03:00
|
|
|
* @brief Get size in bytes of the first argument.
|
2023-10-29 22:51:49 +03:00
|
|
|
*
|
|
|
|
* @param e The event struct
|
|
|
|
*
|
|
|
|
* @return Returns size in bytes
|
|
|
|
*
|
|
|
|
* @example size_t argLen = webui_get_size(e);
|
|
|
|
*/
|
2023-10-06 03:03:12 +03:00
|
|
|
WEBUI_EXPORT size_t webui_get_size(webui_event_t* e);
|
|
|
|
|
2023-10-29 22:51:49 +03:00
|
|
|
/**
|
|
|
|
* @brief Return the response to JavaScript as integer.
|
|
|
|
*
|
|
|
|
* @param e The event struct
|
|
|
|
* @param n The integer to be send to JavaScript
|
|
|
|
*
|
|
|
|
* @example webui_return_int(e, 123);
|
|
|
|
*/
|
2023-04-17 22:43:46 +03:00
|
|
|
WEBUI_EXPORT void webui_return_int(webui_event_t* e, long long int n);
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2024-05-30 02:01:10 +03:00
|
|
|
/**
|
|
|
|
* @brief Return the response to JavaScript as float.
|
|
|
|
*
|
|
|
|
* @param e The event struct
|
|
|
|
* @param f The float number to be send to JavaScript
|
|
|
|
*
|
|
|
|
* @example webui_return_float(e, 123.456);
|
|
|
|
*/
|
|
|
|
WEBUI_EXPORT void webui_return_float(webui_event_t* e, double f);
|
|
|
|
|
2023-10-29 22:51:49 +03:00
|
|
|
/**
|
|
|
|
* @brief Return the response to JavaScript as string.
|
|
|
|
*
|
|
|
|
* @param e The event struct
|
|
|
|
* @param n The string to be send to JavaScript
|
|
|
|
*
|
|
|
|
* @example webui_return_string(e, "Response...");
|
|
|
|
*/
|
2023-05-21 19:20:54 +03:00
|
|
|
WEBUI_EXPORT void webui_return_string(webui_event_t* e, const char* s);
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2023-10-29 22:51:49 +03:00
|
|
|
/**
|
|
|
|
* @brief Return the response to JavaScript as boolean.
|
|
|
|
*
|
|
|
|
* @param e The event struct
|
|
|
|
* @param n The boolean to be send to JavaScript
|
|
|
|
*
|
|
|
|
* @example webui_return_bool(e, true);
|
|
|
|
*/
|
2023-04-17 22:43:46 +03:00
|
|
|
WEBUI_EXPORT void webui_return_bool(webui_event_t* e, bool b);
|
2022-09-25 02:35:56 +03:00
|
|
|
|
2023-09-12 00:18:31 +03:00
|
|
|
// -- Wrapper's Interface -------------
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2023-10-29 22:51:49 +03:00
|
|
|
/**
|
|
|
|
* @brief Bind a specific HTML element click event with a function. Empty element means all events.
|
|
|
|
*
|
|
|
|
* @param window The window number
|
|
|
|
* @param element The element ID
|
|
|
|
* @param func The callback as myFunc(Window, EventType, Element, EventNumber, BindID)
|
|
|
|
*
|
|
|
|
* @return Returns unique bind ID
|
|
|
|
*
|
|
|
|
* @example size_t id = webui_interface_bind(myWindow, "myID", myCallback);
|
|
|
|
*/
|
|
|
|
WEBUI_EXPORT size_t webui_interface_bind(size_t window, const char* element,
|
|
|
|
void (*func)(size_t, size_t, char*, size_t, size_t));
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2023-10-29 22:51:49 +03:00
|
|
|
/**
|
|
|
|
* @brief When using `webui_interface_bind()`, you may need this function to easily set a response.
|
|
|
|
*
|
|
|
|
* @param window The window number
|
|
|
|
* @param event_number The event number
|
|
|
|
* @param response The response as string to be send to JavaScript
|
|
|
|
*
|
|
|
|
* @example webui_interface_set_response(myWindow, e->event_number, "Response...");
|
|
|
|
*/
|
2023-05-07 20:54:15 +03:00
|
|
|
WEBUI_EXPORT void webui_interface_set_response(size_t window, size_t event_number, const char* response);
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2023-10-29 22:51:49 +03:00
|
|
|
/**
|
|
|
|
* @brief Check if the app still running.
|
|
|
|
*
|
|
|
|
* @return Returns True if app is running
|
|
|
|
*
|
|
|
|
* @example bool status = webui_interface_is_app_running();
|
|
|
|
*/
|
2023-04-17 22:43:46 +03:00
|
|
|
WEBUI_EXPORT bool webui_interface_is_app_running(void);
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2023-10-29 22:51:49 +03:00
|
|
|
/**
|
|
|
|
* @brief Get a unique window ID.
|
|
|
|
*
|
|
|
|
* @param window The window number
|
|
|
|
*
|
|
|
|
* @return Returns the unique window ID as integer
|
|
|
|
*
|
|
|
|
* @example size_t id = webui_interface_get_window_id(myWindow);
|
|
|
|
*/
|
2023-05-07 20:54:15 +03:00
|
|
|
WEBUI_EXPORT size_t webui_interface_get_window_id(size_t window);
|
2023-09-12 01:09:42 +03:00
|
|
|
|
2023-10-29 22:51:49 +03:00
|
|
|
/**
|
2024-06-21 22:46:59 +03:00
|
|
|
* @brief Get an argument as string at a specific index.
|
2023-10-29 22:51:49 +03:00
|
|
|
*
|
|
|
|
* @param window The window number
|
|
|
|
* @param event_number The event number
|
|
|
|
* @param index The argument position
|
|
|
|
*
|
|
|
|
* @return Returns argument as string
|
|
|
|
*
|
|
|
|
* @example const char* myStr = webui_interface_get_string_at(myWindow, e->event_number, 0);
|
|
|
|
*/
|
2023-10-07 03:00:46 +03:00
|
|
|
WEBUI_EXPORT const char* webui_interface_get_string_at(size_t window, size_t event_number, size_t index);
|
|
|
|
|
2023-10-29 22:51:49 +03:00
|
|
|
/**
|
2024-06-21 22:46:59 +03:00
|
|
|
* @brief Get an argument as integer at a specific index.
|
2023-10-29 22:51:49 +03:00
|
|
|
*
|
|
|
|
* @param window The window number
|
|
|
|
* @param event_number The event number
|
|
|
|
* @param index The argument position
|
|
|
|
*
|
|
|
|
* @return Returns argument as integer
|
|
|
|
*
|
|
|
|
* @example long long int myNum = webui_interface_get_int_at(myWindow, e->event_number, 0);
|
|
|
|
*/
|
2023-10-07 03:00:46 +03:00
|
|
|
WEBUI_EXPORT long long int webui_interface_get_int_at(size_t window, size_t event_number, size_t index);
|
|
|
|
|
2023-10-29 22:51:49 +03:00
|
|
|
/**
|
2024-06-21 22:46:59 +03:00
|
|
|
* @brief Get an argument as boolean at a specific index.
|
2023-10-29 22:51:49 +03:00
|
|
|
*
|
|
|
|
* @param window The window number
|
|
|
|
* @param event_number The event number
|
|
|
|
* @param index The argument position
|
|
|
|
*
|
|
|
|
* @return Returns argument as boolean
|
|
|
|
*
|
|
|
|
* @example bool myBool = webui_interface_get_bool_at(myWindow, e->event_number, 0);
|
|
|
|
*/
|
2023-10-07 03:00:46 +03:00
|
|
|
WEBUI_EXPORT bool webui_interface_get_bool_at(size_t window, size_t event_number, size_t index);
|
|
|
|
|
2023-11-17 00:46:49 +03:00
|
|
|
/**
|
2024-06-21 22:46:59 +03:00
|
|
|
* @brief Get the size in bytes of an argument at a specific index.
|
2023-11-17 00:46:49 +03:00
|
|
|
*
|
|
|
|
* @param window The window number
|
|
|
|
* @param event_number The event number
|
|
|
|
* @param index The argument position
|
|
|
|
*
|
|
|
|
* @return Returns size in bytes
|
|
|
|
*
|
|
|
|
* @example size_t argLen = webui_interface_get_size_at(myWindow, e->event_number, 0);
|
|
|
|
*/
|
|
|
|
WEBUI_EXPORT size_t webui_interface_get_size_at(size_t window, size_t event_number, size_t index);
|
|
|
|
|
2022-09-25 02:35:56 +03:00
|
|
|
#endif /* _WEBUI_H */
|