prevent reboot on filesystem upload

This commit is contained in:
proddy
2026-09-26 21:03:17 +02:00
parent 684d6b132d
commit 7c6101e819
2 changed files with 21 additions and 19 deletions
+9 -8
View File
@@ -1774,6 +1774,15 @@ void EMSESP::start() {
// start web log service. now we can start capturing logs to the web log
webLogService.begin();
#ifndef EMSESP_STANDALONE
// apply any uploaded settings before any service loads them from the filesystem
if (system_.check_restore()) {
root = LittleFS.open(EMSESP_SETTINGS_FILE);
factory_settings = !root;
root.close();
}
#endif
// loads core system services settings (mqtt, ap, ntp etc)
esp32React.begin();
@@ -1829,14 +1838,6 @@ void EMSESP::start() {
LOG_INFO("Last system reset reason Core0: %s, Core1: %s", system_.reset_reason(0).c_str(), system_.reset_reason(1).c_str());
#endif
// see if we're restoring a settings file
#ifndef EMSESP_STANDALONE
if (system_.check_restore()) {
LOG_WARNING("EMS-ESP will restart to apply new settings. Please wait.");
system_.system_restart();
};
#endif
webSettingsService.begin(); // load EMS-ESP Application settings
LOG_DEBUG("System name: %s", system_.system_name().c_str());
+12 -11
View File
@@ -1362,8 +1362,9 @@ void System::show_system(uuid::console::Shell & shell) {
// see if there is a restore of an older settings file that needs to be applied
// note there can be only one file at a time
// called at boot before any services load their settings, returns true if system settings files were restored
bool System::check_restore() {
bool reboot_required = false; // true if we need to reboot
bool settings_restored = false; // true if system settings files were restored
#ifndef EMSESP_STANDALONE
File new_file = LittleFS.open(TEMP_FILENAME_PATH);
@@ -1378,7 +1379,7 @@ bool System::check_restore() {
// system backup, which is a consolidated json object with all the settings files
if (settings_type == "systembackup") {
reboot_required = true;
settings_restored = true;
JsonArray sections = input["systembackup"].as<JsonArray>();
for (JsonObject section : sections) {
std::string section_type = section["type"];
@@ -1507,14 +1508,14 @@ bool System::check_restore() {
}
}
// It's a single settings file. Parse each section separately. If it's system related it will require a reboot
// It's a single settings file. Parse each section separately
else if (settings_type == "settings") {
reboot_required = saveSettings(NETWORK_SETTINGS_FILE, input);
reboot_required |= saveSettings(AP_SETTINGS_FILE, input);
reboot_required |= saveSettings(MQTT_SETTINGS_FILE, input);
reboot_required |= saveSettings(NTP_SETTINGS_FILE, input);
reboot_required |= saveSettings(SECURITY_SETTINGS_FILE, input);
reboot_required |= saveSettings(EMSESP_SETTINGS_FILE, input);
settings_restored = saveSettings(NETWORK_SETTINGS_FILE, input);
settings_restored |= saveSettings(AP_SETTINGS_FILE, input);
settings_restored |= saveSettings(MQTT_SETTINGS_FILE, input);
settings_restored |= saveSettings(NTP_SETTINGS_FILE, input);
settings_restored |= saveSettings(SECURITY_SETTINGS_FILE, input);
settings_restored |= saveSettings(EMSESP_SETTINGS_FILE, input);
} else if (settings_type == "customizations") {
saveSettings(EMSESP_CUSTOMIZATION_FILE, input);
} else if (settings_type == "schedule") {
@@ -1526,7 +1527,7 @@ bool System::check_restore() {
new_file.close();
if (LittleFS.rename(TEMP_FILENAME_PATH, EMSESP_CUSTOMSUPPORT_FILE)) {
LOG_INFO("Custom support file stored");
return false; // no need to reboot
return false;
} else {
LOG_ERROR("Failed to save custom support file");
}
@@ -1543,7 +1544,7 @@ bool System::check_restore() {
}
#endif
return reboot_required;
return settings_restored;
}
// handle upgrades from previous versions