From 5fd3f15ac71df8e705d7c76e72c9db48b452e00e Mon Sep 17 00:00:00 2001 From: AsmX Date: Sat, 19 Oct 2024 09:48:34 +0800 Subject: [PATCH 1/3] Add user-defined command line parameter. --- include/webui.h | 11 +++++++++++ include/webui.hpp | 5 +++++ src/webui.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/include/webui.h b/include/webui.h index e4713bf8..38b58c75 100644 --- a/include/webui.h +++ b/include/webui.h @@ -330,6 +330,17 @@ WEBUI_EXPORT bool webui_show_wv(size_t window, const char* content); */ WEBUI_EXPORT void webui_set_kiosk(size_t window, bool status); +/** + * @brief Add user-defined command line parameters. + * + * @param window The window number + * @param paramsLen Command line parameters length + * @param params Command line parameters + * + * @example webui_set_custom_parameters(myWindow, "--remote-debugging-port=9222"); + */ +WEBUI_EXPORT void webui_set_custom_parameters(size_t window, int paramsLen, char *params); + /** * @brief Set the window with high-contrast support. Useful when you want to * build a better high-contrast theme with CSS. diff --git a/include/webui.hpp b/include/webui.hpp index 0a8a597f..48f2238b 100644 --- a/include/webui.hpp +++ b/include/webui.hpp @@ -223,6 +223,11 @@ namespace webui { webui_set_kiosk(webui_window, status); } + // Add user-defined command line parameters + void set_custom_parameters(int paramsLen, char *params) const { + webui_set_custom_parameters(webui_window, paramsLen, params); + } + // Set the window with high-contrast support. Useful when you want to build a better high-contrast theme with CSS. void set_high_contrast(bool status) const { webui_set_high_contrast(webui_window, status); diff --git a/src/webui.c b/src/webui.c index 65824d0f..deda2ccf 100644 --- a/src/webui.c +++ b/src/webui.c @@ -317,6 +317,7 @@ typedef struct _webui_window_t { bool default_profile; char* profile_path; char* profile_name; + char* custom_parameters; size_t runtime; bool kiosk_mode; bool disable_browser_high_contrast; @@ -998,6 +999,24 @@ void webui_set_kiosk(size_t window, bool status) { win->kiosk_mode = status; } +void webui_set_custom_parameters(size_t window, int paramsLen, char *params) { + + #ifdef WEBUI_LOG + printf("[User] webui_set_custom_parameters([%zu], [%s])\n", window, params); + #endif + + // Initialization + _webui_init(); + + // Dereference + if (_webui_mutex_is_exit_now(WEBUI_MUTEX_NONE) || _webui.wins[window] == NULL) + return; + _webui_window_t* win = _webui.wins[window]; + + win->custom_parameters = (char *)_webui_malloc(paramsLen + 1); + WEBUI_STR_COPY_STATIC(win->custom_parameters, paramsLen, params); +} + void webui_set_high_contrast(size_t window, bool status) { #ifdef WEBUI_LOG @@ -6073,6 +6092,11 @@ static int _webui_get_browser_args(_webui_window_t* win, size_t browser, char* b c += WEBUI_SN_PRINTF_DYN(buffer + c, len, " --proxy-server=%s", win->proxy_server); else c += WEBUI_SN_PRINTF_DYN(buffer + c, len, " %s", "--no-proxy-server"); + // User-defined command line parameters. + if (!_webui_is_empty(win->custom_parameters)) { + c += WEBUI_SN_PRINTF_DYN(buffer, len, " %s", win->custom_parameters); + _webui_free_mem((void*)win->custom_parameters); + } // URL (END) c += WEBUI_SN_PRINTF_DYN(buffer + c, len, " %s", "--app="); @@ -6102,6 +6126,11 @@ static int _webui_get_browser_args(_webui_window_t* win, size_t browser, char* b // Method 1: modifying `prefs.js` / user.js // Method 2: use Proxy Auto-Configuration (PAC) file } + // User-defined command line parameters. + if (!_webui_is_empty(win->custom_parameters)) { + c += WEBUI_SN_PRINTF_DYN(buffer, len, " %s", win->custom_parameters); + _webui_free_mem((void*)win->custom_parameters); + } // URL (END) c += WEBUI_SN_PRINTF_DYN(buffer + c, len, " -new-window "); From 31c0264a042036ce4a1c4c82974c511207219cb5 Mon Sep 17 00:00:00 2001 From: Hassan DRAGA Date: Sat, 9 Nov 2024 13:44:22 -0500 Subject: [PATCH 2/3] Update - Add user-defined command line parameter --- include/webui.h | 5 ++--- src/webui.c | 10 +++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/webui.h b/include/webui.h index 38b58c75..11dfae9c 100644 --- a/include/webui.h +++ b/include/webui.h @@ -331,15 +331,14 @@ WEBUI_EXPORT bool webui_show_wv(size_t window, const char* content); WEBUI_EXPORT void webui_set_kiosk(size_t window, bool status); /** - * @brief Add user-defined command line parameters. + * @brief Add a user-defined web browser's CLI parameters. * * @param window The window number - * @param paramsLen Command line parameters length * @param params Command line parameters * * @example webui_set_custom_parameters(myWindow, "--remote-debugging-port=9222"); */ -WEBUI_EXPORT void webui_set_custom_parameters(size_t window, int paramsLen, char *params); +WEBUI_EXPORT void webui_set_custom_parameters(size_t window, char *params); /** * @brief Set the window with high-contrast support. Useful when you want to diff --git a/src/webui.c b/src/webui.c index deda2ccf..e447828e 100644 --- a/src/webui.c +++ b/src/webui.c @@ -999,7 +999,7 @@ void webui_set_kiosk(size_t window, bool status) { win->kiosk_mode = status; } -void webui_set_custom_parameters(size_t window, int paramsLen, char *params) { +void webui_set_custom_parameters(size_t window, char* params) { #ifdef WEBUI_LOG printf("[User] webui_set_custom_parameters([%zu], [%s])\n", window, params); @@ -1013,8 +1013,12 @@ void webui_set_custom_parameters(size_t window, int paramsLen, char *params) { return; _webui_window_t* win = _webui.wins[window]; - win->custom_parameters = (char *)_webui_malloc(paramsLen + 1); - WEBUI_STR_COPY_STATIC(win->custom_parameters, paramsLen, params); + size_t len = _webui_strlen(params); + if (len < 1) + return; + + win->custom_parameters = (char*)_webui_malloc(len); + WEBUI_STR_COPY_STATIC(win->custom_parameters, len, params); } void webui_set_high_contrast(size_t window, bool status) { From 65b49d1d0972a1d8b36e3a08c6699e62636df17b Mon Sep 17 00:00:00 2001 From: Hassan DRAGA Date: Sat, 9 Nov 2024 13:50:01 -0500 Subject: [PATCH 3/3] Fix - Add user-defined command line parameter --- include/webui.hpp | 4 ++-- src/webui.c | 17 +++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/include/webui.hpp b/include/webui.hpp index 48f2238b..f38d32d2 100644 --- a/include/webui.hpp +++ b/include/webui.hpp @@ -224,8 +224,8 @@ namespace webui { } // Add user-defined command line parameters - void set_custom_parameters(int paramsLen, char *params) const { - webui_set_custom_parameters(webui_window, paramsLen, params); + void set_custom_parameters(char *params) const { + webui_set_custom_parameters(webui_window, params); } // Set the window with high-contrast support. Useful when you want to build a better high-contrast theme with CSS. diff --git a/src/webui.c b/src/webui.c index e447828e..12a74b23 100644 --- a/src/webui.c +++ b/src/webui.c @@ -1013,10 +1013,15 @@ void webui_set_custom_parameters(size_t window, char* params) { return; _webui_window_t* win = _webui.wins[window]; + // Check size size_t len = _webui_strlen(params); if (len < 1) return; + // Free old + _webui_free_mem((void*)win->custom_parameters); + + // Set new win->custom_parameters = (char*)_webui_malloc(len); WEBUI_STR_COPY_STATIC(win->custom_parameters, len, params); } @@ -6098,8 +6103,7 @@ static int _webui_get_browser_args(_webui_window_t* win, size_t browser, char* b c += WEBUI_SN_PRINTF_DYN(buffer + c, len, " %s", "--no-proxy-server"); // User-defined command line parameters. if (!_webui_is_empty(win->custom_parameters)) { - c += WEBUI_SN_PRINTF_DYN(buffer, len, " %s", win->custom_parameters); - _webui_free_mem((void*)win->custom_parameters); + c += WEBUI_SN_PRINTF_DYN(buffer + c, len, " %s", win->custom_parameters); } // URL (END) @@ -6121,20 +6125,17 @@ static int _webui_get_browser_args(_webui_window_t* win, size_t browser, char* b if (win->size_set) c += WEBUI_SN_PRINTF_DYN(buffer + c, len, " -width %u -height %u", win->width, win->height); // Window Position - // Firefox does not support window positioning. + // Firefox does not support window positioning. // Proxy if (win->proxy_set) { // Server: `win->proxy_server` - // TODO: Add proxy feature to Firefox // Method 1: modifying `prefs.js` / user.js // Method 2: use Proxy Auto-Configuration (PAC) file } // User-defined command line parameters. - if (!_webui_is_empty(win->custom_parameters)) { - c += WEBUI_SN_PRINTF_DYN(buffer, len, " %s", win->custom_parameters); - _webui_free_mem((void*)win->custom_parameters); - } + if (!_webui_is_empty(win->custom_parameters)) + c += WEBUI_SN_PRINTF_DYN(buffer + c, len, " %s", win->custom_parameters); // URL (END) c += WEBUI_SN_PRINTF_DYN(buffer + c, len, " -new-window ");