diff --git a/mkdocs/advancedusage.md b/mkdocs/advancedusage.md
index f905e4b..e84e9bb 100644
--- a/mkdocs/advancedusage.md
+++ b/mkdocs/advancedusage.md
@@ -285,8 +285,9 @@ portal.append("/hello", "HELLO", [](){
For more details, see section [Attach the menu](menuize.md) of Examples page.
-!!! note "Necessary ESP8266WebServer/WebServer has materialized"
- The WebServer must have instantiated for calling with a request handler parameter. AutoConnect can instantiate and host a WebServer internally, but in that case, the point in time to call the [AutoConnct::append](api.md#append) function with a request handler parameter must be after [AutoConnect::begin](api.md#begin).
+!!! note "An instance of ESP8266WebServer/WebServer is needed"
+ When calling the append function with request handler parameters, an instance of the WebServer as the registration destination must exist.
+ AutoConnect can instantiate and host a WebServer internally, but in that case, the point in time to call the [AutoConnct::append](api.md#append) function with a request handler parameter must be after [AutoConnect::begin](api.md#begin).
### Change the menu labels
diff --git a/mkdocs/api.md b/mkdocs/api.md
index cfb688b..3e09aab 100644
--- a/mkdocs/api.md
+++ b/mkdocs/api.md
@@ -99,7 +99,7 @@ Returns the pointer to created AutoConnectAux instance, the `nullptr` if an Auto
A Pointer to a created AutoConnectAux instance.
-!!! note "Necessary ESP8266WebServer/WebServer has materialized"
+!!! note "An instance of ESP8266WebServer/WebServer is needed"
The WebServer must have instantiated for calling with a request handler parameter. AutoConnect can instantiate and host a WebServer internally, but in that case, the point in time to call the append function with a request handler parameter must be after AutoConnect::begin.
### aux
@@ -162,18 +162,21 @@ Set SoftAP's WiFi configuration and static IP configuration.
### detach
```cpp
-AutoConnectAux* detach(const String& uri)
+bool detach(const String& uri)
```
Detach the AutoConnectAux with the specified URI from the management of AutoConnect. An unmanaged AutoConnectAux will no longer appear in menu items, and its page handler will no longer respond even if the URI is accessed directly.
- **Parameter**
- uriURI of AutoConnectAux to be detached.
+ - **Return value**
+ - trueSuccessfully detached.
+ - falseAn AutoConnectAux with the specified URI does not exist.
If the request handler registered in the detaching AutoConnectAux is for a legacy page of the ESP8266WebServer/WebServer, the URI is still valid after detaching. AutoConnect does not delete the request handler registered to ESP8266WebServer/WebServer with the `on` function. (It cannot be removed)
!!! hint "Deleting the AutoConnectAux"
- You can use the return value from the AotoConnect::detach to delete the AutoConnectAux instance which dynamically created with the [AutoConnect::append](api.md#append).
+ If the AutoConnectAux to detach was added by [AutoConnect::append](api.md#append), it will be automatically removed and freed from memory.
### disableMenu
diff --git a/src/AutoConnect.cpp b/src/AutoConnect.cpp
index 7a33525..793958c 100644
--- a/src/AutoConnect.cpp
+++ b/src/AutoConnect.cpp
@@ -586,6 +586,7 @@ AutoConnectAux* AutoConnect::append(const String& uri, const String& title) {
AutoConnectAux* reg = aux(uri);
if (!reg) {
reg = new AutoConnectAux(uri, title);
+ reg->_deletable = true;
join(*reg);
return reg;
}
@@ -611,6 +612,7 @@ AutoConnectAux* AutoConnect::append(const String& uri, const String& title, WebS
_webServer->on(uri, handler);
return reg;
}
+ AC_DBG("No WebServer instance\n");
return nullptr;
}
@@ -620,19 +622,21 @@ AutoConnectAux* AutoConnect::append(const String& uri, const String& title, WebS
* @return true Specified AUX has released
* @return false Specified AUX not registered
*/
-AutoConnectAux* AutoConnect::detach(const String &uri) {
+bool AutoConnect::detach(const String &uri) {
AutoConnectAux** self = &_aux;
while (*self) {
if (!strcmp((*self)->uri(), uri.c_str())) {
AC_DBG("%s released\n", (*self)->uri());
AutoConnectAux* ref = *self;
*self = (*self)->_next;
- return ref;
+ if (ref->_deletable)
+ delete ref;
+ return true;
}
self = &((*self)->_next);
}
AC_DBG("%s not listed\n", uri.c_str());
- return nullptr;
+ return false;
}
/**
diff --git a/src/AutoConnect.h b/src/AutoConnect.h
index 497d588..1753fbb 100644
--- a/src/AutoConnect.h
+++ b/src/AutoConnect.h
@@ -232,7 +232,7 @@ class AutoConnect {
AutoConnectAux* aux(const String& uri) const;
AutoConnectAux* append(const String& uri, const String& title);
AutoConnectAux* append(const String& uri, const String& title, WebServerClass::THandlerFunction handler);
- AutoConnectAux* detach(const String& uri);
+ bool detach(const String& uri);
inline void disableMenu(const uint16_t items) { _apConfig.menuItems &= (0xffff ^ items); }
inline void enableMenu(const uint16_t items) { _apConfig.menuItems |= items; }
void join(AutoConnectAux& aux);
diff --git a/src/AutoConnectAux.h b/src/AutoConnectAux.h
index 66647be..da928ef 100644
--- a/src/AutoConnectAux.h
+++ b/src/AutoConnectAux.h
@@ -148,6 +148,7 @@ class AutoConnectAux : public PageBuilder {
String _title; /**< A title of the page */
bool _menu; /**< Switch for menu displaying */
+ bool _deletable = false; /**< Allow deleting itself. */
AC_AUTH_t _httpAuth = AC_AUTH_NONE; /**< Applying HTTP authentication */
String _uriStr; /**< uri as String */
AutoConnectElementVT _addonElm; /**< A vector set of AutoConnectElements placed on this auxiliary page */