Skip to content

Commit

Permalink
Merge pull request #8 from ab-tools/1.3.3
Browse files Browse the repository at this point in the history
Added webServerPreCallback to init method that allows adding a callba…
  • Loading branch information
tobozo committed Dec 31, 2023
2 parents 79f7790 + f42135b commit 07c0e96
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
3 changes: 1 addition & 2 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ void setup()
WiFiManager wifiManager;

WiFiManagerNS::init( &wifiManager );
// WiFiManagerNS::init( &wifiManager, nullptr ); // using nullptr to prevent WiFiManagerTz from overwriting WiFiManager favicon
// WiFiManagerNS::init( &wifiManager, myFaviconCallback ); // using a custom callback to emit favicon
// WiFiManagerNS::init( &wifiManager, webserverPreCallback ); // using a custom callback add/override server routes

// /!\ make sure "custom" is listed there as it's required to pull the "Setup Clock" button
std::vector<const char *> menu = {"wifi", "info", "custom", "param", "sep", "restart", "exit"};
Expand Down
22 changes: 11 additions & 11 deletions src/WiFiManagerTz.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ namespace WiFiManagerNS
String TimeConfHTML;
char systime[64];

typedef void(*faviconCallback_t)();
faviconCallback_t handleFavicon = nullptr;
void handleFavicon_default();
std::function<void()> _webserverPreCallback;
void bindServerCallback();


Expand Down Expand Up @@ -57,8 +55,6 @@ namespace WiFiManagerNS

#else // defined WiFiManager_h

#include "strings_en.h"


constexpr const char* menuhtml = "<form action='/custom' method='get'><button>Setup Clock</button></form><br/>\n";

Expand Down Expand Up @@ -128,9 +124,11 @@ namespace WiFiManagerNS
WiFiManager *_wifiManager;


void init(WiFiManager *manager, faviconCallback_t faviconCB=handleFavicon_default)

void init(WiFiManager *manager, std::function<void()> webserverPreCallback)
{
handleFavicon = faviconCB;
_webserverPreCallback = webserverPreCallback;

_wifiManager = manager;
_wifiManager->setWebServerCallback(bindServerCallback);
_wifiManager->setCustomMenuHTML( menuhtml );
Expand All @@ -144,7 +142,7 @@ namespace WiFiManagerNS
}


void handleFavicon_default()
void handleFavicon()
{
_wifiManager->server->send_P(200, "image/gif", favicon, sizeof(favicon) );
}
Expand Down Expand Up @@ -305,11 +303,13 @@ namespace WiFiManagerNS

void bindServerCallback()
{
if (_webserverPreCallback != NULL) {
_webserverPreCallback(); // callback to add/override server routes
}

_wifiManager->server->on("/custom", handleRoute);
_wifiManager->server->on("/save-tz", handleValues);
if( handleFavicon ) {
_wifiManager->server->on("/favicon.ico", handleFavicon);
}
_wifiManager->server->on("/favicon.ico", handleFavicon);
}

#endif
Expand Down

0 comments on commit 07c0e96

Please sign in to comment.