From fe37d428b8079b8f5350bf6fb89e6f76c95a8d2e Mon Sep 17 00:00:00 2001 From: Peter Feerick Date: Wed, 16 Mar 2022 21:21:53 +1000 Subject: [PATCH] fix: colorlcd "Global" bg image not being loaded at theme change (#1684) Fixes #1680 --- radio/src/gui/colorlcd/theme_manager.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/radio/src/gui/colorlcd/theme_manager.cpp b/radio/src/gui/colorlcd/theme_manager.cpp index cea93beb5..d7ce4153b 100644 --- a/radio/src/gui/colorlcd/theme_manager.cpp +++ b/radio/src/gui/colorlcd/theme_manager.cpp @@ -300,7 +300,25 @@ void ThemeFile::applyBackground() if (pos != std::string::npos) { auto rootDir = backgroundImageFileName.substr(0, pos + 1); rootDir = rootDir + "background_" + std::to_string(LCD_W) + "x" + std::to_string(LCD_H) + ".png"; - instance->setBackgroundImageFileName((char *)rootDir.c_str()); + + FIL file; + FRESULT result = f_open(&file, rootDir.c_str(), FA_OPEN_EXISTING); + if (result == FR_OK) { + instance->setBackgroundImageFileName((char *)rootDir.c_str()); + } else { + // TODO: This needs to be made user configurable, not + // require the file be deleted to remove global background + char fileName[FF_MAX_LFN + 1]; + fileName[FF_MAX_LFN] = '\0'; + strncpy(fileName, THEMES_PATH, FF_MAX_LFN); + strcat(fileName, "/EdgeTX/background.png"); + result = f_open(&file, fileName, FA_OPEN_EXISTING); + if (result == FR_OK) { + instance->setBackgroundImageFileName(fileName); + } else { + instance->setBackgroundImageFileName(""); + } + } } else { instance->setBackgroundImageFileName(""); }