From f0c3bb2c143c49d7083fa07d63c8156a8285ad54 Mon Sep 17 00:00:00 2001 From: tt2468 Date: Sat, 5 Jun 2021 22:18:39 -0700 Subject: [PATCH] Config: Don't persist debug mode to config A request from the OBS developers. Debug mode tends to be enabled, then not remembered to be disabled, leading to logs that are both long and difficult to read. In some cases, the OBS logviewer may noticeably lock up the UI just trying to parse the long log file. --- data/locale/en-US.ini | 2 +- src/Config.cpp | 7 ++++--- src/utils/Platform.cpp | 10 ++++++++++ src/utils/Utils.h | 1 + 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/data/locale/en-US.ini b/data/locale/en-US.ini index af400081..6986f9a9 100644 --- a/data/locale/en-US.ini +++ b/data/locale/en-US.ini @@ -4,7 +4,7 @@ OBSWebSocket.Settings.PluginSettingsTitle="Plugin Settings" OBSWebSocket.Settings.ServerEnable="Enable WebSocket server" OBSWebSocket.Settings.AlertsEnable="Enable System Tray Alerts" OBSWebSocket.Settings.DebugEnable="Enable Debug Logging" -OBSWebSocket.Settings.DebugEnableHoverText="Changing this requires the WebSocket server to restart. However, changing this will not automatically restart the obs-websocket server." +OBSWebSocket.Settings.DebugEnableHoverText="Enables debug logging for the current instance of OBS. Does not persist on load. Use --websocket_debug to enable on load." OBSWebSocket.Settings.ServerSettingsTitle="Server Settings" OBSWebSocket.Settings.AuthRequired="Enable Authentication" diff --git a/src/Config.cpp b/src/Config.cpp index 058bb782..ecbf4e89 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -17,6 +17,7 @@ #define CMDLINE_WEBSOCKET_PORT "websocket_port" #define CMDLINE_WEBSOCKET_PASSWORD "websocket_password" +#define CMDLINE_WEBSOCKET_DEBUG "websocket_debug" Config::Config() : FirstLoad(true), @@ -42,7 +43,6 @@ void Config::Load() FirstLoad = config_get_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_FIRSTLOAD); ServerEnabled = config_get_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_ENABLED); - DebugEnabled = config_get_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_DEBUG); AlertsEnabled = config_get_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_ALERTS); QString portArgument = Utils::Platform::GetCommandLineArgument(CMDLINE_WEBSOCKET_PORT); @@ -74,6 +74,9 @@ void Config::Load() ServerPassword = config_get_string(obsConfig, CONFIG_SECTION_NAME, PARAM_PASSWORD); } } + + if (Utils::Platform::GetCommandLineFlagSet(CMDLINE_WEBSOCKET_DEBUG)) // Debug does not persist on reload, so we let people override it with a flag. + DebugEnabled = true; } void Config::Save() @@ -89,7 +92,6 @@ void Config::Save() if (!PortOverridden) { config_set_uint(obsConfig, CONFIG_SECTION_NAME, PARAM_PORT, ServerPort); } - config_set_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_DEBUG, DebugEnabled); config_set_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_ALERTS, AlertsEnabled); if (!PasswordOverridden) { config_set_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_AUTHREQUIRED, AuthRequired); @@ -110,7 +112,6 @@ void Config::SetDefaultsToGlobalStore() config_set_default_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_FIRSTLOAD, FirstLoad); config_set_default_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_ENABLED, ServerEnabled); config_set_default_uint(obsConfig, CONFIG_SECTION_NAME, PARAM_PORT, ServerPort); - config_set_default_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_DEBUG, DebugEnabled); config_set_default_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_ALERTS, AlertsEnabled); config_set_default_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_AUTHREQUIRED, AuthRequired); config_set_default_string(obsConfig, CONFIG_SECTION_NAME, PARAM_PASSWORD, QT_TO_UTF8(ServerPassword)); diff --git a/src/utils/Platform.cpp b/src/utils/Platform.cpp index 373b23e5..8790e4e1 100644 --- a/src/utils/Platform.cpp +++ b/src/utils/Platform.cpp @@ -55,3 +55,13 @@ QString Utils::Platform::GetCommandLineArgument(QString arg) return parser.value(cmdlineOption); } + +bool Utils::Platform::GetCommandLineFlagSet(QString arg) +{ + QCommandLineParser parser; + QCommandLineOption cmdlineOption(arg, arg, arg, ""); + parser.addOption(cmdlineOption); + parser.parse(QCoreApplication::arguments()); + + return parser.isSet(cmdlineOption); +} diff --git a/src/utils/Utils.h b/src/utils/Utils.h index 701472e2..3bd7fcf5 100644 --- a/src/utils/Utils.h +++ b/src/utils/Utils.h @@ -24,6 +24,7 @@ namespace Utils { namespace Platform { std::string GetLocalAddress(); QString GetCommandLineArgument(QString arg); + bool GetCommandLineFlagSet(QString arg); } namespace Obs {