mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-04 02:48:13 +10:00
WiFiManager: remove legacy web customization API; simplify handlers to static templates; drop custom menu; keep title and parameter customization; update tests; remove renderer abstraction; build/test clean
This commit is contained in:
@@ -322,17 +322,6 @@ class WiFiManager
|
||||
//if this is set, it will exit after config, even if connection is unsuccessful.
|
||||
void setBreakAfterConfig(boolean shouldBreak);
|
||||
|
||||
//add custom html at inside <head> for all pages
|
||||
void setCustomHeadElement(const char* html);
|
||||
|
||||
//add custom html at start of <body> for all pages
|
||||
void setCustomBodyHeader(const char* html);
|
||||
|
||||
//add custom html at end of <body> for all pages
|
||||
void setCustomBodyFooter(const char* html);
|
||||
|
||||
//if this is set, customise style
|
||||
void setCustomMenuHTML(const char* html);
|
||||
|
||||
//if this is true, remove duplicated Access Points - defaut true
|
||||
void setRemoveDuplicateAPs(boolean removeDuplicates);
|
||||
@@ -389,11 +378,6 @@ class WiFiManager
|
||||
// clean connect, always disconnect before connecting
|
||||
void setCleanConnect(bool enable); // default false
|
||||
|
||||
// set custom menu items and order, vector or arr
|
||||
// see _menutokens for ids
|
||||
void setMenu(std::vector<const char*>& menu);
|
||||
void setMenu(const char* menu[], uint8_t size);
|
||||
|
||||
// set the webapp title, default WiFiManager
|
||||
void setTitle(String title);
|
||||
|
||||
@@ -431,11 +415,6 @@ class WiFiManager
|
||||
// set the country code for wifi settings, CN
|
||||
void setCountry(String cc);
|
||||
|
||||
// set body class (invert), may be used for hacking in alt classes
|
||||
void setClass(String str);
|
||||
|
||||
// set dark mode via invert class
|
||||
void setDarkMode(bool enable);
|
||||
|
||||
// get default ap esp uses , esp_chipid etc
|
||||
String getDefaultAPName();
|
||||
@@ -535,10 +514,6 @@ class WiFiManager
|
||||
protected:
|
||||
// vars
|
||||
std::unique_ptr<WiFiManagerServer> _serverManager;
|
||||
std::vector<uint8_t> _menuIds;
|
||||
std::vector<const char *> _menuIdsParams = {"wifi","param","info","exit"};
|
||||
std::vector<const char *> _menuIdsUpdate = {"wifi","param","info","update","exit"};
|
||||
std::vector<const char *> _menuIdsDefault = {"wifi","info","exit","sep","update"};
|
||||
|
||||
// ip configs @todo struct ?
|
||||
IPAddress _ap_static_ip;
|
||||
@@ -640,12 +615,6 @@ class WiFiManager
|
||||
boolean _enableConfigPortal = true; // FOR autoconnect - start config portal if autoconnect failed
|
||||
boolean _disableConfigPortal = true; // FOR autoconnect - stop config portal if cp wifi save
|
||||
String _hostname = ""; // hostname for esp8266 for dhcp, and or MDNS
|
||||
|
||||
const char* _customHeadElement = ""; // store custom head element html from user inside <head>
|
||||
const char* _customBodyHeader = ""; // store custom top body element html from user inside <body>
|
||||
const char* _customBodyFooter = ""; // store custom bottom body element html from user inside <body>
|
||||
const char* _customMenuHTML = ""; // store custom menu html from user
|
||||
String _bodyClass = ""; // class to add to body
|
||||
String _title = "WiFiManager"; // app title - default WiFiManager
|
||||
|
||||
// internal options
|
||||
|
||||
@@ -25,23 +25,6 @@ class WiFiManager;
|
||||
// Forward declaration - full definition needed in .cpp file
|
||||
class WiFiManagerHandlers;
|
||||
|
||||
// -----------------------------------------------------------------------------------------------
|
||||
// MENU TOKENS (for menu configuration via setMenu)
|
||||
|
||||
extern const char _wifi_token[] PROGMEM;
|
||||
extern const char _wifinoscan_token[] PROGMEM;
|
||||
extern const char _info_token[] PROGMEM;
|
||||
extern const char _param_token[] PROGMEM;
|
||||
extern const char _close_token[] PROGMEM;
|
||||
extern const char _restart_token[] PROGMEM;
|
||||
extern const char _exit_token[] PROGMEM;
|
||||
extern const char _erase_token[] PROGMEM;
|
||||
extern const char _update_token[] PROGMEM;
|
||||
extern const char _sep_token[] PROGMEM;
|
||||
extern const char _custom_token[] PROGMEM;
|
||||
extern PGM_P _menutokens[] PROGMEM;
|
||||
extern const uint8_t _nummenutokens;
|
||||
|
||||
// -----------------------------------------------------------------------------------------------
|
||||
// HTTP ROUTES
|
||||
|
||||
|
||||
@@ -91,7 +91,6 @@ WiFiManager::WiFiManager() {
|
||||
}
|
||||
|
||||
void WiFiManager::WiFiManagerInit(){
|
||||
setMenu(_menuIdsDefault);
|
||||
if(_debug && _debugLevel >= WM_DEBUG_DEV) debugPlatformInfo();
|
||||
_max_params = WIFI_MANAGER_MAX_PARAMS;
|
||||
// _serverManager is created lazily when config portal is started to save memory
|
||||
@@ -1455,46 +1454,6 @@ void WiFiManager::setConfigPortalTimeoutCallback( std::function<void()> func ) {
|
||||
_configportaltimeoutcallback = func;
|
||||
}
|
||||
|
||||
/**
|
||||
* set custom head html
|
||||
* custom element will be added to head, eg. new meta,style,script tag etc.
|
||||
* @access public
|
||||
* @param char element
|
||||
*/
|
||||
void WiFiManager::setCustomHeadElement(const char* html) {
|
||||
_customHeadElement = html;
|
||||
}
|
||||
|
||||
/**
|
||||
* set custom html at the top of the body
|
||||
* custom element will be added after the body tag is opened, eg. to show a logo etc.
|
||||
* @access public
|
||||
* @param char element
|
||||
*/
|
||||
void WiFiManager::setCustomBodyHeader(const char* html) {
|
||||
_customBodyHeader = html;
|
||||
}
|
||||
|
||||
/**
|
||||
* set custom html at the bottom of the body
|
||||
* custom element will be added before the body tag is closed
|
||||
* @access public
|
||||
* @param char element
|
||||
*/
|
||||
void WiFiManager::setCustomBodyFooter(const char* html) {
|
||||
_customBodyFooter = html;
|
||||
}
|
||||
|
||||
/**
|
||||
* set custom menu html
|
||||
* custom element will be added to menu under custom menu item.
|
||||
* @access public
|
||||
* @param char element
|
||||
*/
|
||||
void WiFiManager::setCustomMenuHTML(const char* html) {
|
||||
_customMenuHTML = html;
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle wifiscan hiding of duplicate ssid names
|
||||
* if this is false, wifiscan will remove duplicat Access Points - defaut true
|
||||
@@ -1732,90 +1691,6 @@ void WiFiManager::setTitle(String title){
|
||||
_title = title;
|
||||
}
|
||||
|
||||
/**
|
||||
* set menu items and order
|
||||
* if param is present in menu , params will be removed from wifi page automatically
|
||||
* eg.
|
||||
* const char * menu[] = {"wifi","setup","sep","info","exit"};
|
||||
* WiFiManager.setMenu(menu);
|
||||
* @since $dev
|
||||
* @param uint8_t menu[] array of menu ids
|
||||
*/
|
||||
// Menu tokens (used by setMenu and handlers) - defined here, declared in WiFiManagerServer.h
|
||||
const char _wifi_token[] PROGMEM = "wifi";
|
||||
const char _wifinoscan_token[] PROGMEM = "wifinoscan";
|
||||
const char _info_token[] PROGMEM = "info";
|
||||
const char _param_token[] PROGMEM = "param";
|
||||
const char _close_token[] PROGMEM = "close";
|
||||
const char _restart_token[] PROGMEM = "restart";
|
||||
const char _exit_token[] PROGMEM = "exit";
|
||||
const char _erase_token[] PROGMEM = "erase";
|
||||
const char _update_token[] PROGMEM = "update";
|
||||
const char _sep_token[] PROGMEM = "sep";
|
||||
const char _custom_token[] PROGMEM = "custom";
|
||||
PGM_P _menutokens[] PROGMEM = {
|
||||
_wifi_token,
|
||||
_wifinoscan_token,
|
||||
_info_token,
|
||||
_param_token,
|
||||
_close_token,
|
||||
_restart_token,
|
||||
_exit_token,
|
||||
_erase_token,
|
||||
_update_token,
|
||||
_sep_token,
|
||||
_custom_token
|
||||
};
|
||||
const uint8_t _nummenutokens = (sizeof(_menutokens) / sizeof(PGM_P));
|
||||
|
||||
void WiFiManager::setMenu(const char * menu[], uint8_t size){
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
// DEBUG_WM(WM_DEBUG_DEV,"setmenu array");
|
||||
#endif
|
||||
_menuIds.clear();
|
||||
for(size_t i = 0; i < size; i++){
|
||||
for(size_t j = 0; j < _nummenutokens; j++){
|
||||
if((String)menu[i] == (__FlashStringHelper *)(_menutokens[j])){
|
||||
if((String)menu[i] == "param") _paramsInWifi = false; // param auto flag
|
||||
_menuIds.push_back(j);
|
||||
}
|
||||
delay(0);
|
||||
}
|
||||
delay(0);
|
||||
}
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
// DEBUG_WM(getMenuOut());
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* setMenu with vector
|
||||
* eg.
|
||||
* std::vector<const char *> menu = {"wifi","setup","sep","info","exit"};
|
||||
* WiFiManager.setMenu(menu);
|
||||
* tokens can be found in _menutokens array in strings_en.h
|
||||
* @shiftIncrement $dev
|
||||
* @param {[type]} std::vector<const char *>& menu [description]
|
||||
*/
|
||||
void WiFiManager::setMenu(std::vector<const char *>& menu){
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
// DEBUG_WM(WM_DEBUG_DEV,"setmenu vector");
|
||||
#endif
|
||||
_menuIds.clear();
|
||||
for(auto menuitem : menu ){
|
||||
for(size_t j = 0; j < _nummenutokens; j++){
|
||||
if((String)menuitem == (__FlashStringHelper *)(_menutokens[j])){
|
||||
if((String)menuitem == "param") _paramsInWifi = false; // param auto flag
|
||||
_menuIds.push_back(j);
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
// DEBUG_WM(WM_DEBUG_DEV,getMenuOut());
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set params as separate page not in wifi
|
||||
* NOT COMPATIBLE WITH setMenu!
|
||||
@@ -1823,7 +1698,6 @@ void WiFiManager::setMenu(std::vector<const char *>& menu){
|
||||
*/
|
||||
void WiFiManager::setParamsPage(bool enable){
|
||||
_paramsInWifi = !enable;
|
||||
setMenu(enable ? _menuIdsParams : _menuIdsDefault);
|
||||
}
|
||||
|
||||
// GETTERS
|
||||
@@ -1891,22 +1765,6 @@ void WiFiManager::setCountry(String cc){
|
||||
_wificountry = cc;
|
||||
}
|
||||
|
||||
/**
|
||||
* setClass
|
||||
* @param String str body class string
|
||||
*/
|
||||
void WiFiManager::setClass(String str){
|
||||
_bodyClass = str;
|
||||
}
|
||||
|
||||
/**
|
||||
* setDarkMode
|
||||
* @param bool enable, enable dark mode via invert class
|
||||
*/
|
||||
void WiFiManager::setDarkMode(bool enable){
|
||||
_bodyClass = enable ? "invert" : "";
|
||||
}
|
||||
|
||||
/**
|
||||
* setHttpPort
|
||||
* @param uint16_t port webserver port number default 80
|
||||
|
||||
@@ -16,62 +16,34 @@
|
||||
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
|
||||
WiFiManagerHandlers::WiFiManagerHandlers(WiFiManager* wm) : _wm(wm) {
|
||||
}
|
||||
WiFiManagerHandlers::WiFiManagerHandlers(WiFiManager* wm) : _wm(wm) {}
|
||||
|
||||
// Rendering Methods
|
||||
|
||||
String WiFiManagerHandlers::getHTTPHead(String title, String classes){
|
||||
String page;
|
||||
// Use template for HTML head start
|
||||
page += FPSTR(HTML_HEAD_START);
|
||||
page += title;
|
||||
page += FPSTR(HTML_TITLE_END);
|
||||
page += FPSTR(JS_SCRIPT);
|
||||
page += FPSTR(CSS_STYLE);
|
||||
page += _wm->_customHeadElement;
|
||||
|
||||
// Build body tag with classes using template
|
||||
page += FPSTR(HTML_HEAD_END_START);
|
||||
if (_wm->_bodyClass != "") {
|
||||
if (classes != "") {
|
||||
classes += " "; // add spacing, if necessary
|
||||
}
|
||||
classes += _wm->_bodyClass; // add class str
|
||||
}
|
||||
page += classes;
|
||||
page += FPSTR(HTML_HEAD_END_WRAP);
|
||||
|
||||
if (_wm->_customBodyHeader) {
|
||||
page += _wm->_customBodyHeader;
|
||||
}
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
String WiFiManagerHandlers::getHTTPEnd() {
|
||||
String end = FPSTR(HTML_END);
|
||||
|
||||
if (_wm->_customBodyFooter) {
|
||||
end = String(_wm->_customBodyFooter) + end;
|
||||
}
|
||||
|
||||
return end;
|
||||
return FPSTR(HTML_END);
|
||||
}
|
||||
|
||||
String WiFiManagerHandlers::getMenuOut(){
|
||||
String page;
|
||||
|
||||
for(auto menuId : _wm->_menuIds ){
|
||||
if((String)_menutokens[menuId] == "param" && _wm->_paramsCount == 0) continue; // no params set, omit params from menu, @todo this may be undesired by someone, use only menu to force?
|
||||
if((String)_menutokens[menuId] == "custom" && _wm->_customMenuHTML!=NULL){
|
||||
page += _wm->_customMenuHTML;
|
||||
continue;
|
||||
}
|
||||
page += HTML_PORTAL_MENU[menuId];
|
||||
delay(0);
|
||||
}
|
||||
|
||||
page += HTML_PORTAL_MENU[0]; // WIFI
|
||||
page += HTML_PORTAL_MENU[2]; // INFO
|
||||
page += HTML_PORTAL_MENU[6]; // EXIT
|
||||
page += HTML_PORTAL_MENU[9]; // SEP
|
||||
page += HTML_PORTAL_MENU[8]; // UPDATE
|
||||
return page;
|
||||
}
|
||||
|
||||
|
||||
@@ -50,8 +50,6 @@ void test_ui_display_options() {
|
||||
wm.setShowInfoErase(false);
|
||||
wm.setShowInfoUpdate(true);
|
||||
wm.setShowInfoUpdate(false);
|
||||
wm.setDarkMode(true);
|
||||
wm.setDarkMode(false);
|
||||
wm.setParamsPage(true);
|
||||
wm.setParamsPage(false);
|
||||
|
||||
@@ -67,26 +65,8 @@ void test_ui_customization() {
|
||||
|
||||
WiFiManager wm;
|
||||
|
||||
// Test custom HTML elements
|
||||
wm.setCustomHeadElement("<style>body { background: red; }</style>");
|
||||
wm.setCustomHeadElement("");
|
||||
wm.setCustomBodyHeader("<div>Custom Header</div>");
|
||||
wm.setCustomBodyHeader("");
|
||||
wm.setCustomBodyFooter("<div>Custom Footer</div>");
|
||||
wm.setCustomBodyFooter("");
|
||||
wm.setCustomMenuHTML("<div>Custom Menu</div>");
|
||||
wm.setCustomMenuHTML("");
|
||||
|
||||
// Test menu configuration
|
||||
const char* menu[] = {"wifi", "info", "exit"};
|
||||
wm.setMenu(menu, 3);
|
||||
std::vector<const char*> menuVec = {"wifi", "info", "param", "exit"};
|
||||
wm.setMenu(menuVec);
|
||||
|
||||
// Test CSS class
|
||||
wm.setClass("invert");
|
||||
wm.setClass("custom-class");
|
||||
wm.setClass("");
|
||||
// Minimal customization retained: title
|
||||
wm.setTitle("MyDevice");
|
||||
|
||||
// All setters executed without crash
|
||||
TEST_ASSERT_TRUE_MESSAGE(true, "UI customization options executed without crash");
|
||||
|
||||
Reference in New Issue
Block a user