diff --git a/wled00/fcn_declare.h b/wled00/fcn_declare.h index ff44bbd9..38a18b09 100644 --- a/wled00/fcn_declare.h +++ b/wled00/fcn_declare.h @@ -93,6 +93,7 @@ bool readObjectFromFileUsingId(const char* file, uint16_t id, JsonDocument* dest bool readObjectFromFile(const char* file, const char* key, JsonDocument* dest); void updateFSInfo(); void closeFile(); +void invalidateFileNameCache(); // WLEDMM call when new files were uploaded //hue.cpp void handleHue(); diff --git a/wled00/file.cpp b/wled00/file.cpp index 9d6e6a1e..84f99c09 100644 --- a/wled00/file.cpp +++ b/wled00/file.cpp @@ -407,10 +407,33 @@ static String getContentType(AsyncWebServerRequest* request, String filename){ return "text/plain"; } +// WLEDMM +static bool haveLedmapFile = true; +static bool haveIndexFile = true; +static bool haveSkinFile = true; +static bool haveICOFile = true; +static bool haveCpalFile = true; +void invalidateFileNameCache() { // reset "file not found" cache + haveLedmapFile = true; + haveIndexFile = true; + haveSkinFile = true; + haveICOFile = true; + haveCpalFile = true; +} + bool handleFileRead(AsyncWebServerRequest* request, String path){ DEBUG_PRINTLN("WS FileRead: " + path); if(path.endsWith("/")) path += "index.htm"; if(path.indexOf("sec") > -1) return false; + + // WLEDMM shortcuts + if ((haveLedmapFile == false) && path.equals("/ledmap.json")) return false; + if ((haveIndexFile == false) && path.equals("/index.htm")) return false; + if ((haveSkinFile == false) && path.equals("/skin.css")) return false; + if ((haveICOFile == false) && path.equals("/favicon.ico")) return false; + if ((haveCpalFile == false) && path.equals("/cpal.htm")) return false; + // WLEDMM toDO: add file caching (PSRAM) for /presets.json an /cfg.json + String contentType = getContentType(request, path); /*String pathWithGz = path + ".gz"; if(WLED_FS.exists(pathWithGz)){ @@ -421,5 +444,13 @@ bool handleFileRead(AsyncWebServerRequest* request, String path){ request->send(WLED_FS, path, contentType); return true; } + //USER_PRINTLN("WS FileRead failed: " + path + " (" + contentType + ")"); + + // WLEDMM cache "file not found" results (reduces LED flickering during UI activities) + if (path.equals("/ledmap.json")) haveLedmapFile = false; + if (path.equals("/index.htm")) haveIndexFile = false; + if (path.equals("/skin.css")) haveSkinFile = false; + if (path.equals("/favicon.ico")) haveICOFile = false; + if (path.equals("/cpal.htm")) haveCpalFile = false; return false; } diff --git a/wled00/wled.h b/wled00/wled.h index dc3ee12b..36170286 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2404260 +#define VERSION 2404280 // WLEDMM - you can check for this define in usermods, to only enabled WLEDMM specific code in the "right" fork. Its not defined in AC WLED. #define _MoonModules_WLED_ diff --git a/wled00/wled_server.cpp b/wled00/wled_server.cpp index a08e9ea6..f3fe1c08 100644 --- a/wled00/wled_server.cpp +++ b/wled00/wled_server.cpp @@ -58,6 +58,7 @@ void handleUpload(AsyncWebServerRequest *request, const String& filename, size_t request->_tempFile.close(); USER_PRINT(F("File uploaded: ")); // WLEDMM USER_PRINTLN(filename); // WLEDMM + invalidateFileNameCache(); // WLEDMM if (filename.equalsIgnoreCase("/cfg.json") || filename.equalsIgnoreCase("cfg.json")) { // WLEDMM request->send(200, "text/plain", F("Configuration restore successful.\nRebooting...")); doReboot = true;