From 7c6101e8190427a5047114501199e181ebe1f2c6 Mon Sep 17 00:00:00 2001 From: proddy Date: Sat, 26 Sep 2026 21:03:17 +0200 Subject: [PATCH] prevent reboot on filesystem upload --- src/core/emsesp.cpp | 17 +++++++++-------- src/core/system.cpp | 23 ++++++++++++----------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/core/emsesp.cpp b/src/core/emsesp.cpp index 6fecba8f9..8f26c0e6e 100644 --- a/src/core/emsesp.cpp +++ b/src/core/emsesp.cpp @@ -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()); diff --git a/src/core/system.cpp b/src/core/system.cpp index 3d24b4f61..a0bc7306a 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -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(); 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