Skip to content

Commit 2b155b6

Browse files
committed
feat: use WEBUI_EXTENSION_API to turn on/off extensions
1 parent 9214d03 commit 2b155b6

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,26 @@
88
Canada.
99
*/
1010

11-
#ifndef _WEBUI_EXTRAS_H
12-
#define _WEBUI_EXTRAS_H
11+
#ifndef _WEBUI_EXTENSIONS_H
12+
#define _WEBUI_EXTENSIONS_H
1313

1414
#ifdef __cplusplus
1515
extern "C" {
1616
#endif
1717

18-
#include "webui.h"
18+
/**
19+
* This is to help the compiler identify whether to compile the extensions API funtions or not
20+
* - If you are including the webui.c file to your source file directly,
21+
* and wish to use the extensions API functions,
22+
* please include this header file before including webui.c,
23+
* or define this macro manually before including webui.c
24+
* - In other cases, as long as the webui.c file is not included directly,
25+
* you might need to define this macro in your compiler settings
26+
*/
27+
#define WEBUI_EXTENSIONS_API
28+
29+
#include <stdbool.h>
30+
#include <stddef.h>
1931

2032
/**
2133
* @brief Construct a JavaScript string from a format string,
@@ -32,7 +44,7 @@ extern "C" {
3244
*
3345
* @example webui_run_fmt(myWindow, "alert('Hello %s');", "World");
3446
*/
35-
WEBUI_EXPORT void webui_run_fmt(size_t window, const char* fmt, ...);
47+
void webui_run_fmt(size_t window, const char* fmt, ...);
3648

3749
/**
3850
* @brief Construct a JavaScript string from a format string,
@@ -56,12 +68,12 @@ WEBUI_EXPORT void webui_run_fmt(size_t window, const char* fmt, ...);
5668
* @example bool err = webui_script_fmt(myWindow, 0, myBuffer, myBufferSize,
5769
* "return %d + %d;", 4, 6);
5870
*/
59-
WEBUI_EXPORT bool webui_script_fmt(size_t window, size_t timeout,
71+
bool webui_script_fmt(size_t window, size_t timeout,
6072
char* buffer, size_t buffer_length,
6173
const char* fmt, ...);
6274

6375
#ifdef __cplusplus
6476
}
6577
#endif
6678

67-
#endif /*_WEBUI_EXTRAS_H */
79+
#endif /*_WEBUI_EXTENSIONS_H */

src/webui.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,7 @@ void webui_run(size_t window, const char* script) {
847847
_webui_send_all(win, 0, WEBUI_CMD_JS_QUICK, script, js_len);
848848
}
849849

850+
#ifdef WEBUI_EXTENSION_API
850851
void webui_run_fmt(size_t window, const char* fmt, ...) {
851852
int len;
852853
char* buf;
@@ -871,6 +872,7 @@ void webui_run_fmt(size_t window, const char* fmt, ...) {
871872

872873
_webui_free_mem((void*)buf);
873874
}
875+
#endif /* WEBUI_EXTENSION_API */
874876

875877
void webui_set_close_handler_wv(size_t window, bool(*close_handler)(size_t window)) {
876878

@@ -1090,6 +1092,7 @@ bool webui_script(size_t window, const char* script, size_t timeout,
10901092
return webui_script_client(&e, script, timeout, buffer, buffer_length);
10911093
}
10921094

1095+
#ifdef WEBUI_EXTENSION_API
10931096
bool webui_script_fmt(
10941097
size_t window, size_t timeout,
10951098
char* buffer, size_t buffer_length,
@@ -1120,6 +1123,7 @@ bool webui_script_fmt(
11201123

11211124
return status;
11221125
}
1126+
#endif /* WEBUI_EXTENSION_API */
11231127

11241128
static uint32_t _webui_generate_random_uint32() {
11251129
uint32_t timestamp = (uint32_t) time(NULL);

0 commit comments

Comments
 (0)