Adding webui_get_url

- Adding `char* webui_get_url(size_t window);`
This commit is contained in:
fibodevy 2023-09-21 07:21:04 +02:00
parent 1478c4ffdd
commit 6f782bc1a8
2 changed files with 28 additions and 0 deletions

View File

@ -415,6 +415,17 @@ WEBUI_EXPORT void webui_set_position(size_t window, unsigned int x, unsigned int
*/
WEBUI_EXPORT void webui_set_profile(size_t window, const char* name, const char* path);
/**
* @brief Get the server URL
*
* @param window The window number
*
* @return Returns the server URL
*
* @example char* URL = webui_get_url(myWindow);
*/
WEBUI_EXPORT char* webui_get_url(size_t window);
// -- JavaScript ----------------------
// Run JavaScript without waiting for the response.

View File

@ -1142,6 +1142,23 @@ void webui_set_profile(size_t window, const char* name, const char* path) {
win->custom_profile = true;
}
char* webui_get_url(size_t window) {
#ifdef WEBUI_LOG
printf("[User] webui_get_url([%zu])...\n", window);
#endif
// Dereference
_webui_init();
if(_webui_core.exit_now || _webui_core.wins[window] == NULL) return NULL;
_webui_window_t* win = _webui_core.wins[window];
// Get current URL
char* url = (char*) _webui_malloc(32);
sprintf(url, "http://127.0.0.1:%zu", win->server_port);
return url;
}
void webui_send_raw(size_t window, const char* function, const void* raw, size_t size) {
#ifdef WEBUI_LOG