From 656dab6e6ab6467ee834f05cff20d1b1a1099d61 Mon Sep 17 00:00:00 2001 From: Nikola Kirov Date: Sat, 9 Dec 2023 08:56:52 +0200 Subject: [PATCH] Add onCreateServerCallback hook --- src/ESPUI.cpp | 4 ++++ src/ESPUI.h | 13 ++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/ESPUI.cpp b/src/ESPUI.cpp index 341ec88..78ec95c 100644 --- a/src/ESPUI.cpp +++ b/src/ESPUI.cpp @@ -1435,6 +1435,10 @@ void ESPUIClass::begin(const char* _title, const char* username, const char* pas request->send(404); } }); + + if (onCreateServerCallback) { + onCreateServerCallback(server); + } server->begin(); diff --git a/src/ESPUI.h b/src/ESPUI.h index 7bf0577..f1b33f4 100644 --- a/src/ESPUI.h +++ b/src/ESPUI.h @@ -28,9 +28,7 @@ #else -#include #include -#include #include #include @@ -108,6 +106,13 @@ public: bool auto_update_values = false; void setVerbosity(Verbosity verbosity); + + typedef std::function onCreateServerCallback_t; + void onCreateServerCallbackSet(onCreateServerCallback_t callback) + { + onCreateServerCallback = callback; + } + void begin(const char* _title, const char* username = nullptr, const char* password = nullptr, uint16_t port = 80); // Setup server and page in Memorymode void beginSPIFFS(const char* _title, const char* username = nullptr, const char* password = nullptr, @@ -245,7 +250,9 @@ protected: AsyncWebServer* server; AsyncWebSocket* ws; - + + + onCreateServerCallback_t onCreateServerCallback = nullptr; const char* basicAuthUsername = nullptr; const char* basicAuthPassword = nullptr; bool basicAuth = true;