From d576cbc03fc72907857b93b98bb0d2aeecd321e7 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Mon, 2 Oct 2023 19:59:13 +0200 Subject: [PATCH] Added a 'Debug mode' option to the Other settings menu --- es-app/src/guis/GuiMenu.cpp | 33 +++++++++++++++++++++++++++++++++ es-app/src/main.cpp | 9 ++++++++- es-core/src/Settings.cpp | 5 ++++- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index ce69cede5..7d68741c4 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -1546,6 +1546,39 @@ void GuiMenu::openOtherOptions() }); #endif + if (Settings::getInstance()->getBool("DebugFlag")) { + // If the --debug command line option was passed then create a dummy entry. + auto debugMode = std::make_shared(); + debugMode->setState(true); + s->addWithLabel("DEBUG MODE", debugMode); + debugMode->setEnabled(false); + debugMode->setOpacity(DISABLED_OPACITY); + debugMode->getParent() + ->getChild(debugMode->getChildIndex() - 1) + ->setOpacity(DISABLED_OPACITY); + } + else { + // Debug mode. + auto debugMode = std::make_shared(); + debugMode->setState(Settings::getInstance()->getBool("DebugMode")); + s->addWithLabel("DEBUG MODE", debugMode); + s->addSaveFunc([debugMode, s] { + if (debugMode->getState() != Settings::getInstance()->getBool("DebugMode")) { + if (!Settings::getInstance()->getBool("DebugMode")) { + Settings::getInstance()->setBool("DebugMode", true); + Settings::getInstance()->setBool("Debug", true); + Log::setReportingLevel(LogDebug); + } + else { + Settings::getInstance()->setBool("DebugMode", false); + Settings::getInstance()->setBool("Debug", false); + Log::setReportingLevel(LogInfo); + } + s->setNeedsSaving(); + } + }); + } + // GPU statistics overlay. auto displayGpuStatistics = std::make_shared(); displayGpuStatistics->setState(Settings::getInstance()->getBool("DisplayGPUStatistics")); diff --git a/es-app/src/main.cpp b/es-app/src/main.cpp index b5afd99c5..b0c79d97a 100644 --- a/es-app/src/main.cpp +++ b/es-app/src/main.cpp @@ -382,6 +382,7 @@ bool parseArguments(const std::vector& arguments) } else if (arguments[i] == "--debug") { Settings::getInstance()->setBool("Debug", true); + Settings::getInstance()->setBool("DebugFlag", true); Log::setReportingLevel(LogDebug); } else if (arguments[i] == "--version" || arguments[i] == "-v") { @@ -419,7 +420,7 @@ bool parseArguments(const std::vector& arguments) " --force-input-config Force configuration of input devices\n" " --create-system-dirs Create game system directories\n" " --home [path] Directory to use as home path\n" -" --debug Print debug information\n" +" --debug Enable debug mode\n" " --version, -v Display version information\n" " --help, -h Summon a sentient, angry tuba\n"; // clang-format on @@ -570,6 +571,12 @@ int main(int argc, char* argv[]) #endif } + if (!Settings::getInstance()->getBool("DebugFlag") && + Settings::getInstance()->getBool("DebugMode")) { + Settings::getInstance()->setBool("Debug", true); + Log::setReportingLevel(LogDebug); + } + #if defined(FREEIMAGE_LIB) // Call this ONLY when linking with FreeImage as a static library. FreeImage_Initialise(); diff --git a/es-core/src/Settings.cpp b/es-core/src/Settings.cpp index 073ae51a0..85b469429 100644 --- a/es-core/src/Settings.cpp +++ b/es-core/src/Settings.cpp @@ -38,7 +38,8 @@ namespace "ForceFull", // --force-full "ForceKiosk", // --force-kiosk "ForceKid", // --force-kid - "Debug", // --debug + "Debug", // Whether we're in debug mode. + "DebugFlag", // Whether the --debug flag was passed. // These options are only used internally during the application session: "PortableMode", @@ -288,6 +289,7 @@ void Settings::setDefaults() #if defined(__unix__) mBoolMap["DisableComposition"] = {false, false}; #endif + mBoolMap["DebugMode"] = {false, false}; mBoolMap["DisplayGPUStatistics"] = {false, false}; mBoolMap["EnableMenuKidMode"] = {false, false}; // macOS requires root privileges to reboot and power off so it doesn't make much @@ -339,6 +341,7 @@ void Settings::setDefaults() mStringMap["ApplicationVersion"] = {"", ""}; mStringMap["ApplicationUpdaterLastCheck"] = {"", ""}; mBoolMap["PortableMode"] = {false, false}; + mBoolMap["DebugFlag"] = {false, false}; mBoolMap["DebugGrid"] = {false, false}; mBoolMap["DebugText"] = {false, false}; mBoolMap["DebugImage"] = {false, false};