Skip to content

Commit

Permalink
New API webui_set_hide
Browse files Browse the repository at this point in the history
* Adding `webui_set_hide()` to run the window in hidden mode
  • Loading branch information
hassandraga committed Aug 18, 2023
1 parent 3fe765c commit 28274c5
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 5 deletions.
2 changes: 2 additions & 0 deletions examples/C++/VS2019/serve_a_folder/my_webui_app/webui.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ WEBUI_EXPORT void webui_free(void* ptr);
WEBUI_EXPORT void* webui_malloc(size_t size);
// Safely send raw data to the UI.
WEBUI_EXPORT void webui_send_raw(size_t window, const char* function, const void* raw, size_t size);
// Run the window in hidden mode
WEBUI_EXPORT void webui_set_hide(size_t window, bool status);

// -- 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, EventNumber)
Expand Down
2 changes: 2 additions & 0 deletions examples/C++/VS2022/serve_a_folder/my_webui_app/webui.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ WEBUI_EXPORT void webui_free(void* ptr);
WEBUI_EXPORT void* webui_malloc(size_t size);
// Safely send raw data to the UI.
WEBUI_EXPORT void webui_send_raw(size_t window, const char* function, const void* raw, size_t size);
// Run the window in hidden mode
WEBUI_EXPORT void webui_set_hide(size_t window, bool status);

// -- 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, EventNumber)
Expand Down
2 changes: 2 additions & 0 deletions examples/C/text-editor/webui.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ WEBUI_EXPORT void webui_free(void* ptr);
WEBUI_EXPORT void* webui_malloc(size_t size);
// Safely send raw data to the UI.
WEBUI_EXPORT void webui_send_raw(size_t window, const char* function, const void* raw, size_t size);
// Run the window in hidden mode
WEBUI_EXPORT void webui_set_hide(size_t window, bool status);

// -- 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, EventNumber)
Expand Down
2 changes: 2 additions & 0 deletions include/webui.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ WEBUI_EXPORT void webui_free(void* ptr);
WEBUI_EXPORT void* webui_malloc(size_t size);
// Safely send raw data to the UI.
WEBUI_EXPORT void webui_send_raw(size_t window, const char* function, const void* raw, size_t size);
// Run the window in hidden mode
WEBUI_EXPORT void webui_set_hide(size_t window, bool status);

// -- 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, EventNumber)
Expand Down
25 changes: 20 additions & 5 deletions src/webui.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,19 @@ void webui_return_bool(webui_event_t* e, bool b) {
*response = buf;
}

void webui_set_hide(size_t window, bool status) {

#ifdef WEBUI_LOG
printf("[User] webui_set_hide(%zu, %d)...\n", window, status);
#endif

// Dereference
if(_webui_core.wins[window] == NULL) return;
_webui_window_t* win = _webui_core.wins[window];

win->hide = status;
}

void webui_send_raw(size_t window, const char* function, const void* raw, size_t size) {

#ifdef WEBUI_LOG
Expand Down Expand Up @@ -2901,16 +2914,18 @@ static int _webui_get_browser_args(_webui_window_t* win, size_t browser, char *b
for (int i = 0; i < (int)(sizeof(chromium_options) / sizeof(chromium_options[0])); i++) {
c += sprintf(buffer + c, " %s", chromium_options[i]);
}

if (win->kiosk_mode)
c += sprintf(buffer + c, " %s", "--chrome-frame --kiosk");

c += sprintf(buffer + c, " %s", "--chrome-frame --kiosk");
if (win->hide)
c += sprintf(buffer + c, " %s", "--headless");
c += sprintf(buffer + c, " %s", "--app=");
return c;
case Firefox:
c = sprintf(buffer, " -P WebUI -purgecaches");
if (win->kiosk_mode)
c += sprintf(buffer, "%s", " -kiosk");
if (win->hide)
c += sprintf(buffer, "%s", " -headless");
c += sprintf(buffer, " -new-window ");
return c;
}
Expand Down Expand Up @@ -4669,7 +4684,7 @@ static WEBUI_SERVER_START
(void*)win
);

if(_webui_core.startup_timeout > 0) {
if(_webui_core.startup_timeout > 0 && !win->hide) {

#ifdef WEBUI_LOG
printf("[Core]\t\t[Thread] _webui_server_start([%zu]) -> Listening Success\n", win->window_number);
Expand Down Expand Up @@ -4804,7 +4819,7 @@ static WEBUI_SERVER_START
// Let's check the flag again, there is a change that
// the flag has ben changed during the first loop for
// example when set_timeout() get called later
if(_webui_core.startup_timeout == 0) {
if(_webui_core.startup_timeout == 0 || win->hide) {

#ifdef WEBUI_LOG
printf("[Core]\t\t[Thread] _webui_server_start([%zu]) -> Listening success\n", win->window_number);
Expand Down
1 change: 1 addition & 0 deletions src/webui_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ typedef struct _webui_window_t {
bool has_events;
char* server_root_path;
bool kiosk_mode;
bool hide;
size_t process_id;
webui_event_core_t* event_core[WEBUI_MAX_ARRAY];
#ifdef _WIN32
Expand Down

0 comments on commit 28274c5

Please sign in to comment.