From aba38b949f6d22d23e73aff8df64d27046bb267d Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Tue, 4 Nov 2025 11:27:52 -0500 Subject: [PATCH] feat: add new setting Log::GuiDebug to control when the Gui shows debug messages no longer controled by an ENV var --- doc/user/configuration.md | 21 ---- src/apps/deskflow-gui/deskflow-gui.cpp | 1 - src/lib/common/Settings.h | 3 + src/lib/gui/Logger.cpp | 12 +-- src/lib/gui/Logger.h | 8 -- src/lib/gui/dialogs/SettingsDialog.cpp | 2 + src/lib/gui/dialogs/SettingsDialog.ui | 141 +++++++++++++------------ src/unittests/gui/LoggerTests.cpp | 25 +++-- src/unittests/gui/LoggerTests.h | 5 + translations/deskflow_es.ts | 4 + translations/deskflow_it.ts | 4 + 11 files changed, 113 insertions(+), 113 deletions(-) diff --git a/doc/user/configuration.md b/doc/user/configuration.md index b6b8b2b66..17cd8b15a 100644 --- a/doc/user/configuration.md +++ b/doc/user/configuration.md @@ -802,24 +802,3 @@ section: links down = larry end ``` - -# Example `.env` file - - -``` -# -# App -# - -# Shows the test menu in the GUI (on by default in debug mode) -# DESKFLOW_TEST_MENU=true - -# Version checker URL to use (useful for testing) -# DESKFLOW_VERSION_URL="https://api.deskflow.org/version?fake=1.100.0" - -# Enable debug logging in the GUI (on by default in debug mode) -# DESKFLOW_GUI_DEBUG=true - -# Enable verbose logging in the GUI (always off by default) -# DESKFLOW_GUI_VERBOSE=true -``` diff --git a/src/apps/deskflow-gui/deskflow-gui.cpp b/src/apps/deskflow-gui/deskflow-gui.cpp index f323da2eb..517fa9a79 100644 --- a/src/apps/deskflow-gui/deskflow-gui.cpp +++ b/src/apps/deskflow-gui/deskflow-gui.cpp @@ -133,7 +133,6 @@ int main(int argc, char *argv[]) qInfo("%s v%s", kAppName, kDisplayVersion); dotenv(); - Logger::instance()->loadEnvVars(); #if defined(Q_OS_MAC) diff --git a/src/lib/common/Settings.h b/src/lib/common/Settings.h index fb3b66464..bc0beb995 100644 --- a/src/lib/common/Settings.h +++ b/src/lib/common/Settings.h @@ -78,6 +78,7 @@ public: inline static const auto File = QStringLiteral("log/file"); inline static const auto Level = QStringLiteral("log/level"); inline static const auto ToFile = QStringLiteral("log/toFile"); + inline static const auto GuiDebug = QStringLiteral("log/guiDebug"); }; struct Security { @@ -185,6 +186,7 @@ private: , Settings::Log::File , Settings::Log::Level , Settings::Log::ToFile + , Settings::Log::GuiDebug , Settings::Gui::Autohide , Settings::Gui::AutoUpdateCheck , Settings::Gui::CloseReminder @@ -209,6 +211,7 @@ private: , Settings::Server::ExternalConfig , Settings::Client::InvertScrollDirection , Settings::Log::ToFile + , Settings::Log::GuiDebug }; // When checking the default values this list contains the ones that default to true. diff --git a/src/lib/gui/Logger.cpp b/src/lib/gui/Logger.cpp index 926499066..2d971fa1c 100644 --- a/src/lib/gui/Logger.cpp +++ b/src/lib/gui/Logger.cpp @@ -5,6 +5,7 @@ */ #include "Logger.h" +#include "common/Settings.h" #include #include @@ -49,14 +50,8 @@ QString printLine(FILE *out, const QString &type, const QString &message, const return logLine; } -void Logger::loadEnvVars() -{ - m_debug = QVariant(qEnvironmentVariable("DESKFLOW_GUI_DEBUG")).toBool(); -} - void Logger::handleMessage(const QtMsgType type, const QString &fileLine, const QString &message) { - auto mutatedType = type; if (kForceDebugMessages.contains(message)) { mutatedType = QtDebugMsg; @@ -66,10 +61,9 @@ void Logger::handleMessage(const QtMsgType type, const QString &fileLine, const auto out = stdout; switch (mutatedType) { case QtDebugMsg: - typeString = "DEBUG"; - if (!m_debug) { + if (!Settings::value(Settings::Log::GuiDebug).toBool()) return; - } + typeString = "DEBUG"; break; case QtInfoMsg: typeString = "INFO"; diff --git a/src/lib/gui/Logger.h b/src/lib/gui/Logger.h index 5519a4f17..6a560edc4 100644 --- a/src/lib/gui/Logger.h +++ b/src/lib/gui/Logger.h @@ -21,18 +21,10 @@ public: return &m; } - void loadEnvVars(); void handleMessage(const QtMsgType type, const QString &fileLine, const QString &message); Q_SIGNALS: void newLine(const QString &line); - -private: -#ifdef NDEBUG - bool m_debug = false; -#else - bool m_debug = true; -#endif }; } // namespace deskflow::gui diff --git a/src/lib/gui/dialogs/SettingsDialog.cpp b/src/lib/gui/dialogs/SettingsDialog.cpp index 62a2f81e1..1dc7c9ebc 100644 --- a/src/lib/gui/dialogs/SettingsDialog.cpp +++ b/src/lib/gui/dialogs/SettingsDialog.cpp @@ -177,6 +177,7 @@ void SettingsDialog::accept() Settings::setValue(Settings::Security::CheckPeers, ui->cbRequireClientCert->isChecked()); Settings::setValue(Settings::Client::ScrollSpeed, ui->sbScrollSpeed->value()); Settings::setValue(Settings::Core::Language, ui->comboLanguage->currentText()); + Settings::setValue(Settings::Log::GuiDebug, ui->cbGuiDebug->isChecked()); Settings::ProcessMode mode; if (ui->groupService->isChecked()) @@ -203,6 +204,7 @@ void SettingsDialog::loadFromConfig() ui->cbElevateDaemon->setChecked(Settings::value(Settings::Daemon::Elevate).toBool()); ui->cbAutoUpdate->setChecked(Settings::value(Settings::Gui::AutoUpdateCheck).toBool()); ui->sbScrollSpeed->setValue(Settings::value(Settings::Client::ScrollSpeed).toInt()); + ui->cbGuiDebug->setChecked(Settings::value(Settings::Log::GuiDebug).toBool()); const auto processMode = Settings::value(Settings::Core::ProcessMode).value(); ui->groupService->setChecked(processMode == Settings::ProcessMode::Service); diff --git a/src/lib/gui/dialogs/SettingsDialog.ui b/src/lib/gui/dialogs/SettingsDialog.ui index bf831c806..d4ea34fd9 100644 --- a/src/lib/gui/dialogs/SettingsDialog.ui +++ b/src/lib/gui/dialogs/SettingsDialog.ui @@ -417,7 +417,64 @@ 9 - + + + + + 0 + 0 + + + + Level + + + + + + + + Fatal + + + + + Error + + + + + Warning + + + + + Note + + + + + Info + + + + + Debug + + + + + Debug1 + + + + + Debug2 + + + + + @@ -505,7 +562,14 @@ - + + + + Log to file + + + + Qt::Orientation::Horizontal @@ -518,71 +582,7 @@ - - - - Log to file - - - - - - - - Fatal - - - - - Error - - - - - Warning - - - - - Note - - - - - Info - - - - - Debug - - - - - Debug1 - - - - - Debug2 - - - - - - - - - 0 - 0 - - - - Level - - - - + Using a Debug log level may affect performance. Only use a Debug level if you are attempting to debug an issue or are gathering logs to submit with a bug report. @@ -592,6 +592,13 @@ + + + + Enable GUI debug messages + + + diff --git a/src/unittests/gui/LoggerTests.cpp b/src/unittests/gui/LoggerTests.cpp index bd735555a..db7ce3950 100644 --- a/src/unittests/gui/LoggerTests.cpp +++ b/src/unittests/gui/LoggerTests.cpp @@ -6,13 +6,28 @@ */ #include "LoggerTests.h" +#include "common/Settings.h" #include "gui/Logger.h" +#include +#include #include using namespace deskflow::gui; +void LoggerTests::initTestCase() +{ + QDir dir; + QVERIFY(dir.mkpath(m_settingsPath)); + + QFile oldSettings(m_settingsFile); + if (oldSettings.exists()) + oldSettings.remove(); + + Settings::setSettingsFile(m_settingsFile); +} + void LoggerTests::newLine() { Logger logger; @@ -20,14 +35,12 @@ void LoggerTests::newLine() QSignalSpy spy(&logger, &Logger::newLine); QVERIFY(spy.isValid()); - qputenv("DESKFLOW_GUI_DEBUG", "true"); - logger.loadEnvVars(); - + Settings::setValue(Settings::Log::GuiDebug, true); logger.handleMessage(QtDebugMsg, "stub", "test"); QCOMPARE(spy.count(), 1); QVERIFY(qvariant_cast(spy.takeFirst().at(0)).contains("test")); - qputenv("DESKFLOW_GUI_DEBUG", ""); + Settings::setValue(Settings::Log::GuiDebug, false); } void LoggerTests::noNewLine() @@ -38,12 +51,10 @@ void LoggerTests::noNewLine() QSignalSpy spy(&logger, &Logger::newLine); QVERIFY(spy.isValid()); - qputenv("DESKFLOW_GUI_DEBUG", "false"); - logger.loadEnvVars(); + Settings::setValue(Settings::Log::GuiDebug, false); logger.handleMessage(QtDebugMsg, "stub", "test"); QCOMPARE(spy.count(), 0); QVERIFY(!newLineEmitted); - qputenv("DESKFLOW_GUI_DEBUG", ""); } QTEST_MAIN(LoggerTests) diff --git a/src/unittests/gui/LoggerTests.h b/src/unittests/gui/LoggerTests.h index 77d5aa160..7ffedb974 100644 --- a/src/unittests/gui/LoggerTests.h +++ b/src/unittests/gui/LoggerTests.h @@ -11,6 +11,11 @@ class LoggerTests : public QObject Q_OBJECT private Q_SLOTS: // Test are run in order top to bottom + void initTestCase(); void newLine(); void noNewLine(); + +private: + inline static const QString m_settingsPath = QStringLiteral("tmp/test"); + inline static const QString m_settingsFile = QStringLiteral("%1/Deskflow.conf").arg(m_settingsPath); }; diff --git a/translations/deskflow_es.ts b/translations/deskflow_es.ts index 28f565df3..865bf7485 100644 --- a/translations/deskflow_es.ts +++ b/translations/deskflow_es.ts @@ -1235,6 +1235,10 @@ Al habilitar esta opción, se deshabilitará la interfaz gráfica de usuario (GU Force a language to be used for the GUI. Fuerza el uso de un idioma para la interfaz gráfica de usuario. + + Enable GUI debug messages + Habilitar mensajes de depuración de la interfaz gráfica de usuario + TlsCertificate diff --git a/translations/deskflow_it.ts b/translations/deskflow_it.ts index 266125f94..3b155bec7 100644 --- a/translations/deskflow_it.ts +++ b/translations/deskflow_it.ts @@ -1235,6 +1235,10 @@ L'abilitazione di questa impostazione disabiliterà l'interfaccia graf Force a language to be used for the GUI. Forza l'utilizzo di una lingua per la GUI. + + Enable GUI debug messages + Abilita i messaggi di debug della GUI + TlsCertificate