mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-09 09:19:51 +03:00
refactored restart and format services to be non-blocking
This commit is contained in:
@@ -156,7 +156,7 @@ void WebCustomizationService::reset_customization(AsyncWebServerRequest * reques
|
||||
if (LittleFS.remove(EMSESP_CUSTOMIZATION_FILE)) {
|
||||
AsyncWebServerResponse * response = request->beginResponse(205); // restart needed
|
||||
request->send(response);
|
||||
EMSESP::system_.restart_requested(true);
|
||||
EMSESP::system_.restart_pending(true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -156,7 +156,8 @@ StateUpdateResult WebSettings::update(JsonObject root, WebSettings & settings) {
|
||||
} else {
|
||||
EMSESP::nvs_.putString("boot", "S32");
|
||||
}
|
||||
ESP.restart();
|
||||
// ESP.restart();
|
||||
EMSESP::system_.restart_requested(true);
|
||||
#elif CONFIG_IDF_TARGET_ESP32C3
|
||||
settings.board_profile = "C3MINI";
|
||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||
|
||||
@@ -34,12 +34,6 @@ WebStatusService::WebStatusService(AsyncWebServer * server, SecurityManager * se
|
||||
|
||||
// /rest/systemStatus
|
||||
void WebStatusService::systemStatus(AsyncWebServerRequest * request) {
|
||||
// This is a litle trick for the OTA upload. We don't want the React RestartService to think we're finished
|
||||
// with the upload so we fake it and pretent the /rest/systemStatus is not available. That way the spinner keeps spinning.
|
||||
if (EMSESP::system_.upload_status()) {
|
||||
return; // ignore endpoint
|
||||
}
|
||||
|
||||
EMSESP::system_.refreshHeapMem(); // refresh free heap and max alloc heap
|
||||
|
||||
auto * response = new AsyncJsonResponse(false);
|
||||
@@ -85,6 +79,7 @@ void WebStatusService::systemStatus(AsyncWebServerRequest * request) {
|
||||
}
|
||||
|
||||
// /rest/hardwareStatus
|
||||
// This is also used for polling
|
||||
void WebStatusService::hardwareStatus(AsyncWebServerRequest * request) {
|
||||
EMSESP::system_.refreshHeapMem(); // refresh free heap and max alloc heap
|
||||
|
||||
@@ -144,6 +139,14 @@ void WebStatusService::hardwareStatus(AsyncWebServerRequest * request) {
|
||||
root["has_partition"] = false;
|
||||
}
|
||||
|
||||
// Matches RestartMonitor.tsx
|
||||
if (EMSESP::system_.restart_pending()) {
|
||||
root["status"] = "restarting";
|
||||
EMSESP::system_.restart_requested(true); // tell emsesp loop to start restart
|
||||
} else {
|
||||
root["status"] = EMSESP::system_.upload_status() ? "uploading" : "ready";
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
response->setLength();
|
||||
|
||||
Reference in New Issue
Block a user